Skip to content
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

Add support tools #13

Merged
merged 1 commit into from
Apr 5, 2024
Merged
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ end

`force_encoding` is preferred to avoid JSON parsing issue when Cohere returns emoticon.

`chat` supports Tool use (function calling).

```ruby
tools = [
{
name: "query_daily_sales_report",
description: "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
parameter_definitions: {
Copy link
Collaborator

@andreibondarev andreibondarev Apr 5, 2024

Choose a reason for hiding this comment

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

Why did they have to call this key differently from OpenAI and Google Gemini?! 😭😭😭

day: {
description: "Retrieves sales data for this day, formatted as YYYY-MM-DD.",
type: "str",
required: true
}
}
}
]

message = "Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?"

client.chat(
model: model,
message: message,
tools: tools,
)
```



### Embed

```ruby
Expand Down
2 changes: 2 additions & 0 deletions lib/cohere/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def chat(
p: nil,
frequency_penalty: nil,
presence_penalty: nil,
tools: [],
&block
)
response = connection.post("chat") do |req|
Expand All @@ -53,6 +54,7 @@ def chat(
req.body[:p] = p if p
req.body[:frequency_penalty] = frequency_penalty if frequency_penalty
req.body[:presence_penalty] = presence_penalty if presence_penalty
req.body[:tools] = tools if tools
end
response.body
end
Expand Down