Skip to content

Commit 2a377a0

Browse files
Merge pull request #23 from ScotterC/rerank-v2
v2 endpoint
2 parents 0328455 + e58eabb commit 2a377a0

19 files changed

Lines changed: 241 additions & 197 deletions

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COHERE_API_KEY=

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
# rspec failure tracking
1111
.rspec_status
12+
13+
.env

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## [Unreleased]
2+
- Migrate to v2 APIs
23

34
## [0.9.11] - 2024-08-01
45
- New `rerank()` method

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ gem "rake", "~> 13.0"
99

1010
gem "rspec", "~> 3.0"
1111
gem "standard", "~> 1.28.0"
12+
gem "dotenv", "~> 2.8.1"

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GEM
99
specs:
1010
ast (2.4.2)
1111
diff-lcs (1.5.0)
12+
dotenv (2.8.1)
1213
faraday (2.7.10)
1314
faraday-net_http (>= 2.0, < 3.1)
1415
ruby2_keywords (>= 0.0.4)
@@ -74,6 +75,7 @@ PLATFORMS
7475

7576
DEPENDENCIES
7677
cohere-ruby!
78+
dotenv (~> 2.8.1)
7779
rake (~> 13.0)
7880
rspec (~> 3.0)
7981
standard (~> 1.28.0)

README.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
Cohere API client for Ruby.
1010

11-
Part of the [Langchain.rb](https://github.com/andreibondarev/langchainrb) stack.
11+
Part of the [Langchain.rb](https://github.com/patterns-ai-core/langchainrb) stack.
1212

13-
![Tests status](https://github.com/andreibondarev/cohere-ruby/actions/workflows/ci.yml/badge.svg)
13+
![Tests status](https://github.com/patterns-ai-core/cohere-ruby/actions/workflows/ci.yml/badge.svg)
1414
[![Gem Version](https://badge.fury.io/rb/cohere-ruby.svg)](https://badge.fury.io/rb/cohere-ruby)
1515
[![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/cohere-ruby)
16-
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/cohere-ruby/blob/main/LICENSE.txt)
16+
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/patterns-ai-core/cohere-ruby/blob/main/LICENSE.txt)
1717
[![](https://dcbadge.vercel.app/api/server/WDARp7J2n8?compact=true&style=flat)](https://discord.gg/WDARp7J2n8)
1818

1919
## Installation
@@ -50,14 +50,18 @@ client.generate(
5050

5151
```ruby
5252
client.chat(
53-
message: "Hey! How are you?"
53+
model: "command-r-plus-08-2024",
54+
messages: [{role:"user", content: "Hey! How are you?"}]
5455
)
5556
```
5657

5758
`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.
5859

5960
```ruby
60-
client.chat(message: "Hey! How are you?", stream: true) do |chunk, overall_received_bytes|
61+
client.chat(
62+
model: "command-r-plus-08-2024",
63+
messages: [{role:"user", content: "Hey! How are you?"}]
64+
) do |chunk, overall_received_bytes|
6165
puts "Received #{overall_received_bytes} bytes: #{chunk.force_encoding(Encoding::UTF_8)}"
6266
end
6367
```
@@ -68,33 +72,36 @@ end
6872

6973
```ruby
7074
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-
}
75+
{
76+
name: "query_daily_sales_report",
77+
description: "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
78+
parameter_definitions: {
79+
day: {
80+
description: "Retrieves sales data for this day, formatted as YYYY-MM-DD.",
81+
type: "str",
82+
required: true
83+
}
84+
}
85+
}
8286
]
8387

8488
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?"
8589

8690
client.chat(
8791
model: model,
88-
message: message,
89-
tools: tools,
92+
messages: [{ role:"user", content: message }],
93+
tools: tools
9094
)
9195
```
9296

9397
### Embed
9498

9599
```ruby
96100
client.embed(
97-
texts: ["hello!"]
101+
model: "embed-english-v3.0",
102+
texts: ["hello", "goodbye"],
103+
input_type: "classification",
104+
embedding_types: ["float"]
98105
)
99106
```
100107

@@ -110,6 +117,7 @@ docs = [
110117
]
111118

112119
client.rerank(
120+
model: "rerank-english-v3.0",
113121
query: "What is the capital of the United States?",
114122
documents: docs
115123
)
@@ -137,24 +145,27 @@ inputs = [
137145
]
138146

139147
client.classify(
140-
examples: examples,
141-
inputs: inputs
148+
model: "embed-multilingual-v2.0",
149+
inputs: inputs,
150+
examples: examples
142151
)
143152
```
144153

145154
### Tokenize
146155

147156
```ruby
148157
client.tokenize(
149-
text: "hello world!"
158+
model: "command-r-plus-08-2024",
159+
text: "Hello, world!"
150160
)
151161
```
152162

153163
### Detokenize
154164

155165
```ruby
156166
client.detokenize(
157-
tokens: [33555, 1114 , 34]
167+
model: "command-r-plus-08-2024",
168+
tokens: [33555, 1114, 34]
158169
)
159170
```
160171

bin/console

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33

44
require "bundler/setup"
55
require "cohere"
6-
7-
# You can add fixtures and/or initialization code here to make experimenting
8-
# with your gem easier. You can also use a different console, if you like.
9-
10-
# (If you use this, don't forget to add pry to your Gemfile!)
11-
# require "pry"
12-
# Pry.start
6+
require "dotenv/load"
137

148
client = Cohere::Client.new(
159
api_key: ENV['COHERE_API_KEY']

0 commit comments

Comments
 (0)