164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/monadic_chat/open_ai.rb', line 164
def run(params, research_mode: false, timeout_sec: 60, num_retrials: 1, &block)
method = OpenAI.model_to_method(params["model"])
response = OpenAI.query(@access_token, "post", method, timeout_sec, params, &block)
if response["error"]
raise response["error"]["message"]
elsif response["choices"][0]["finish_reason"] == "length"
raise "finished because of length"
end
if research_mode
get_json response["choices"][0]["text"]
else
response["choices"][0]["text"]
end
rescue StandardError => e
case num_retrials
when 0
raise e
else
run(params, research_mode: research_mode, timeout_sec: timeout_sec, num_retrials: num_retrials - 1, &block)
end
end
|