ruby-openai-swarm 0.2.1 → 0.2.3

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: b48c60ccd21aaf774b8c7b8a325f42e3dc536d7c8ccea30930fd20f15e5d8903
4
- data.tar.gz: 9962aca258023744e3e6cae3ccebb2f1212f8b2136ab7546fb92f9f919917e5a
3
+ metadata.gz: ccab6a10acd813cb4a174589038d87cf1eb63d27e323f5333acf6ae53a663985
4
+ data.tar.gz: 78737dfe700a187d8b598ede955598971aeac20a26f0ddd793a4fea18872410d
5
5
  SHA512:
6
- metadata.gz: d067c62379602b8f0b267eaf4168f14faf96112444f1abe7731145c99f34efe19045d967c2d90e854bb277e64e8659f8a7e7884dfc4f2a5aca990f3d786c2944
7
- data.tar.gz: 77eaae12e12a5dd0a3db95737c9221ed867ea0aacb40847020da7de42631c0f51414aeb3b8901658be82b3b5cebc6b76045d2a8f2b20262fb8772ed1812b51b5
6
+ metadata.gz: '097fefd36ba24bcfa9a566e5cce325b2baf8aa1ae62a7382046752e1c1872ece6a12496ada95db3f089f54b1d7f4a0aff253bd2fc734ba46083f03b04d4c46bc'
7
+ data.tar.gz: 963693d7321e959d1fd44fea1f70cda22cc789f76e544af2481a4d4134b908d698c32343e002ea59acbf00f495c3e48f9b18fd6bb53fbd72d422048054e822a7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai-swarm (0.1.0)
4
+ ruby-openai-swarm (0.2.3)
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, debug: env_debug)
68
+ OpenAISwarm::Repl.run_demo_loop(triage_agent, context_variables: context_variables, stream: true, debug: env_debug)
@@ -6,7 +6,20 @@ def get_weather(location:)
6
6
  "{'temp':67, 'unit':'F'}"
7
7
  end
8
8
 
