Class: LlmGateway::Clients::Groq

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

Instance Attribute Summary

Attributes inherited from BaseClient

#api_key, #base_endpoint, #model_key

Instance Method Summary collapse

Methods inherited from BaseClient

#get, #post, #post_file, #post_stream

Constructor Details

#initialize(model_key: "openai/gpt-oss-120b", api_key: ENV["GROQ_API_KEY"]) ⇒ Groq

Returns a new instance of Groq.



8
9
10
11
# File 'lib/llm_gateway/clients/groq.rb', line 8

def initialize(model_key: "openai/gpt-oss-120b", api_key: ENV["GROQ_API_KEY"])
  @base_endpoint = "https://api.groq.com/openai/v1"
  super(model_key: model_key, api_key: api_key)
end

Instance Method Details

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



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

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

  post("chat/completions", body)
end

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



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

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

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