Class: LlmGateway::Clients::Groq

Inherits:
BaseClient show all
Defined in:
lib/llm_gateway/clients/groq.rb

Constant Summary collapse

DEFAULT_MODEL =
"openai/gpt-oss-120b"

Instance Attribute Summary

Attributes inherited from BaseClient

#api_key, #base_endpoint

Instance Method Summary collapse

Methods inherited from BaseClient

#get, #post, #post_file, #post_stream

Constructor Details

#initialize(api_key: ENV["GROQ_API_KEY"]) ⇒ Groq

Returns a new instance of Groq.



10
11
12
13
# File 'lib/llm_gateway/clients/groq.rb', line 10

def initialize(api_key: ENV["GROQ_API_KEY"])
  @base_endpoint = "https://api.groq.com/openai/v1"
  super(api_key: api_key)
end

Instance Method Details

#chat(messages, tools: nil, system: [], model: DEFAULT_MODEL, **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/llm_gateway/clients/groq.rb', line 15

def chat(messages, tools: nil, system: [], model: DEFAULT_MODEL, **options)
  body = {
    model: model,
    messages: system + messages,
    tools: tools
  }
  body.merge!(options)

  post("chat/completions", body)
end

#stream(messages, tools: nil, system: [], model: DEFAULT_MODEL, **options, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/llm_gateway/clients/groq.rb', line 26

def stream(messages, tools: nil, system: [], model: DEFAULT_MODEL, **options, &block)
  body = {
    model: model,
    messages: system + messages,
    tools: tools,
    stream_options: { include_usage: true }
  }
  body.merge!(options)

  post_stream("chat/completions", body, &block)
end