From e4812a6a14dfa6c7bb26605ec166e95d1506e7d6 Mon Sep 17 00:00:00 2001 From: naoa Date: Fri, 5 Apr 2024 23:09:36 +0900 Subject: [PATCH] Add support tools --- README.md | 28 ++++++++++++++++++++++++++++ lib/cohere/client.rb | 2 ++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index cee027e..f357b64 100644 --- a/README.md +++ b/README.md @@ -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: { + 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 diff --git a/lib/cohere/client.rb b/lib/cohere/client.rb index 67c72e7..2ca1059 100644 --- a/lib/cohere/client.rb +++ b/lib/cohere/client.rb @@ -30,6 +30,7 @@ def chat( p: nil, frequency_penalty: nil, presence_penalty: nil, + tools: [], &block ) response = connection.post("chat") do |req| @@ -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