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
- .map(options) ⇒ Object
- .normalize_reasoning_effort(reasoning) ⇒ Object
- .normalize_response_format(response_format) ⇒ Object
- .validate_options!(mapped_options) ⇒ Object
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() = .reject { |key, _| MANAGED_OPTIONS.include?(key) } [:temperature] = .key?(:temperature) ? [:temperature] : DEFAULT_TEMPERATURE [:max_completion_tokens] = [:max_completion_tokens] || DEFAULT_MAX_COMPLETION_TOKENS [:response_format] = normalize_response_format([:response_format] || "text") reasoning = [:reasoning] unless reasoning.nil? || reasoning.to_s == "none" [:reasoning_effort] = normalize_reasoning_effort(reasoning) [:reasoning_format] = "parsed" end () end |
.normalize_reasoning_effort(reasoning) ⇒ Object
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
86 87 88 89 90 91 92 93 |
# File 'lib/llm_gateway/adapters/groq/option_mapper.rb', line 86 def () = .keys - VALID_OPTIONS return if .empty? raise ArgumentError, "Unknown Groq Chat Completions options: #{.join(', ')}. " \ "Valid options: #{VALID_OPTIONS.join(', ')}." end |