ruby-openai-swarm 0.2.2 → 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: 3d67b89e89e841ab9bdc643976530992131eb83bc4b472fc2420523e1e4eb469
4
- data.tar.gz: e243f02c680ed9f2623e4895fc6cd4dce51fc313c0e65506ab65c7da3c691185
3
+ metadata.gz: ccab6a10acd813cb4a174589038d87cf1eb63d27e323f5333acf6ae53a663985
4
+ data.tar.gz: 78737dfe700a187d8b598ede955598971aeac20a26f0ddd793a4fea18872410d
5
5
  SHA512:
6
- metadata.gz: a45863631968a5d0bfc7798b18eb3d565dc231fc6f2472fe10fe6e08a545dfca38d574ba27a674841b8f42e03b2eb9e5cc072e3f153c53b1bf5efea4eddcf36e
7
- data.tar.gz: 0bf2a1cc69a4d82674152f2079cfc9e6c98f10cafeb9865bbc61c3840886cd7b821bf887c8f9f3f8081695b9d58826f29d21955a250819715ab4a2354b55a5bf
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.2.2)
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
@@ -1,3 +1,3 @@
1
1
  module OpenAISwarm
2
- VERSION = "0.2.2"
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.2
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-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