Skip to content

Commit 41694cd

Browse files
Merge pull request #1 from andreibondarev/andreibondarev-patch-1
Update README.md
2 parents 1e10b14 + 1eace18 commit 41694cd

File tree

6 files changed

+102
-55
lines changed

6 files changed

+102
-55
lines changed

Gemfile

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

1010
gem "rspec", "~> 3.0"
11+
gem "standard", "~> 1.28.0"

Gemfile.lock

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
PATH
22
remote: .
33
specs:
4-
cohere-ruby (0.9.0)
4+
cohere-ruby (0.9.1)
55
faraday (~> 2.7.0)
66

77
GEM
88
remote: https://rubygems.org/
99
specs:
10+
ast (2.4.2)
1011
diff-lcs (1.5.0)
1112
faraday (2.7.4)
1213
faraday-net_http (>= 2.0, < 3.1)
1314
ruby2_keywords (>= 0.0.4)
1415
faraday-net_http (3.0.2)
16+
json (2.6.3)
17+
language_server-protocol (3.17.0.3)
18+
lint_roller (1.0.0)
19+
parallel (1.23.0)
20+
parser (3.2.2.1)
21+
ast (~> 2.4.1)
22+
rainbow (3.1.1)
1523
rake (13.0.6)
24+
regexp_parser (2.8.0)
25+
rexml (3.2.5)
1626
rspec (3.12.0)
1727
rspec-core (~> 3.12.0)
1828
rspec-expectations (~> 3.12.0)
@@ -26,15 +36,45 @@ GEM
2636
diff-lcs (>= 1.2.0, < 2.0)
2737
rspec-support (~> 3.12.0)
2838
rspec-support (3.12.0)
39+
rubocop (1.50.2)
40+
json (~> 2.3)
41+
parallel (~> 1.10)
42+
parser (>= 3.2.0.0)
43+
rainbow (>= 2.2.2, < 4.0)
44+
regexp_parser (>= 1.8, < 3.0)
45+
rexml (>= 3.2.5, < 4.0)
46+
rubocop-ast (>= 1.28.0, < 2.0)
47+
ruby-progressbar (~> 1.7)
48+
unicode-display_width (>= 2.4.0, < 3.0)
49+
rubocop-ast (1.28.0)
50+
parser (>= 3.2.1.0)
51+
rubocop-performance (1.16.0)
52+
rubocop (>= 1.7.0, < 2.0)
53+
rubocop-ast (>= 0.4.0)
54+
ruby-progressbar (1.13.0)
2955
ruby2_keywords (0.0.5)
56+
standard (1.28.0)
57+
language_server-protocol (~> 3.17.0.2)
58+
lint_roller (~> 1.0)
59+
rubocop (~> 1.50.2)
60+
standard-custom (~> 1.0.0)
61+
standard-performance (~> 1.0.1)
62+
standard-custom (1.0.0)
63+
lint_roller (~> 1.0)
64+
standard-performance (1.0.1)
65+
lint_roller (~> 1.0)
66+
rubocop-performance (~> 1.16.0)
67+
unicode-display_width (2.4.2)
3068

3169
PLATFORMS
3270
x86_64-darwin-19
71+
x86_64-linux
3372

3473
DEPENDENCIES
3574
cohere-ruby!
3675
rake (~> 13.0)
3776
rspec (~> 3.0)
77+
standard (~> 1.28.0)
3878

