Skip to content

Commit 6f05154

Browse files
standardrb fixes
1 parent c8e2fdc commit 6f05154

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

lib/google_palm_api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
module GooglePalmApi
66
class Error < StandardError; end
7-
7+
88
autoload :Client, "google_palm_api/client"
99
end

lib/google_palm_api/client.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Client
1313
temperature: 0.0,
1414
completion_model_name: "text-bison-001",
1515
chat_completion_model_name: "chat-bison-001",
16-
embeddings_model_name: "embedding-gecko-001",
16+
embeddings_model_name: "embedding-gecko-001"
1717
}
1818

1919
def initialize(api_key:)
@@ -52,7 +52,7 @@ def generate_text(
5252
response = connection.post("/v1beta2/models/#{DEFAULTS[:completion_model_name]}:generateText") do |req|
5353
req.params = {key: api_key}
5454

55-
req.body = {prompt: { text: prompt }}
55+
req.body = {prompt: {text: prompt}}
5656
req.body[:temperature] = temperature || DEFAULTS[:temperature]
5757
req.body[:candidate_count] = candidate_count if candidate_count
5858
req.body[:max_output_tokens] = max_output_tokens if max_output_tokens
@@ -99,7 +99,7 @@ def generate_chat_message(
9999
response = connection.post("/v1beta2/models/#{DEFAULTS[:chat_completion_model_name]}:generateMessage") do |req|
100100
req.params = {key: api_key}
101101

102-
req.body = {prompt: { messages: [{content: prompt}] }}
102+
req.body = {prompt: {messages: [{content: prompt}]}}
103103
req.body[:context] = context if context
104104
req.body[:examples] = examples if examples
105105
req.body[:messages] = messages if messages
@@ -110,7 +110,7 @@ def generate_chat_message(
110110
req.body[:client] = client if client
111111
end
112112
response.body
113-
end
113+
end
114114

115115
#
116116
# The embedding service in the PaLM API generates state-of-the-art embeddings for words, phrases, and sentences.
@@ -141,49 +141,49 @@ def embed(
141141

142142
#
143143
# Lists models available through the API.
144-
#
144+
#
145145
# @param [Integer] page_size
146146
# @param [String] page_token
147147
# @return [Hash]
148-
#
148+
#
149149
def list_models(page_size: nil, page_token: nil)
150150
response = connection.get("/v1beta2/models") do |req|
151151
req.params = {key: api_key}
152152

153153
req.params[:pageSize] = page_size if page_size
154154
req.params[:pageToken] = page_token if page_token
155155
end
156-
response.body
156+
response.body
157157
end
158158

159-
#
159+
#
160160
# Runs a model's tokenizer on a string and returns the token count.
161-
#
161+
#
162162
# @param [String] model
163163
# @param [String] prompt
164164
# @return [Hash]
165-
#
165+
#
166166
def count_message_tokens(model:, prompt:)
167167
response = connection.post("/v1beta2/models/#{model}:countMessageTokens") do |req|
168168
req.params = {key: api_key}
169169

170-
req.body = {prompt: { messages: [{content: prompt}] }}
170+
req.body = {prompt: {messages: [{content: prompt}]}}
171171
end
172172
response.body
173173
end
174174

175175
#
176176
# Gets information about a specific Model.
177-
#
177+
#
178178
# @param [String] name
179179
# @return [Hash]
180-
#
180+
#
181181
def get_model(model:)
182182
response = connection.get("/v1beta2/models/#{model}") do |req|
183183
req.params = {key: api_key}
184184
end
185185
response.body
186-
end
186+
end
187187

188188
private
189189

spec/google_palm_api/client_spec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171

7272
before do
7373
allow_any_instance_of(Faraday::Connection).to receive(:post)
74-
.with("/v1beta2/models/text-bison-001:generateText")
75-
.and_return(response)
74+
.with("/v1beta2/models/text-bison-001:generateText")
75+
.and_return(response)
7676
end
7777

7878
it "returns the generated text" do
@@ -84,15 +84,14 @@
8484
let(:fixture) { JSON.parse(File.read("spec/fixtures/generate_chat_message.json")) }
8585
let(:response) { OpenStruct.new(body: fixture) }
8686

87-
8887
before do
8988
allow_any_instance_of(Faraday::Connection).to receive(:post)
90-
.with("/v1beta2/models/chat-bison-001:generateMessage")
91-
.and_return(response)
89+
.with("/v1beta2/models/chat-bison-001:generateMessage")
90+
.and_return(response)
9291
end
9392

9493
it "returns the generated text" do
9594
expect(subject.generate_chat_message(prompt: "Hello!")).to eq(fixture)
96-
end
95+
end
9796
end
9897
end

0 commit comments

Comments
 (0)