cohere-ruby 0.9.8 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83208ee6cbdf496180ac2e6ed258388a74a266d86188b81ceb011bf5f2b61f44
4
- data.tar.gz: 9f0ff2d20ea3c988663bc1c104f46f0c94a6d8d833d4a0ebf1cb81f765d8502d
3
+ metadata.gz: 35acc85a1ec589048eae603675fd23afeec9c66c0ce8c14954c20916c099b93b
4
+ data.tar.gz: e48ea97c36afafa8ca134c240a19ff159af1086643e99efba0aaf5aaed225cca
5
5
  SHA512:
6
- metadata.gz: a0425fe338748ba829c6d15b3fe319c23cf6fe47ab18c885476dcccffe969888c215162d9139768e53ed569b5e6799c9abc17ecb028551f3cd48c2f92cec49e6
7
- data.tar.gz: 48add01bf4d9ee6a43ee27809efe2eb352eee73bceac26b6fcfff29ae060063b8e3f4dc5803e317d80a612d0f6890ac18ca1d90cf5fd62254e3d1bc6f1dce8de
6
+ metadata.gz: eb6700a2088e5b37842fb6a601e160bbc6e8a6e8c15a7dd52b42f74cc0ce5fc71c77d789d9eaa20a440b1a3c4b4bab46088a5117b84d0a5027531acbfaf28067
7
+ data.tar.gz: 4e759bd938560031412e4602ee86321e3953e61dfa9c368c843b0d1b71e0676b061007dda48514b8ef5e9df072f7df3b5c817452f06a72553864bf77a679b492
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.9] - 2024-04-05
4
+ - Adding missing parameters to endpoints
5
+
3
6
  ## [0.9.8] - 2024-02-10
4
7
  - Adding method for /chat endpoint
5
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cohere-ruby (0.9.8)
4
+ cohere-ruby (0.9.9)
5
5
  faraday (>= 2.0.1, < 3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -29,6 +29,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
29
29
  ## Usage
30
30
 
31
31
  ### Instantiating API client
32
+
32
33
  ```ruby
33
34
  require "cohere"
34
35
 
@@ -36,7 +37,9 @@ client = Cohere::Client.new(
36
37
  ENV['COHERE_API_KEY']
37
38
  )
38
39
  ```
40
+
39
41
  ### Generate
42
+
40
43
  ```ruby
41
44
  client.generate(
42
45
  prompt: "Once upon a time in a magical land called"
@@ -44,13 +47,53 @@ client.generate(
44
47
  ```
45
48
 
46
49
  ### Chat
50
+
47
51
  ```ruby
48
52
  client.chat(
49
53
  message: "Hey! How are you?"
50
54
  )
51
55
  ```
52
56
 
57
+ `chat` supports a streaming option. You can pass a block to the `chat` method and it will yield a new chunk as soon as it is received.
58
+
59
+ ```ruby
60
+ client.chat(message: "Hey! How are you?", stream: true) do |chunk, overall_received_bytes|
61
+ puts "Received #{overall_received_bytes} bytes: #{chunk.force_encoding(Encoding::UTF_8)}"
62
+ end
63
+ ```
64
+
65
+ `force_encoding` is preferred to avoid JSON parsing issue when Cohere returns emoticon.
66
+
67
+ `chat` supports Tool use (function calling).
68
+
69
+ ```ruby
70
+ tools = [
71
+ {
72
+ name: "query_daily_sales_report",
73
+ description: "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
74
+ parameter_definitions: {
75
+ day: {
76
+ description: "Retrieves sales data for this day, formatted as YYYY-MM-DD.",
77
+ type: "str",
78
+ required: true
79
+ }
80
+ }
81
+ }
82
+ ]
83
+
84
+ 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?"
85
+
86
+ client.chat(
87
+ model: model,
88
+ message: message,
89
+ tools: tools,
90
+ )
91
+ ```
92
+
93
+
94
+
53
95
  ### Embed
96
+
54
97
  ```ruby
55
98
  client.embed(
56
99
  texts: ["hello!"]
@@ -58,6 +101,7 @@ client.embed(
58
101
  ```
59
102
 
60
103
  ### Classify
104
+
61
105
  ```ruby
62
106
  examples = [
63
107
  { text: "Dermatologists don't like her!", label: "Spam" },
@@ -84,6 +128,7 @@ client.classify(
84
128
  ```
85
129
 
86
130
  ### Tokenize
131
+
87
132
  ```ruby
88
133
  client.tokenize(
89
134
  text: "hello world!"
@@ -91,6 +136,7 @@ client.tokenize(
91
136
  ```
92
137
 
93
138
  ### Detokenize
139
+
94
140
  ```ruby
95
141
  client.detokenize(
96
142
  tokens: [33555, 1114 , 34]
@@ -98,6 +144,7 @@ client.detokenize(
98
144
  ```
99
145
 
100
146
  ### Detect language
147
+
101
148
  ```ruby
102
149
  client.detect_language(
103
150
  texts: ["Здравствуй, Мир"]
@@ -105,6 +152,7 @@ client.detect_language(
105
152
  ```
106
153
 
107
154
  ### Summarize
155
+
108
156
  ```ruby
109
157
  client.summarize(
110
158
  text: "..."
data/lib/cohere/client.rb CHANGED
@@ -16,6 +16,7 @@ module Cohere
16
16
  message:,
17
17
  model: nil,
18
18
  stream: false,
19
+ preamble: nil,
19
20
  preamble_override: nil,
20
21
  chat_history: [],
21
22
  conversation_id: nil,
@@ -29,12 +30,18 @@ module Cohere
29
30
  k: nil,
30
31
  p: nil,
31
32
  frequency_penalty: nil,
32
- presence_penalty: nil
33
+ presence_penalty: nil,
34
+ tools: [],
35
+ &block
33
36
  )
34
37
  response = connection.post("chat") do |req|
35
38
  req.body = {message: message}
36
39
  req.body[:model] = model if model
37
- req.body[:stream] = stream if stream
40
+ if stream || block
41
+ req.body[:stream] = true
42
+ req.options.on_data = block if block
43
+ end
44
+ req.body[:preamble] = preamble if preamble
38
45
  req.body[:preamble_override] = preamble_override if preamble_override
39
46
  req.body[:chat_history] = chat_history if chat_history
40
47
  req.body[:conversation_id] = conversation_id if conversation_id
@@ -49,6 +56,7 @@ module Cohere
49
56
  req.body[:p] = p if p
50
57
  req.body[:frequency_penalty] = frequency_penalty if frequency_penalty
51
58
  req.body[:presence_penalty] = presence_penalty if presence_penalty
59
+ req.body[:tools] = tools if tools
52
60
  end
53
61
  response.body
54
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cohere
4
- VERSION = "0.9.8"
4
+ VERSION = "0.9.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cohere-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-11 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.5.3
73
+ rubygems_version: 3.4.1
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Cohere API client for Ruby.