Skip to content

Commit c522de7

Browse files
standardrb fixes
1 parent 5fcb004 commit c522de7

File tree

2 files changed

+56
-52
lines changed

2 files changed

+56
-52
lines changed

lib/cohere/client.rb

Lines changed: 14 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
@@ -137,4 +137,4 @@ def connection
137137
end
138138
end
139139
end
140-
end
140+
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)