Module: LlmGateway::Adapters::AnthropicOptionMapper
- Defined in:
- lib/llm_gateway/adapters/anthropic_option_mapper.rb
Constant Summary collapse
- DEFAULT_MAX_TOKENS =
20_480- REASONING_EFFORT_BUDGET_TOKENS =
{ "low" => 1024, "medium" => 5 * 1024, "high" => 10 * 1024, "xhigh" => 20 * 1024 }.freeze
Class Method Summary collapse
- .map(options) ⇒ Object
- .normalize_output_config(response_format) ⇒ Object
- .normalize_reasoning(reasoning) ⇒ Object
Class Method Details
.map(options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/llm_gateway/adapters/anthropic_option_mapper.rb', line 16 def map() = .reject { |key, _| %i[reasoning max_completion_tokens response_format prompt_cache_retention cache_key prompt_cache_key].include?(key) } [:max_tokens] = [:max_completion_tokens] || DEFAULT_MAX_TOKENS retention = [:cache_retention] [:cache_retention] = retention unless retention.nil? response_format = [:response_format] [:output_config] = normalize_output_config(response_format) unless response_format.nil? reasoning = [:reasoning] return if reasoning.nil? || reasoning.to_s == "none" [:thinking] = normalize_reasoning(reasoning) end |
.normalize_output_config(response_format) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/llm_gateway/adapters/anthropic_option_mapper.rb', line 33 def normalize_output_config(response_format) format_type = response_format.is_a?(Hash) ? response_format[:type] || response_format["type"] : response_format case format_type.to_s when "json_object", "json_schema" { format: "json_schema" } else { format: "text" } end end |
.normalize_reasoning(reasoning) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/llm_gateway/adapters/anthropic_option_mapper.rb', line 44 def normalize_reasoning(reasoning) budget_tokens = REASONING_EFFORT_BUDGET_TOKENS[reasoning.to_s] || raise(ArgumentError, "Invalid reasoning '#{reasoning}'. Use 'none', 'low', 'medium', 'high', or 'xhigh'.") { type: "enabled", budget_tokens: budget_tokens } end |