Sha256: 658aef905d8e4556e1e950d6e5beb9ef296d16a966e3e0b7140f90ff22a96899

Contents?: true

Size: 691 Bytes

Versions: 15

Compression:

Stored size: 691 Bytes

Contents

require_relative "../bootstrap"

client = OpenAISwarm.new

agent = OpenAISwarm::Agent.new(
  name: "Agent",
  instructions: "You are a helpful agent.",
  model: "gpt-4o-mini",
)

def pretty_print_messages(messages)
  messages.each do |message|
    next if message["content"].nil?
    puts "#{message["sender"]}: #{message["content"]}"
  end
end

messages = []
loop do
  print "> "
  user_input = gets.chomp

  break if user_input.downcase == "exit"

  messages << { "role": "user", "content": user_input }
  response = client.run(agent: agent, messages: messages)

  messages.concat(response.messages)
  agent = response.agent

  pretty_print_messages(response.messages)
end
puts "Goodbye!"

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ruby-openai-swarm-0.4.0.1 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.4.0 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.3.1 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.3.0.1 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.3.0 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.9 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.8 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.7 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.6 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.5 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.4 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.3 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.2 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.1 examples/basic/simple_loop_no_helpers.rb
ruby-openai-swarm-0.2.0 examples/basic/simple_loop_no_helpers.rb