cohere-ruby 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c5f0625529c315bd0a953bb8e0acf36fbebe685b13decde1fe26d93b5d97ab8
4
- data.tar.gz: 504ce83377f6f2175b2d7ab9f899c307a7a02563c75b8c630b249d0e7487c746
3
+ metadata.gz: 5f1c3798500d154b882bd6bb2e0e43904fea4bf69db4d982da4abc6265bc461c
4
+ data.tar.gz: d91ed933c24f2dacc5f2604639d307fd389f3774aaed8082df07e03ac2961704
5
5
  SHA512:
6
- metadata.gz: 1dc8c2c85e551438f597346679c3bb198808e906eb9317dd05c26511556e34f512707cbc4bb3046487de9e498ca7b92c6405d2f9c3e4175f466e49618c7215b9
7
- data.tar.gz: 0024a4c8c6091fa78fe83dcd7879ea8a511436e4ddc16929dd3e88e517901ba1ac569e16c519f47abccbba08a0cdd43fe795c4e867b4e252f0d5003a9ffb5b3e
6
+ metadata.gz: b989c60be670a143848367a7be84f53fc6adf97f31e1f3739113a7a7caec988450e4e889bcbc7f2733783623977dc4f6e1eb7484470259935e30e7dc6d5d1414
7
+ data.tar.gz: 00a2e3e1a19bfb1980d06ebc1fd6117262bcdf226bc95bfe0edff8ea8e1397791eaf7ef37b78ad158e0ef5a8363fa809c9215fc325d771e72abf22d7919c54c0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.11] - 2024-08-01
4
+ - New `rerank()` method
5
+
3
6
  ## [0.9.10] - 2024-05-10
4
7
  - /chat endpoint does not require `message:` parameter anymore
5
8
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cohere-ruby (0.9.10)
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>
@@ -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
@@ -119,6 +119,29 @@ module Cohere
119
119
  response.body
120
120
  end
121
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
+
122
145
  def classify(
123
146
  inputs:,
124
147
  examples:,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cohere
4
- VERSION = "0.9.10"
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.10
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-05-11 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.