3979
BUNDLED WITH
4080
2.4.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ client.summarize(
9898

9999
## Development
100100

101-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec/` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
102102

103103
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
104104

lib/cohere/client.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def generate(
3030
logit_bias: nil,
3131
truncate: nil
3232
)
33-
response = connection.post('generate') do |req|
34-
req.body = { prompt: prompt }
33+
response = connection.post("generate") do |req|
34+
req.body = {prompt: prompt}
3535
req.body[:model] = model if model
3636
req.body[:num_generations] = num_generations if num_generations
3737
req.body[:max_tokens] = max_tokens if max_tokens
@@ -55,8 +55,8 @@ def embed(
5555
model: nil,
5656
truncate: nil
5757
)
58-
response = connection.post('embed') do |req|
59-
req.body = { texts: texts }
58+
response = connection.post("embed") do |req|
59+
req.body = {texts: texts}
6060
req.body[:model] = model if model
6161
req.body[:truncate] = truncate if truncate
6262
end
@@ -70,7 +70,7 @@ def classify(
7070
present: nil,
7171
truncate: nil
7272
)
73-
response = connection.post('classify') do |req|
73+
response = connection.post("classify") do |req|
7474
req.body = {
7575
inputs: inputs,
7676
examples: examples
@@ -83,22 +83,22 @@ def classify(
8383
end
8484

8585
def tokenize(text:)
86-
response = connection.post('tokenize') do |req|
87-
req.body = { text: text }
86+
response = connection.post("tokenize") do |req|
87+
req.body = {text: text}
8888
end
8989
response.body
9090
end
9191

9292
def detokenize(tokens:)
93-
response = connection.post('detokenize') do |req|
94-
req.body = { tokens: tokens }
93+
response = connection.post("detokenize") do |req|
94+
req.body = {tokens: tokens}
9595
end
9696
response.body
9797
end
9898

9999
def detect_language(texts:)
100-
response = connection.post('detect-language') do |req|
101-
req.body = { texts: texts }
100+
response = connection.post("detect-language") do |req|
101+
req.body = {texts: texts}
102102
end
103103
response.body
104104
end
@@ -112,8 +112,8 @@ def summarize(
112112
temperature: nil,
113113
additional_command: nil
114114
)
115-
response = connection.post('summarize') do |req|
116-
req.body = { text: text }
115+
response = connection.post("summarize") do |req|
116+
req.body = {text: text}
117117
req.body[:length] = length if length
118118
req.body[:format] = format if format
119119
req.body[:model] = model if model
@@ -126,6 +126,7 @@ def summarize(
126126

127127
private
128128

129+
# standard:disable Lint/DuplicateMethods
129130
def connection
130131
@connection ||= Faraday.new(url: ENDPOINT_URL) do |faraday|
131132
if api_key
@@ -136,5 +137,6 @@ def connection
136137
faraday.adapter Faraday.default_adapter
137138
end
138139
end
140+
# standard:enable Lint/DuplicateMethods
139141
end
140-
end
142+
end

lib/cohere/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Cohere
4-
VERSION = "0.9.0"
4+
VERSION = "0.9.1"
55
end

spec/cohere/client_spec.rb

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it "returns a response" do
1919
expect(instance.generate(
2020
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.")
21+
).dig("generations").first.dig("text")).to eq(" The Past there was a Game called Warhammer Fantasy Battle.")
2222
end
2323
end
2424

@@ -35,23 +35,27 @@
3535
it "returns a response" do
3636
expect(instance.embed(
3737
texts: ["hello!"]
38-
).dig('embeddings')).to eq([[ 1.2177734, 0.67529297, 2.0742188 ]])
38+
).dig("embeddings")).to eq([[1.2177734, 0.67529297, 2.0742188]])
3939
end
4040
end
4141

4242
describe "#classify" do
4343
let(:classify_result) { JSON.parse(File.read("spec/fixtures/classify_result.json")) }
4444
let(:response) { OpenStruct.new(body: classify_result) }
4545

46-
let(:inputs) {[
47-
{ text: "Dermatologists don't like her!", label: "Spam" },
48-
{ text: "Hello, open to this?", label: "Spam" }
49-
]}
50-
51-
let(:examples) {[
52-
"Confirm your email address",
53-
"hey i need u to send some $"
54-
]}
46+
let(:inputs) {
47+
[
48+
{text: "Dermatologists don't like her!", label: "Spam"},
49+
{text: "Hello, open to this?", label: "Spam"}
50+
]
51+
}
52+
53+
let(:examples) {
54+
[
55+
"Confirm your email address",
56+
"hey i need u to send some $"
57+
]
58+
}
5559

5660
before do
5761
allow_any_instance_of(Faraday::Connection).to receive(:post)
@@ -63,10 +67,10 @@
6367
res = instance.classify(
6468
inputs: inputs,
6569
examples: examples
66-
).dig('classifications')
70+
).dig("classifications")
6771

68-
expect(res.first.dig('prediction')).to eq("Not spam")
69-
expect(res.last.dig('prediction')).to eq("Spam")
72+
expect(res.first.dig("prediction")).to eq("Not spam")
73+
expect(res.last.dig("prediction")).to eq("Spam")
7074
end
7175
end
7276

@@ -83,7 +87,7 @@
8387
it "returns a response" do
8488
expect(instance.tokenize(
8589
text: "Hello, world!"
86-
).dig('tokens')).to eq([33555, 1114 , 34])
90+
).dig("tokens")).to eq([33555, 1114, 34])
8791
end
8892
end
8993

@@ -99,8 +103,8 @@
99103

100104
it "returns a response" do
101105
expect(instance.detokenize(
102-
tokens: [33555, 1114 , 34]
103-
).dig('text')).to eq("hello world!")
106+
tokens: [33555, 1114, 34]
107+
).dig("text")).to eq("hello world!")
104108
end
105109
end
106110

@@ -117,7 +121,7 @@
117121
it "returns a response" do
118122
expect(instance.detect_language(
119123
texts: ["Здравствуй, Мир"]
120-
).dig('results').first.dig('language_code')).to eq("ru")
124+
).dig("results").first.dig("language_code")).to eq("ru")
121125
end
122126
end
123127

@@ -133,27 +137,27 @@
133137

134138
it "returns a response" do
135139
expect(instance.summarize(
136-
text: "Ice cream is a sweetened frozen food typically eaten as a snack or dessert. " +
137-
"It may be made from milk or cream and is flavoured with a sweetener, " +
138-
"either sugar or an alternative, and a spice, such as cocoa or vanilla, " +
139-
"or with fruit such as strawberries or peaches. " +
140-
"It can also be made by whisking a flavored cream base and liquid nitrogen together. " +
141-
"Food coloring is sometimes added, in addition to stabilizers. " +
142-
"The mixture is cooled below the freezing point of water and stirred to incorporate air spaces " +
143-
"and to prevent detectable ice crystals from forming. The result is a smooth, " +
144-
"semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F). " +
145-
"It becomes more malleable as its temperature increases.\n\n" +
146-
"The meaning of the name \"ice cream\" varies from one country to another. " +
147-
"In some countries, such as the United States, \"ice cream\" applies only to a specific variety, " +
148-
"and most governments regulate the commercial use of the various terms according to the " +
149-
"relative quantities of the main ingredients, notably the amount of cream. " +
150-
"Products that do not meet the criteria to be called ice cream are sometimes labelled " +
151-
"\"frozen dairy dessert\" instead. In other countries, such as Italy and Argentina, " +
152-
"one word is used fo\r all variants. Analogues made from dairy alternatives, " +
153-
"such as goat's or sheep's milk, or milk substitutes " +
154-
"(e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are " +
140+
text: "Ice cream is a sweetened frozen food typically eaten as a snack or dessert. " \
141+
"It may be made from milk or cream and is flavoured with a sweetener, " \
142+
"either sugar or an alternative, and a spice, such as cocoa or vanilla, " \
143+
"or with fruit such as strawberries or peaches. " \
144+
"It can also be made by whisking a flavored cream base and liquid nitrogen together. " \
145+
"Food coloring is sometimes added, in addition to stabilizers. " \
146+
"The mixture is cooled below the freezing point of water and stirred to incorporate air spaces " \
147+
"and to prevent detectable ice crystals from forming. The result is a smooth, " \
148+
"semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F). " \
149+
"It becomes more malleable as its temperature increases.\n\n" \
150+
"The meaning of the name \"ice cream\" varies from one country to another. " \
151+
"In some countries, such as the United States, \"ice cream\" applies only to a specific variety, " \
152+
"and most governments regulate the commercial use of the various terms according to the " \
153+
"relative quantities of the main ingredients, notably the amount of cream. " \
154+
"Products that do not meet the criteria to be called ice cream are sometimes labelled " \
155+
"\"frozen dairy dessert\" instead. In other countries, such as Italy and Argentina, " \
156+
"one word is used fo\r all variants. Analogues made from dairy alternatives, " \
157+
"such as goat's or sheep's milk, or milk substitutes " \
158+
"(e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are " \
155159
"lactose intolerant, allergic to dairy protein or vegan."
156-
).dig('summary')).to eq("Ice cream is a frozen dessert made from dairy products or non-dairy substitutes. It is flavoured with a sweetener and a spice or with fruit. It is smooth and semi-solid at low temperatures.")
160+
).dig("summary")).to eq("Ice cream is a frozen dessert made from dairy products or non-dairy substitutes. It is flavoured with a sweetener and a spice or with fruit. It is smooth and semi-solid at low temperatures.")
157161
end
158162
end
159163
end

0 commit comments

Comments
 (0)