-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunction_calling.rb
More file actions
61 lines (49 loc) · 1.69 KB
/
function_calling.rb
File metadata and controls
61 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require_relative "../bootstrap"
client = OpenAISwarm.new
def get_weather(location:)
"{'temp':67, 'unit':'F'}"
end
def get_news(category:)
[
"Tech Company A Acquires Startup B",
"New AI Model Revolutionizes Industry",
"Breakthrough in Quantum Computing"
].sample
end
get_news_instance = OpenAISwarm::FunctionDescriptor.new(
target_method: :get_news,
description: 'Get the latest news headlines. The category of news, e.g., world, business, sports.'
)
get_weather_instance = OpenAISwarm::FunctionDescriptor.new(
target_method: :get_weather,
description: 'Simulate fetching weather data'
)
agent = OpenAISwarm::Agent.new(
name: "Agent",
instructions: "You are a helpful agent.",
model: ENV['SWARM_AGENT_DEFAULT_MODEL'],
functions: [
get_weather_instance,
get_news_instance
]
)
guide_examples = <<~GUIDE_EXAMPLES
############# GUIDE_EXAMPLES #####################################
examples:
What's the weather in NYC?
Tell me the weather in New York and the latest news headlines.
Details:
1. Single Function Call
Example: “What’s the weather in NYC?”
Action: Calls get_weather with location “New York City”.
Response: Only provides weather details.
2. Multiple Function Calls
Example: “Tell me the weather in New York and the latest news headlines.”
Action: Calls get_weather for weather and get_news for news.
Response: Combines weather and news information.
params:
`DEBUG=1 ruby examples/basic/function_calling.rb` # turn on debug (default turn off)
################################################################
GUIDE_EXAMPLES
puts guide_examples
OpenAISwarm::Repl.run_demo_loop(agent, stream: true, debug: env_debug)