Class: Regent::LLM::OpenAI

Inherits:
Base
  • Object
show all
Defined in:
lib/regent/llm/open_ai.rb

Constant Summary collapse

ENV_KEY =
"OPENAI_API_KEY"

Instance Method Summary collapse

Methods inherited from Base

#initialize, #parse_error

Methods included from Concerns::Dependable

included, #initialize, #require_dynamic

Constructor Details

This class inherits a constructor from Regent::LLM::Base

Instance Method Details

#invoke(messages, **args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/regent/llm/open_ai.rb', line 10

def invoke(messages, **args)
  response = client.chat(parameters: {
    messages: messages,
    model: model,
    temperature: args[:temperature] || 0.0,
    stop: args[:stop] || []
  })

  result(
    model: model,
    content: response.dig("choices", 0, "message", "content"),
    input_tokens: response.dig("usage", "prompt_tokens"),
    output_tokens: response.dig("usage", "completion_tokens")
  )
end