9
- function_instance = OpenAISwarm::FunctionDescriptor.new(
9
+ def get_news(category:)
10
+ [
11
+ "Tech Company A Acquires Startup B",
12
+ "New AI Model Revolutionizes Industry",
13
+ "Breakthrough in Quantum Computing"
14
+ ].sample
15
+ end
16
+
17
+ get_news_instance = OpenAISwarm::FunctionDescriptor.new(
18
+ target_method: :get_news,
19
+ description: 'Get the latest news headlines. The category of news, e.g., world, business, sports.'
20
+ )
21
+
22
+ get_weather_instance = OpenAISwarm::FunctionDescriptor.new(
10
23
  target_method: :get_weather,
11
24
  description: 'Simulate fetching weather data'
12
25
  )
@@ -15,16 +28,50 @@ agent = OpenAISwarm::Agent.new(
15
28
  name: "Agent",
16
29
  instructions: "You are a helpful agent.",
17
30
  model: "gpt-4o-mini",
18
- functions: [function_instance]
31
+ functions: [
32
+ get_weather_instance,
33
+ get_news_instance
34
+ ]
19
35
  )
20
- # debugger logger: {:model=>"gpt-4o-mini", :messages=>[{:role=>"system", :content=>"You are a helpful agent."}, {"role"=>"user", "content"=>"What's the weather in NYC?"}], :tools=>[{:type=>"function", :function=>{:name=>"get_weather", :description=>"", :parameters=>{:type=>"object", :properties=>{:location=>{:type=>"string"}}, :required=>["location"]}}}], :stream=>false, :parallel_tool_calls=>true}
21
- response = client.run(
22
- messages: [{"role" => "user", "content" => "What's the weather in NYC?"}],
36
+
37
+ guide_examples = <<~GUIDE_EXAMPLES
38
+ ############# GUIDE_EXAMPLES #####################################
39
+ examples:
40
+ What's the weather in NYC?
41
+
42
+ Tell me the weather in New York and the latest news headlines.
43
+
44
+ Details:
45
+ 1. Single Function Call
46
+ Example: “What’s the weather in NYC?”
47
+ Action: Calls get_weather with location “New York City”.
48
+ Response: Only provides weather details.
49
+
50
+ 2. Multiple Function Calls
51
+ Example: “Tell me the weather in New York and the latest news headlines.”
52
+ Action: Calls get_weather for weather and get_news for news.
53
+ Response: Combines weather and news information.
54
+
55
+ params:
56
+ `DEBUG=1 ruby examples/basic/function_calling.rb` # turn on debug (default turn off)
57
+ ################################################################
58
+ GUIDE_EXAMPLES
59
+
60
+ puts guide_examples
61
+
62
+ # OpenAISwarm::Repl.run_demo_loop(agent, stream: true, debug: env_debug)
63
+
64
+ OpenAISwarm.new.run_and_stream(
23
65
  agent: agent,
24
66
  debug: true,
25
- )
26
-
27
- pp response.messages.last
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
28
72
 
29
- # print(response.messages[-1]["content"])
30
- # The current temperature in New York City is 67°F. => nil
73
+ if chunk.key?('response')
74
+ binding.pry
75
+ # log_llm_request(chunk['response'])
76
+ end
77
+ end
@@ -1,6 +1,13 @@
1
1
  module OpenAISwarm
2
2
  class Agent
3
- attr_accessor :name, :model, :instructions, :functions, :tool_choice, :parallel_tool_calls
3
+ attr_accessor :name, :model, :instructions,
4
+ :functions, :tool_choice,
5
+ :parallel_tool_calls,
6
+ :resource
7
+ # These attributes can be read and written externally. They include:
8
+ # - name: The name of the agent.
9
+ # - model: The model used, e.g., "gpt-4".
10
+ # - resource: Additional custom parameters or data that the agent might need.
4
11
 
5
12
  def initialize(
6
13
  name: "Agent",
@@ -8,7 +15,8 @@ module OpenAISwarm
8
15
  instructions: "You are a helpful agent.",
9
16
  functions: [],
10
17
  tool_choice: nil,
11
- parallel_tool_calls: true
18
+ parallel_tool_calls: true,
19
+ resource: nil
12
20
  )
13
21
  @name = name
14
22
  @model = model
@@ -16,6 +24,7 @@ module OpenAISwarm
16
24
  @functions = functions
17
25
  @tool_choice = tool_choice
18
26
  @parallel_tool_calls = parallel_tool_calls
27
+ @resource = resource
19
28
  end
20
29
  end
21
30
  end
@@ -102,10 +102,10 @@ module OpenAISwarm
102
102
  unless function_map.key?(name)
103
103
  Util.debug_print(debug, "Tool #{name} not found in function map.")
104
104
  partial_response.messages << {
105
- role: 'tool',
106
- tool_call_id: tool_call['id'],
107
- tool_name: name,
108
- content: "Error: Tool #{name} not found."
105
+ 'role' => 'tool',
106
+ 'tool_call_id' => tool_call['id'],
107
+ 'tool_name' => name,
108
+ 'content' => "Error: Tool #{name} not found."
109
109
  }
110
110
  next
111
111
  end
@@ -123,10 +123,10 @@ module OpenAISwarm
123
123
  result = handle_function_result(raw_result, debug)
124
124
 
125
125
  partial_response.messages << {
126
- role: 'tool',
127
- tool_call_id: tool_call['id'],
128
- tool_name: name,
129
- content: result.value
126
+ 'role' => 'tool',
127
+ 'tool_call_id' => tool_call['id'],
128
+ 'tool_name' => name,
129
+ 'content' => result.value
130
130
  }
131
131
 
132
132
  partial_response.context_variables.merge!(result.context_variables)
@@ -1,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-openai-swarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-05 00:00:00.000000000 Z
11
+ date: 2024-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai