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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccab6a10acd813cb4a174589038d87cf1eb63d27e323f5333acf6ae53a663985
4
- data.tar.gz: 78737dfe700a187d8b598ede955598971aeac20a26f0ddd793a4fea18872410d
3
+ metadata.gz: cbea41bea26f5e39c1441ed97500e665d40a690d70e7e1808b860a45acafd748
4
+ data.tar.gz: 7bb5230432bd503ff5e6a6cd263d75acd2070846cc6df75442519cf35fd9ade8
5
5
  SHA512:
6
- metadata.gz: '097fefd36ba24bcfa9a566e5cce325b2baf8aa1ae62a7382046752e1c1872ece6a12496ada95db3f089f54b1d7f4a0aff253bd2fc734ba46083f03b04d4c46bc'
7
- data.tar.gz: 963693d7321e959d1fd44fea1f70cda22cc789f76e544af2481a4d4134b908d698c32343e002ea59acbf00f495c3e48f9b18fd6bb53fbd72d422048054e822a7
6
+ metadata.gz: 1763ee7808957a4ae784681f6505c227af4dcadaddde476447dc0dd6837f64d6106e9b91f6b50be9fc3dc0b1da948c579a2850db4f4cd1b0843eaa6227c88333
7
+ data.tar.gz: 07fc02cfef9035871e28726171d8f4de803332fa38be5d0964c985ee71b8473317f21dc2a839fad281c805a3822de890907113e9cf683db470987babce22a7ee
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai-swarm (0.2.3)
4
+ ruby-openai-swarm (0.2.5)
5
5
  ruby-openai (~> 7.3)
6
6
 
7
7
  GEM
@@ -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, stream: true, debug: env_debug)
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
- # OpenAISwarm::Repl.run_demo_loop(agent, stream: true, debug: env_debug)
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, :description
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
@@ -1,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-openai-swarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson