From 95afe81811cff215bdf1bb0d833eb26889d7d9de Mon Sep 17 00:00:00 2001 From: yjean Date: Wed, 10 Apr 2024 11:45:05 +0200 Subject: [PATCH 1/6] feat(client): accept tool_results too --- lib/cohere/client.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index 668edcc..552d463 100644 --- a/lib/cohere/client.rb +++ b/lib/cohere/client.rb @@ -34,6 +34,7 @@ def chat( frequency_penalty: nil, presence_penalty: nil, tools: [], + tool_results: [], &block ) response = connection.post("chat") do |req| @@ -60,6 +61,7 @@ def chat( req.body[:frequency_penalty] = frequency_penalty if frequency_penalty req.body[:presence_penalty] = presence_penalty if presence_penalty req.body[:tools] = tools if tools + req.body[:tool_results] = tool_results if tool_results end response.body end From f393161dd5142adfd437e7f442fd2b5330557111 Mon Sep 17 00:00:00 2001 From: yjean Date: Wed, 10 Apr 2024 11:53:50 +0200 Subject: [PATCH 2/6] fix(client): use nil for tool_results by default Otherwise, an empty array is sent and Cohere relies on tool_results as being empty and therefore don't trigger tool_calls --- lib/cohere/client.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index 552d463..5eb03d8 100644 --- a/lib/cohere/client.rb +++ b/lib/cohere/client.rb @@ -33,8 +33,8 @@ def chat( seed: nil, frequency_penalty: nil, presence_penalty: nil, - tools: [], - tool_results: [], + tools: nil, + tool_results: nil, &block ) response = connection.post("chat") do |req| From f4db0f0d2a35241ec45dadf113f423d1a554a881 Mon Sep 17 00:00:00 2001 From: yjean Date: Wed, 10 Apr 2024 11:56:45 +0200 Subject: [PATCH 3/6] feat(client): add tool_results documentation --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 1ab14fa..063b7ba 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,20 @@ client.chat( ) ``` +Once the function is called, results are passed through `tool_results` array so you can get insights on the next reply. +```ruby +client.chat( + model: model, + message: message, + tools: tool, + tool_results: [ + { + rows: [['Ruby', 42]] + } + ] +) +``` ### Embed From 4730bffb1b3444235f153965e55f80b472dfe450 Mon Sep 17 00:00:00 2001 From: yjean Date: Wed, 10 Apr 2024 11:58:47 +0200 Subject: [PATCH 4/6] revert: tools default as [] is working --- lib/cohere/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index 5eb03d8..a4008e4 100644 --- a/lib/cohere/client.rb +++ b/lib/cohere/client.rb @@ -33,7 +33,7 @@ def chat( seed: nil, frequency_penalty: nil, presence_penalty: nil, - tools: nil, + tools: [], tool_results: nil, &block ) From 50ce83c9f270f0cae9a8b52eb1f751c9f4e91751 Mon Sep 17 00:00:00 2001 From: yjean Date: Fri, 3 May 2024 10:01:17 +0200 Subject: [PATCH 5/6] fix(chat-history): ensure we pass nil by default otherwise, the conversation_id is ignored by Cohere --- lib/cohere/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index a4008e4..abaa226 100644 --- a/lib/cohere/client.rb +++ b/lib/cohere/client.rb @@ -19,7 +19,7 @@ def chat( stream: false, preamble: nil, preamble_override: nil, - chat_history: [], + chat_history: nil, conversation_id: nil, prompt_truncation: nil, connectors: [], From 2f1f780cce2b4a538ca4dad9a2ec8c8d809c6fe4 Mon Sep 17 00:00:00 2001 From: yjean Date: Fri, 14 Jun 2024 08:32:34 +0200 Subject: [PATCH 6/6] fix(api): force_single_step to true To restore behavior prior to 6/10/2024 change --- lib/cohere/client.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index abaa226..720457c 100644 --- a/lib/cohere/client.rb +++ b/lib/cohere/client.rb @@ -35,6 +35,7 @@ def chat( presence_penalty: nil, tools: [], tool_results: nil, + force_single_step: true, # default to true for backwards compatibility prior 6/10/2024 change &block ) response = connection.post("chat") do |req| @@ -62,6 +63,7 @@ def chat( req.body[:presence_penalty] = presence_penalty if presence_penalty req.body[:tools] = tools if tools req.body[:tool_results] = tool_results if tool_results + req.body[:force_single_step] = force_single_step end response.body end @@ -119,6 +121,26 @@ def embed( response.body end + def rerank( + query:, + documents: [], + top_n: nil, + rank_fields: nil, + return_documents: nil, + max_chunks_per_doc: nil, + model: nil + ) + response = connection.post("rerank") do |req| + req.body = { query:, documents: } + req.body[:top_n] = top_n if top_n + req.body[:rank_fields] = rank_fields if rank_fields + req.body[:return_documents] = return_documents if return_documents + req.body[:max_chunks_per_doc] = max_chunks_per_doc if max_chunks_per_doc + req.body[:model] = model if model + end + response.body + end + def classify( inputs:, examples:,