cohere-ruby 0.9.9 → 0.9.11

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: 35acc85a1ec589048eae603675fd23afeec9c66c0ce8c14954c20916c099b93b
4
- data.tar.gz: e48ea97c36afafa8ca134c240a19ff159af1086643e99efba0aaf5aaed225cca
3
+ metadata.gz: 5f1c3798500d154b882bd6bb2e0e43904fea4bf69db4d982da4abc6265bc461c
4
+ data.tar.gz: d91ed933c24f2dacc5f2604639d307fd389f3774aaed8082df07e03ac2961704
5
5
  SHA512:
6
- metadata.gz: eb6700a2088e5b37842fb6a601e160bbc6e8a6e8c15a7dd52b42f74cc0ce5fc71c77d789d9eaa20a440b1a3c4b4bab46088a5117b84d0a5027531acbfaf28067
7
- data.tar.gz: 4e759bd938560031412e4602ee86321e3953e61dfa9c368c843b0d1b71e0676b061007dda48514b8ef5e9df072f7df3b5c817452f06a72553864bf77a679b492
6
+ metadata.gz: b989c60be670a143848367a7be84f53fc6adf97f31e1f3739113a7a7caec988450e4e889bcbc7f2733783623977dc4f6e1eb7484470259935e30e7dc6d5d1414
7
+ data.tar.gz: 00a2e3e1a19bfb1980d06ebc1fd6117262bcdf226bc95bfe0edff8ea8e1397791eaf7ef37b78ad158e0ef5a8363fa809c9215fc325d771e72abf22d7919c54c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.11] - 2024-08-01
4
+ - New `rerank()` method
5
+
6
+ ## [0.9.10] - 2024-05-10
7
+ - /chat endpoint does not require `message:` parameter anymore
8
+
3
9
  ## [0.9.9] - 2024-04-05
4
10
  - Adding missing parameters to endpoints
