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 diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index ed5b2a4..7d1b2fd 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: [], @@ -34,6 +34,8 @@ def chat( frequency_penalty: nil, 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 +64,8 @@ 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 + req.body[:force_single_step] = force_single_step end response.body end @@ -119,6 +123,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:,