From c62d271a3c9ac80f0ba9785e53b408005c75d496 Mon Sep 17 00:00:00 2001 From: Michael Kozakov Date: Wed, 13 Sep 2023 16:23:05 +0100 Subject: [PATCH 1/3] Add prompt truncation --- cohere/client.py | 5 +++++ cohere/client_async.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/cohere/client.py b/cohere/client.py index a23e2fcdb..caa87e122 100644 --- a/cohere/client.py +++ b/cohere/client.py @@ -244,6 +244,7 @@ def chat( search_queries_only: Optional[bool] = None, documents: Optional[List[Dict[str, Any]]] = None, citation_quality: Optional[str] = None, + prompt_truncation: Optional[str] = None, connectors: Optional[List[Dict[str, Any]]] = None, ) -> Union[Chat, StreamingChat]: """Returns a Chat object with the query reply. @@ -288,6 +289,7 @@ def chat( ], connectors (List[Dict[str, str]]): (Optional) When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG). Example: connectors=[{"id": "web-search"}] citation_quality (str): (Optional) Dictates the approach taken to generating citations by allowing the user to specify whether they want "accurate" results or "fast" results. Defaults to "accurate". + prompt_truncation (str): (Optional) Dictates how the prompt will be constructed. With `prompt_truncation` set to "AUTO", some elements from `chat_history` and `documents` will be dropped in attempt to construct a prompt that fits within the model's context length limit. With `prompt_truncation` set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a `TooManyTokens` error will be returned. Returns: a Chat object if stream=False, or a StreamingChat object if stream=True @@ -376,6 +378,9 @@ def chat( } if citation_quality is not None: json_body["citation_quality"] = citation_quality + if prompt_truncation is not None: + json_body["prompt_truncation"] = prompt_truncation + response = self._request(cohere.CHAT_URL, json=json_body, stream=stream) if stream: diff --git a/cohere/client_async.py b/cohere/client_async.py index e3cb2d9d3..bd7ff88da 100644 --- a/cohere/client_async.py +++ b/cohere/client_async.py @@ -226,6 +226,7 @@ async def chat( search_queries_only: Optional[bool] = None, documents: Optional[List[Dict[str, Any]]] = None, citation_quality: Optional[str] = None, + prompt_truncation: Optional[str] = None, connectors: Optional[List[Dict[str, Any]]] = None, ) -> Union[AsyncChat, StreamingChat]: if message is None: @@ -253,6 +254,8 @@ async def chat( } if citation_quality is not None: json_body["citation_quality"] = citation_quality + if prompt_truncation is not None: + json_body["prompt_truncation"] = prompt_truncation response = await self._request(cohere.CHAT_URL, json=json_body, stream=stream) From da8cb576e12f4e2051106663887cef4783a2df3e Mon Sep 17 00:00:00 2001 From: Michael Kozakov Date: Wed, 13 Sep 2023 16:34:00 +0100 Subject: [PATCH 2/3] Bump version --- CHANGELOG.md | 19 +++++++++++++++---- pyproject.toml | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 549142418..24ae961bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,41 @@ # Changelog +## 4.25 + +- [#296] (https://github.com/cohere-ai/cohere-python/pull/301) + - Chat: add support for prompt_truncation param + ## 4.24 + - [#296] (https://github.com/cohere-ai/cohere-python/pull/296) - Allow passing of delimiter for csv - + ## 4.23 + - [#294] (https://github.com/cohere-ai/cohere-python/pull/294) - Allow passing of ParseInfo for datasets ## 4.22 + - [#292] (https://github.com/cohere-ai/cohere-python/pull/292) - Add search query only parameter - - Add documents to generate citations - - Add connectors to generate citations + - Add documents to generate citations + - Add connectors to generate citations - Add citation quality ## 4.21 + - [#287] (https://github.com/cohere-ai/cohere-python/pull/287) - Remove deprecated chat "query" parameter including inside chat_history parameter - Support event-type for chat streaming ## 4.20.2 + - [#284] (https://github.com/cohere-ai/cohere-python/pull/284) - Rename dataset urls to download_urls ## 4.20.1 + - [#279] (https://github.com/cohere-ai/cohere-python/pull/279) - Fix dataset listing key error @@ -60,7 +71,7 @@ - [#262](https://github.com/cohere-ai/cohere-python/pull/262) - Deprecate embed custom models -## 4.15 +## 4.15 - [#256](https://github.com/cohere-ai/cohere-python/pull/256) - Add rerank finetuning endpoint diff --git a/pyproject.toml b/pyproject.toml index 252606212..7d9b456eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "4.24" +version = "4.25" description = "" authors = ["Cohere"] readme = "README.md" From cf33d34f8c7ae7cc139e42ba14c5be835f14ae15 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Sep 2023 14:45:08 +0100 Subject: [PATCH 3/3] Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7d9b456eb..8b1695d12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cohere" -version = "4.25" +version = "4.26" description = "" authors = ["Cohere"] readme = "README.md"