Class: OmniAgent::Providers::OpenAI

Inherits:
Base
  • Object
show all
Defined in:
lib/omni_agent/providers/openai.rb

Instance Attribute Summary

Attributes inherited from Base

#model

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from OmniAgent::Providers::Base

Instance Method Details

#chat(messages:, tools: [], **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/omni_agent/providers/openai.rb', line 15

def chat(messages:, tools: [], **options)
  openai_tools = tools.map { |tool| format_tool(tool) }

  payload = {
    model: model,
    messages: messages
  }
  payload[:tools] = openai_tools if openai_tools.any?
  payload.merge!(options) if options.any?

  response = client.chat.completions.create(**payload)

  parse_response(response)
rescue => e 
  puts "Error during OpenAI chat: #{e.message}"
end