Skip to content

client: accept tool_results too #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct format? The docs mention the following format:

tool_results = [
  {
    "call": {
      "name": <tool name>,
      "parameters": {
        <param name>: <param value>
      }
    },
    "outputs": [{
      <key>: <value>
    }]
  },
  ...
]

}
]
)
```

### Embed

Expand Down
26 changes: 25 additions & 1 deletion lib/cohere/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -34,6 +34,8 @@ def chat(
frequency_penalty: nil,
presence_penalty: nil,
tools: [],
tool_results: nil,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally put tool_results: [] and then below:

req.body[:tool_results] = tool_results if tool_results.any?

force_single_step: true, # default to true for backwards compatibility prior 6/10/2024 change
&block
)
response = connection.post("chat") do |req|
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:,
Expand Down
Loading