ruby-openai-swarm 0.2.2 → 0.2.4

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: 3d67b89e89e841ab9bdc643976530992131eb83bc4b472fc2420523e1e4eb469
4
- data.tar.gz: e243f02c680ed9f2623e4895fc6cd4dce51fc313c0e65506ab65c7da3c691185
3
+ metadata.gz: ef97e65185db604611e9a15e4e5a3dcf3b35eb38e8c87e54040175f1947280b8
4
+ data.tar.gz: cac5ea7cad0afc755fd528e39e5f77c10db1ecbda43d94b4021863d6f1ac5cea
5
5
  SHA512:
6
- metadata.gz: a45863631968a5d0bfc7798b18eb3d565dc231fc6f2472fe10fe6e08a545dfca38d574ba27a674841b8f42e03b2eb9e5cc072e3f153c53b1bf5efea4eddcf36e
7
- data.tar.gz: 0bf2a1cc69a4d82674152f2079cfc9e6c98f10cafeb9865bbc61c3840886cd7b821bf887c8f9f3f8081695b9d58826f29d21955a250819715ab4a2354b55a5bf
6
+ metadata.gz: 80460e88514e6e117d11de243ddb44f3d412b6c009f6d5ace6f18e82c615fef54f6ccab33e0e0ebb1ec0b9a2d762a2011ed8bef48dc3d0afaf6dd908eb07d331
7
+ data.tar.gz: 101d70a78daa2d7f2be6917b23aaa81ff0c6e76d37d6a49d5405af7983fd2ba19f974ef6620fec79b4899644a6b8c4d208b45df9292aee834456f6fea57bee6e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-openai-swarm (0.2.2)
4
+ ruby-openai-swarm (0.2.4)
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
@@ -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,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
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.2
4
+ version: 0.2.4
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-21 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