Class: Regent::LLM::OpenRouter

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

Constant Summary collapse

ENV_KEY =
"OPEN_ROUTER_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
25
26
# File 'lib/regent/llm/open_router.rb', line 10

def invoke(messages, **args)
  response = client.complete(
    messages,
    model: model,
    extras: {
      temperature: args[:temperature] || 0.0,
      stop: args[:stop] || [],
      **args
    }
  )
  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