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 +4 -4
- data/Gemfile.lock +1 -1
- data/examples/airline/main.rb +1 -1
- data/examples/basic/function_calling.rb +57 -10
- data/lib/ruby-openai-swarm/agent.rb +11 -2
- data/lib/ruby-openai-swarm/core.rb +3 -0
- data/lib/ruby-openai-swarm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef97e65185db604611e9a15e4e5a3dcf3b35eb38e8c87e54040175f1947280b8
|
4
|
+
data.tar.gz: cac5ea7cad0afc755fd528e39e5f77c10db1ecbda43d94b4021863d6f1ac5cea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80460e88514e6e117d11de243ddb44f3d412b6c009f6d5ace6f18e82c615fef54f6ccab33e0e0ebb1ec0b9a2d762a2011ed8bef48dc3d0afaf6dd908eb07d331
|
7
|
+
data.tar.gz: 101d70a78daa2d7f2be6917b23aaa81ff0c6e76d37d6a49d5405af7983fd2ba19f974ef6620fec79b4899644a6b8c4d208b45df9292aee834456f6fea57bee6e
|
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, 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
|
-
|
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: [
|
31
|
+
functions: [
|
32
|
+
get_weather_instance,
|
33
|
+
get_news_instance
|
34
|
+
]
|
19
35
|
)
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
30
|
-
|
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,
|
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
|
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.
|
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-
|
11
|
+
date: 2024-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|