Skip to content

Commit

Permalink
Enhance README
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibondarev committed Nov 23, 2024
1 parent b3cd3fc commit fd64a61
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ client.chat(

```ruby
client.embed(
texts: ["hello!"]
model: "embed-english-v3.0",
texts: ["hello", "goodbye"],
input_type: "classification",
embedding_types: ["float"]
)
```

Expand All @@ -114,6 +117,7 @@ docs = [
]

client.rerank(
model: "rerank-english-v3.0",
query: "What is the capital of the United States?",
documents: docs
)
Expand Down Expand Up @@ -141,24 +145,27 @@ inputs = [
]

client.classify(
examples: examples,
inputs: inputs
model: "embed-multilingual-v2.0",
inputs: inputs,
examples: examples
)
```

### Tokenize

```ruby
client.tokenize(
text: "hello world!"
model: "command-r-plus-08-2024",
text: "Hello, world!"
)
```

### Detokenize

```ruby
client.detokenize(
tokens: [33555, 1114 , 34]
model: "command-r-plus-08-2024",
tokens: [33555, 1114, 34]
)
```

Expand Down
2 changes: 1 addition & 1 deletion lib/cohere/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def generate(
logit_bias: nil,
truncate: nil
)
response = connection.post("generate") do |req|
response = v1_connection.post("generate") do |req|
req.body = {prompt: prompt}
req.body[:model] = model if model
req.body[:num_generations] = num_generations if num_generations
Expand Down
17 changes: 17 additions & 0 deletions spec/cohere/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
RSpec.describe Cohere::Client do
subject { described_class.new(api_key: "123") }

describe "#generate" do
let(:generate_result) { JSON.parse(File.read("spec/fixtures/generate.json")) }
let(:response) { OpenStruct.new(body: generate_result) }

before do
allow_any_instance_of(Faraday::Connection).to receive(:post)
.with("generate")
.and_return(response)
end

it "returns a response" do
expect(subject.generate(
prompt: "Once upon a time in a magical land called"
).dig("generations").first.dig("text")).to eq(" The Past there was a Game called Warhammer Fantasy Battle.")
end
end

describe "#chat" do
let(:generate_result) { JSON.parse(File.read("spec/fixtures/chat.json")) }
let(:response) { OpenStruct.new(body: generate_result) }
Expand Down
15 changes: 15 additions & 0 deletions spec/fixtures/generate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "a6bdaf27-5050-4ec1-862e-cdc171245692",
"generations": [
{
"id": "2dcf03a3-e375-4aa5-b442-ab95bdc5f989",
"text": " The Past there was a Game called Warhammer Fantasy Battle."
}
],
"prompt": "Once upon a time in a magical land called",
"meta": {
"api_version": {
"version": "1"
}
}
}

0 comments on commit fd64a61

Please sign in to comment.