Sha256: e7d8eae33f428f396556ee2096227e9238a0fda188b61cf18ea51cbab3df5e37

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

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: "gpt-4o-mini",
  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)

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruby-openai-swarm-0.4.0.1 examples/basic/function_calling.rb
ruby-openai-swarm-0.4.0 examples/basic/function_calling.rb
ruby-openai-swarm-0.3.1 examples/basic/function_calling.rb
ruby-openai-swarm-0.2.9 examples/basic/function_calling.rb
ruby-openai-swarm-0.2.8 examples/basic/function_calling.rb
ruby-openai-swarm-0.2.7 examples/basic/function_calling.rb
ruby-openai-swarm-0.2.5 examples/basic/function_calling.rb