Module: LlmGateway::Adapters::Groq::OptionMapper

Defined in:
lib/llm_gateway/adapters/groq/option_mapper.rb

Constant Summary collapse

DEFAULT_TEMPERATURE =
0
DEFAULT_MAX_COMPLETION_TOKENS =
20_480
VALID_REASONING_LEVELS =
%w[default low medium high].freeze
VALID_OPTIONS =

Source: console.groq.com/docs/text-chat.md and console.groq.com/docs/api-reference.md#chat-create API: Groq Chat Completions Create; accessed 2026-05-19. Body parameters listed by the API reference: messages, model, citation_options, compound_custom, disable_tool_validation, documents, exclude_domains, frequency_penalty, function_call, functions, include_domains, include_reasoning, logit_bias, logprobs, max_completion_tokens, max_tokens, metadata, n, parallel_tool_calls, presence_penalty, reasoning_effort, reasoning_format, response_format, search_settings, seed, service_tier, stop, store, stream, stream_options, temperature, tool_choice, tools, top_logprobs, top_p, user. This mapper intentionally excludes transcript/tool structural fields (messages, tools) from option handling.

%i[
  model
  citation_options
  compound_custom
  disable_tool_validation
  documents
  exclude_domains
  frequency_penalty
  function_call
  functions
  include_domains
  include_reasoning
  logit_bias
  logprobs
  max_completion_tokens
  max_tokens
  metadata
  n
  parallel_tool_calls
  presence_penalty
  reasoning_effort
  reasoning_format
  response_format
  search_settings
  seed
  service_tier
  stop
  store
  stream
  stream_options
  temperature
  tool_choice
  top_logprobs
  top_p
  user
].freeze
MANAGED_OPTIONS =
%i[
  reasoning
  cache_key
  cache_retention
].freeze

Class Method Summary collapse

Class Method Details

.map(options) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/llm_gateway/adapters/groq/option_mapper.rb', line 70

def map(options)
  mapped_options = options.reject { |key, _| MANAGED_OPTIONS.include?(key) }
  mapped_options[:temperature] = options.key?(:temperature) ? options[:temperature] : DEFAULT_TEMPERATURE
  mapped_options[:max_completion_tokens] = options[:max_completion_tokens] || DEFAULT_MAX_COMPLETION_TOKENS
  mapped_options[:response_format] = normalize_response_format(options[:response_format] || "text")

  reasoning = options[:reasoning]
  unless reasoning.nil? || reasoning.to_s == "none"
    mapped_options[:reasoning_effort] = normalize_reasoning_effort(reasoning)
    mapped_options[:reasoning_format] = "parsed"
  end

  validate_options!(mapped_options)
  mapped_options
end

.normalize_reasoning_effort(reasoning) ⇒ Object

Raises:

  • (ArgumentError)


103
104
105
106
107
108
# File 'lib/llm_gateway/adapters/groq/option_mapper.rb', line 103

def normalize_reasoning_effort(reasoning)
  effort = reasoning.to_s
  return effort if VALID_REASONING_LEVELS.include?(effort)

  raise ArgumentError, "Invalid reasoning '#{reasoning}'. Use 'none', 'default', 'low', 'medium', or 'high'."
end

.normalize_response_format(response_format) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/llm_gateway/adapters/groq/option_mapper.rb', line 95

def normalize_response_format(response_format)
  if response_format.is_a?(String)
    { type: response_format }
  else
    response_format
  end
end

.validate_options!(mapped_options) ⇒ Object

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
93
# File 'lib/llm_gateway/adapters/groq/option_mapper.rb', line 86

def validate_options!(mapped_options)
  unknown_options = mapped_options.keys - VALID_OPTIONS
  return if unknown_options.empty?

  raise ArgumentError,
        "Unknown Groq Chat Completions options: #{unknown_options.join(', ')}. " \
        "Valid options: #{VALID_OPTIONS.join(', ')}."
end