ruby-openai-swarm 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/examples/airline/main.rb +1 -1
- data/examples/basic/function_calling.rb +1 -17
- data/lib/ruby-openai-swarm/core.rb +3 -0
- data/lib/ruby-openai-swarm/function_descriptor.rb +5 -2
- data/lib/ruby-openai-swarm/util.rb +8 -5
- data/lib/ruby-openai-swarm/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: cbea41bea26f5e39c1441ed97500e665d40a690d70e7e1808b860a45acafd748
|
4
|
+
data.tar.gz: 7bb5230432bd503ff5e6a6cd263d75acd2070846cc6df75442519cf35fd9ade8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1763ee7808957a4ae784681f6505c227af4dcadaddde476447dc0dd6837f64d6106e9b91f6b50be9fc3dc0b1da948c579a2850db4f4cd1b0843eaa6227c88333
|
7
|
+
data.tar.gz: 07fc02cfef9035871e28726171d8f4de803332fa38be5d0964c985ee71b8473317f21dc2a839fad281c805a3822de890907113e9cf683db470987babce22a7ee
|
data/Gemfile.lock
CHANGED
data/examples/airline/main.rb
CHANGED
@@ -65,4 +65,4 @@ params:
|
|
65
65
|
GUIDE_EXAMPLES
|
66
66
|
puts guide_examples
|
67
67
|
|
68
|
-
OpenAISwarm::Repl.run_demo_loop(triage_agent, context_variables: context_variables,
|
68
|
+
OpenAISwarm::Repl.run_demo_loop(triage_agent, context_variables: context_variables, debug: env_debug)
|
@@ -46,7 +46,6 @@ Details:
|
|
46
46
|
Example: “What’s the weather in NYC?”
|
47
47
|
Action: Calls get_weather with location “New York City”.
|
48
48
|
Response: Only provides weather details.
|
49
|
-
|
50
49
|
2. Multiple Function Calls
|
51
50
|
Example: “Tell me the weather in New York and the latest news headlines.”
|
52
51
|
Action: Calls get_weather for weather and get_news for news.
|
@@ -59,19 +58,4 @@ GUIDE_EXAMPLES
|
|
59
58
|
|
60
59
|
puts guide_examples
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
OpenAISwarm.new.run_and_stream(
|
65
|
-
agent: agent,
|
66
|
-
debug: true,
|
67
|
-
messages: [{"role" => "user", "content" => "Tell me the weather in New York and the latest news headlines."}]
|
68
|
-
) do |chunk|
|
69
|
-
if chunk.key?("content") && !chunk["content"].nil?
|
70
|
-
puts ">>>#{chunk}"
|
71
|
-
end
|
72
|
-
|
73
|
-
if chunk.key?('response')
|
74
|
-
binding.pry
|
75
|
-
# log_llm_request(chunk['response'])
|
76
|
-
end
|
77
|
-
end
|
61
|
+
OpenAISwarm::Repl.run_demo_loop(agent, stream: true, debug: env_debug)
|
@@ -212,6 +212,9 @@ module OpenAISwarm
|
|
212
212
|
|
213
213
|
yield({ delim: "start" }) if block_given?
|
214
214
|
completion.each do |chunk|
|
215
|
+
|
216
|
+
raise OpenAISwarm::Error.new(chunk['error']) if chunk['error']
|
217
|
+
|
215
218
|
delta = chunk.dig('choices', 0, 'delta')
|
216
219
|
if delta['role'] == "assistant"
|
217
220
|
delta['sender'] = active_agent.name
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module OpenAISwarm
|
2
2
|
class FunctionDescriptor
|
3
|
-
attr_reader :target_method,
|
3
|
+
attr_reader :target_method,
|
4
|
+
:description,
|
5
|
+
:parameters
|
4
6
|
|
5
|
-
def initialize(target_method:, description: '')
|
7
|
+
def initialize(target_method:, description: '', parameters: nil)
|
6
8
|
@target_method = target_method.is_a?(Method) ? target_method : method(target_method)
|
7
9
|
@description = description
|
10
|
+
@parameters = parameters
|
8
11
|
end
|
9
12
|
end
|
10
13
|
end
|
@@ -52,6 +52,7 @@ module OpenAISwarm
|
|
52
52
|
def self.function_to_json(func_instance)
|
53
53
|
is_target_method = func_instance.respond_to?(:target_method) || func_instance.is_a?(OpenAISwarm::FunctionDescriptor)
|
54
54
|
func = is_target_method ? func_instance.target_method : func_instance
|
55
|
+
custom_parameters = is_target_method ? func_instance.parameters : nil
|
55
56
|
|
56
57
|
function_name = func.name
|
57
58
|
function_parameters = func.parameters
|
@@ -82,16 +83,18 @@ module OpenAISwarm
|
|
82
83
|
|
83
84
|
description = func_instance.respond_to?(:description) ? func_instance&.description : nil
|
84
85
|
|
86
|
+
json_parameters = {
|
87
|
+
type: "object",
|
88
|
+
properties: parameters,
|
89
|
+
required: required
|
90
|
+
}
|
91
|
+
|
85
92
|
{
|
86
93
|
type: "function",
|
87
94
|
function: {
|
88
95
|
name: function_name,
|
89
96
|
description: description || '',
|
90
|
-
parameters:
|
91
|
-
type: "object",
|
92
|
-
properties: parameters,
|
93
|
-
required: required
|
94
|
-
}
|
97
|
+
parameters: custom_parameters || json_parameters
|
95
98
|
}
|
96
99
|
}
|
97
100
|
end
|