From d27479d01cc69b259665d8f4dce72ff378731954 Mon Sep 17 00:00:00 2001 From: Stefano Faraggi <40745694+stepp1@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:45:00 -0300 Subject: [PATCH 1/2] Added truncate argument to Cohere `generate` API --- langchain/llms/cohere.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/langchain/llms/cohere.py b/langchain/llms/cohere.py index adb50ad3cd8cb..605d4bb493b69 100644 --- a/langchain/llms/cohere.py +++ b/langchain/llms/cohere.py @@ -46,6 +46,9 @@ class Cohere(LLM, BaseModel): presence_penalty: int = 0 """Penalizes repeated tokens.""" + + truncate: Optional[str] = None + """Specify how the API will handle inputs longer than the maximum token length.""" cohere_api_key: Optional[str] = None @@ -83,6 +86,7 @@ def _default_params(self) -> Dict[str, Any]: "p": self.p, "frequency_penalty": self.frequency_penalty, "presence_penalty": self.presence_penalty, + "truncate": self.truncate, } @property From f35c8e742e9d9c6c04d8a0c67dd08cdc95656094 Mon Sep 17 00:00:00 2001 From: Stefano Faraggi <40745694+stepp1@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:56:56 -0300 Subject: [PATCH 2/2] Update doc for cohere's truncate option --- langchain/llms/cohere.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langchain/llms/cohere.py b/langchain/llms/cohere.py index 605d4bb493b69..f47e36ed9f88a 100644 --- a/langchain/llms/cohere.py +++ b/langchain/llms/cohere.py @@ -48,7 +48,7 @@ class Cohere(LLM, BaseModel): """Penalizes repeated tokens.""" truncate: Optional[str] = None - """Specify how the API will handle inputs longer than the maximum token length.""" + """Specify how the client handles inputs longer than the maximum token length: Truncate from START, END or NONE""" cohere_api_key: Optional[str] = None