Class: Soka::LLMs::OpenAI

Inherits:
Base
  • Object
show all
Defined in:
lib/soka/llms/openai.rb

Overview

OpenAI (GPT) LLM provider implementation

Constant Summary collapse

ENV_KEY =
'OPENAI_API_KEY'

Instance Attribute Summary

Attributes inherited from Base

#api_key, #model, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #streaming_chat, #supports_streaming?

Constructor Details

This class inherits a constructor from Soka::LLMs::Base

Instance Method Details

#chat(messages, **params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/soka/llms/openai.rb', line 9

def chat(messages, **params)
  request_params = build_request_params(messages, params)

  response = connection.post do |req|
    req.url '/v1/responses'
    req.headers['Authorization'] = "Bearer #{api_key}"
    req.body = request_params
  end

  parse_response(response)
rescue Faraday::Error => e
  handle_error(e)
end