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 +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/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: ccab6a10acd813cb4a174589038d87cf1eb63d27e323f5333acf6ae53a663985
|
4
|
+
data.tar.gz: 78737dfe700a187d8b598ede955598971aeac20a26f0ddd793a4fea18872410d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '097fefd36ba24bcfa9a566e5cce325b2baf8aa1ae62a7382046752e1c1872ece6a12496ada95db3f089f54b1d7f4a0aff253bd2fc734ba46083f03b04d4c46bc'
|
7
|
+
data.tar.gz: 963693d7321e959d1fd44fea1f70cda22cc789f76e544af2481a4d4134b908d698c32343e002ea59acbf00f495c3e48f9b18fd6bb53fbd72d422048054e822a7
|
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
|
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.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-
|
11
|
+
date: 2024-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|