Skip to content

Commit fd64a61

Browse files
Enhance README
1 parent b3cd3fc commit fd64a61

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ client.chat(
9898

9999
```ruby
100100
client.embed(
101-
texts: ["hello!"]
101+
model: "embed-english-v3.0",
102+
texts: ["hello", "goodbye"],
103+
input_type: "classification",
104+
embedding_types: ["float"]
102105
)
103106
```
104107

@@ -114,6 +117,7 @@ docs = [
114117
]
115118

116119
client.rerank(
120+
model: "rerank-english-v3.0",
117121
query: "What is the capital of the United States?",
118122
documents: docs
119123
)
@@ -141,24 +145,27 @@ inputs = [
141145
]
142146

143147
client.classify(
144-
examples: examples,
145-
inputs: inputs
148+
model: "embed-multilingual-v2.0",
149+
inputs: inputs,
150+
examples: examples
146151
)
147152
```
148153

149154
### Tokenize
150155

151156
```ruby
152157
client.tokenize(
153-
text: "hello world!"
158+
model: "command-r-plus-08-2024",
159+
text: "Hello, world!"
154160
)
155161
```
156162

157163
### Detokenize
158164

159165
```ruby
160166
client.detokenize(
161-
tokens: [33555, 1114 , 34]
167+
model: "command-r-plus-08-2024",
168+
tokens: [33555, 1114, 34]
162169
)
163170
```
164171

lib/cohere/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def generate(
7878
logit_bias: nil,
7979
truncate: nil
8080
)
81-
response = connection.post("generate") do |req|
81+
response = v1_connection.post("generate") do |req|
8282
req.body = {prompt: prompt}
8383
req.body[:model] = model if model
8484
req.body[:num_generations] = num_generations if num_generations

spec/cohere/client_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
RSpec.describe Cohere::Client do
66
subject { described_class.new(api_key: "123") }
77

8+
describe "#generate" do
9+
let(:generate_result) { JSON.parse(File.read("spec/fixtures/generate.json")) }
10+
let(:response) { OpenStruct.new(body: generate_result) }
11+
12+
before do
13+
allow_any_instance_of(Faraday::Connection).to receive(:post)
14+
.with("generate")
15+
.and_return(response)
16+
end
17+
18+
it "returns a response" do
19+
expect(subject.generate(
20+
prompt: "Once upon a time in a magical land called"
21+
).dig("generations").first.dig("text")).to eq(" The Past there was a Game called Warhammer Fantasy Battle.")
22+
end
23+
end
24+
825
describe "#chat" do
926
let(:generate_result) { JSON.parse(File.read("spec/fixtures/chat.json")) }
1027
let(:response) { OpenStruct.new(body: generate_result) }

spec/fixtures/generate.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"id": "a6bdaf27-5050-4ec1-862e-cdc171245692",
3+
"generations": [
4+
{
5+
"id": "2dcf03a3-e375-4aa5-b442-ab95bdc5f989",
6+
"text": " The Past there was a Game called Warhammer Fantasy Battle."
7+
}
8+
],
9+
"prompt": "Once upon a time in a magical land called",
10+
"meta": {
11+
"api_version": {
12+
"version": "1"
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)