5
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cohere-ruby (0.9.9)
4
+ cohere-ruby (0.9.11)
5
5
  faraday (>= 2.0.1, < 3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Cohere
2
2
 
3
3
  <p>
4
- <img alt='Weaviate logo' src='https://static.wikia.nocookie.net/logopedia/images/d/d4/Cohere_2023.svg/revision/latest?cb=20230419182227' height='50' />
4
+ <img alt='Cohere logo' src='https://static.wikia.nocookie.net/logopedia/images/d/d4/Cohere_2023.svg/revision/latest?cb=20230419182227' height='50' />
5
5
  +&nbsp;&nbsp;
6
6
  <img alt='Ruby logo' src='https://user-images.githubusercontent.com/541665/230231593-43861278-4550-421d-a543-fd3553aac4f6.png' height='40' />
7
7
  </p>
@@ -34,7 +34,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
34
34
  require "cohere"
35
35
 
36
36
  client = Cohere::Client.new(
37
- ENV['COHERE_API_KEY']
37
+ api_key: ENV['COHERE_API_KEY']
38
38
  )
39
39
  ```
40
40
 
@@ -42,7 +42,7 @@ client = Cohere::Client.new(
42
42
 
43
43
  ```ruby
44
44
  client.generate(
45
- prompt: "Once upon a time in a magical land called"
45
+ prompt: "Once upon a time in a magical land called"
46
46
  )
47
47
  ```
48
48
 
@@ -50,7 +50,7 @@ client.generate(
50
50
 
51
51
  ```ruby
52
52
  client.chat(
53
- message: "Hey! How are you?"
53
+ message: "Hey! How are you?"
54
54
  )
55
55
  ```
56
56
 
@@ -90,30 +90,45 @@ client.chat(
90
90
  )
91
91
  ```
92
92
 
93
-
94
-
95
93
  ### Embed
96
94
 
97
95
  ```ruby
98
96
  client.embed(
99
- texts: ["hello!"]
97
+ texts: ["hello!"]
98
+ )
99
+ ```
100
+
101
+ ### Rerank
102
+
103
+ ```ruby
104
+ docs = [
105
+ "Carson City is the capital city of the American state of Nevada.",
106
+ "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
107
+ "Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
108
+ "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
109
+ "Capital punishment (the death penalty) has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states.",
110
+ ]
111
+
112
+ client.rerank(
113
+ texts: ["hello!"]
100
114
  )
101
115
  ```
102
116
 
117
+
103
118
  ### Classify
104
119
 
105
120
  ```ruby
106
121
  examples = [
107
- { text: "Dermatologists don't like her!", label: "Spam" },
108
- { text: "Hello, open to this?", label: "Spam" },
109
- { text: "I need help please wire me $1000 right now", label: "Spam" },
110
- { text: "Nice to know you ;)", label: "Spam" },
111
- { text: "Please help me?", label: "Spam" },
112
- { text: "Your parcel will be delivered today", label: "Not spam" },
113
- { text: "Review changes to our Terms and Conditions", label: "Not spam" },
114
- { text: "Weekly sync notes", label: "Not spam" },
115
- { text: "Re: Follow up from today's meeting", label: "Not spam" },
116
- { text: "Pre-read for tomorrow", label: "Not spam" }
122
+ { text: "Dermatologists don't like her!", label: "Spam" },
123
+ { text: "Hello, open to this?", label: "Spam" },
124
+ { text: "I need help please wire me $1000 right now", label: "Spam" },
125
+ { text: "Nice to know you ;)", label: "Spam" },
126
+ { text: "Please help me?", label: "Spam" },
127
+ { text: "Your parcel will be delivered today", label: "Not spam" },
128
+ { text: "Review changes to our Terms and Conditions", label: "Not spam" },
129
+ { text: "Weekly sync notes", label: "Not spam" },
130
+ { text: "Re: Follow up from today's meeting", label: "Not spam" },
131
+ { text: "Pre-read for tomorrow", label: "Not spam" }
117
132
  ]
118
133
 
119
134
  inputs = [
@@ -122,8 +137,8 @@ inputs = [
122
137
  ]
123
138
 
124
139
  client.classify(
125
- examples: examples,
126
- inputs: inputs
140
+ examples: examples,
141
+ inputs: inputs
127
142
  )
128
143
  ```
129
144
 
@@ -131,7 +146,7 @@ client.classify(
131
146
 
132
147
  ```ruby
133
148
  client.tokenize(
134
- text: "hello world!"
149
+ text: "hello world!"
135
150
  )
136
151
  ```
137
152
 
@@ -139,7 +154,7 @@ client.tokenize(
139
154
 
140
155
  ```ruby
141
156
  client.detokenize(
142
- tokens: [33555, 1114 , 34]
157
+ tokens: [33555, 1114 , 34]
143
158
  )
144
159
  ```
145
160
 
@@ -147,7 +162,7 @@ client.detokenize(
147
162
 
148
163
  ```ruby
149
164
  client.detect_language(
150
- texts: ["Здравствуй, Мир"]
165
+ texts: ["Здравствуй, Мир"]
151
166
  )
152
167
  ```
153
168
 
@@ -155,7 +170,7 @@ client.detect_language(
155
170
 
156
171
  ```ruby
157
172
  client.summarize(
158
- text: "..."
173
+ text: "..."
159
174
  )
160
175
  ```
161
176
 
data/lib/cohere/client.rb CHANGED
@@ -8,12 +8,13 @@ module Cohere
8
8
 
9
9
  ENDPOINT_URL = "https://api.cohere.ai/v1"
10
10
 
11
- def initialize(api_key)
11
+ def initialize(api_key:, timeout: nil)
12
12
  @api_key = api_key
13
+ @timeout = timeout
13
14
  end
14
15
 
15
16
  def chat(
16
- message:,
17
+ message: nil,
17
18
  model: nil,
18
19
  stream: false,
19
20
  preamble: nil,
@@ -29,13 +30,16 @@ module Cohere
29
30
  max_tokens: nil,
30
31
  k: nil,
31
32
  p: nil,
33
+ seed: nil,
32
34
  frequency_penalty: nil,
33
35
  presence_penalty: nil,
34
36
  tools: [],
35
37
  &block
36
38
  )
37
39
  response = connection.post("chat") do |req|
38
- req.body = {message: message}
40
+ req.body = {}
41
+
42
+ req.body[:message] = message if message
39
43
  req.body[:model] = model if model
40
44
  if stream || block
41
45
  req.body[:stream] = true
@@ -54,6 +58,7 @@ module Cohere
54
58
  req.body[:max_tokens] = max_tokens if max_tokens
55
59
  req.body[:k] = k if k
56
60
  req.body[:p] = p if p
61
+ req.body[:seed] = seed if seed
57
62
  req.body[:frequency_penalty] = frequency_penalty if frequency_penalty
58
63
  req.body[:presence_penalty] = presence_penalty if presence_penalty
59
64
  req.body[:tools] = tools if tools
@@ -114,6 +119,29 @@ module Cohere
114
119
  response.body
115
120
  end
116
121
 
122
+ def rerank(
123
+ query:,
124
+ documents:,
125
+ model: nil,
126
+ top_n: nil,
127
+ rank_fields: nil,
128
+ return_documents: nil,
129
+ max_chunks_per_doc: nil
130
+ )
131
+ response = connection.post("rerank") do |req|
132
+ req.body = {
133
+ query: query,
134
+ documents: documents
135
+ }
136
+ req.body[:model] = model if model
137
+ req.body[:top_n] = top_n if top_n
138
+ req.body[:rank_fields] = rank_fields if rank_fields
139
+ req.body[:return_documents] = return_documents if return_documents
140
+ req.body[:max_chunks_per_doc] = max_chunks_per_doc if max_chunks_per_doc
141
+ end
142
+ response.body
143
+ end
144
+
117
145
  def classify(
118
146
  inputs:,
119
147
  examples:,
@@ -179,7 +207,7 @@ module Cohere
179
207
 
180
208
  # standard:disable Lint/DuplicateMethods
181
209
  def connection
182
- @connection ||= Faraday.new(url: ENDPOINT_URL) do |faraday|
210
+ @connection ||= Faraday.new(url: ENDPOINT_URL, request: {timeout: @timeout}) do |faraday|
183
211
  if api_key
184
212
  faraday.request :authorization, :Bearer, api_key
185
213
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cohere
4
- VERSION = "0.9.9"
4
+ VERSION = "0.9.11"
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.9
4
+ version: 0.9.11
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-04-05 00:00:00.000000000 Z
11
+ date: 2024-08-01 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.4.1
73
+ rubygems_version: 3.5.11
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Cohere API client for Ruby.