Class: Rasti::AI::OpenAI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rasti/ai/open_ai/client.rb

Constant Summary collapse

BASE_URL =
'https://api.openai.com/v1'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, logger: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/rasti/ai/open_ai/client.rb', line 8

def initialize(api_key:nil, logger:nil)
  @api_key = api_key || Rasti::AI.openai_api_key
  @logger = logger || Rasti::AI.logger
end

Instance Method Details

#chat_completions(messages:, model: nil, tools: [], response_format: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rasti/ai/open_ai/client.rb', line 13

def chat_completions(messages:, model:nil, tools:[], response_format: nil)
  body = {
    model: model || Rasti::AI.openai_default_model,
    messages: messages,
    tools: tools,
    tool_choice: tools.empty? ? 'none' : 'auto'
  }

  body[:response_format] = response_format unless response_format.nil?

  post '/chat/completions', body
end