smart_prompt 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/smart_prompt/anthropic_adapter.rb +49 -5
- data/lib/smart_prompt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 396c6097973289a34143e86b65f428d55919d0e755916992a5c714e289ebf5a2
|
|
4
|
+
data.tar.gz: 5d2c2d81b486e1fb05b53f116047ab1f90be77c9536fd6440a96b573bdad00c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6880395149678a195ea6efc46a81623d61c14c56534936041a625616a9e6b716597c078ccee0ac0d47c3b2a8e67d272742ee36940fa64321426799db0b26e4d
|
|
7
|
+
data.tar.gz: 63f0b8ae0f6f62363443731cae6fed3eafe746c463d259c9b88eee8563d6ef0cdcd84e684d6daeedd7329c3dcab84748ab62358fa2935b9d0278ec347df45ffb
|
|
@@ -239,16 +239,60 @@ module SmartPrompt
|
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
def extract_content(response)
|
|
242
|
-
|
|
242
|
+
text_parts = []
|
|
243
|
+
tool_calls = []
|
|
244
|
+
|
|
245
|
+
response.fetch("content", []).each do |block|
|
|
243
246
|
case block["type"]
|
|
244
247
|
when "text"
|
|
245
|
-
block["text"].to_s
|
|
248
|
+
text_parts << block["text"].to_s
|
|
246
249
|
when "tool_use"
|
|
247
|
-
block
|
|
250
|
+
tool_calls << openai_tool_call(block)
|
|
248
251
|
else
|
|
249
|
-
block.to_s
|
|
252
|
+
text_parts << block.to_s
|
|
250
253
|
end
|
|
251
|
-
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
content = text_parts.join
|
|
257
|
+
return content if tool_calls.empty?
|
|
258
|
+
|
|
259
|
+
openai_response(response, content, tool_calls)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def openai_response(response, content, tool_calls)
|
|
263
|
+
{
|
|
264
|
+
"id" => response["id"],
|
|
265
|
+
"object" => "chat.completion",
|
|
266
|
+
"created" => Time.now.to_i,
|
|
267
|
+
"model" => response["model"],
|
|
268
|
+
"choices" => [{
|
|
269
|
+
"index" => 0,
|
|
270
|
+
"message" => {
|
|
271
|
+
"role" => "assistant",
|
|
272
|
+
"content" => content,
|
|
273
|
+
"tool_calls" => tool_calls,
|
|
274
|
+
},
|
|
275
|
+
"finish_reason" => openai_finish_reason(response["stop_reason"]),
|
|
276
|
+
}],
|
|
277
|
+
"usage" => response["usage"],
|
|
278
|
+
}
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def openai_tool_call(block)
|
|
282
|
+
{
|
|
283
|
+
"id" => block["id"],
|
|
284
|
+
"type" => "function",
|
|
285
|
+
"function" => {
|
|
286
|
+
"name" => block["name"],
|
|
287
|
+
"arguments" => JSON.generate(block["input"] || {}),
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def openai_finish_reason(stop_reason)
|
|
293
|
+
return "tool_calls" if stop_reason == "tool_use"
|
|
294
|
+
|
|
295
|
+
stop_reason
|
|
252
296
|
end
|
|
253
297
|
end
|
|
254
298
|
end
|
data/lib/smart_prompt/version.rb
CHANGED