Class: Legion::Extensions::Llm::Canonical::Params
- Inherits:
-
Data
- Object
- Data
- Legion::Extensions::Llm::Canonical::Params
- Defined in:
- lib/legion/extensions/llm/canonical/params.rb
Overview
rubocop:disable Lint/ConstantDefinitionInBlock – required for Data.define block scope Canonical sampling and limit parameters for a request. Per G18: all standard/useful params are first-class, mapped per provider by translators.
Constant Summary collapse
- PARAMS_KNOWN_KEYS =
%i[max_tokens max_thinking_tokens temperature top_p top_k stop_sequences seed frequency_penalty presence_penalty response_format].freeze
Instance Attribute Summary collapse
-
#frequency_penalty ⇒ Object
readonly
Returns the value of attribute frequency_penalty.
-
#max_thinking_tokens ⇒ Object
readonly
Returns the value of attribute max_thinking_tokens.
-
#max_tokens ⇒ Object
readonly
Returns the value of attribute max_tokens.
-
#presence_penalty ⇒ Object
readonly
Returns the value of attribute presence_penalty.
-
#response_format ⇒ Object
readonly
Returns the value of attribute response_format.
-
#seed ⇒ Object
readonly
Returns the value of attribute seed.
-
#stop_sequences ⇒ Object
readonly
Returns the value of attribute stop_sequences.
-
#temperature ⇒ Object
readonly
Returns the value of attribute temperature.
-
#top_k ⇒ Object
readonly
Returns the value of attribute top_k.
-
#top_p ⇒ Object
readonly
Returns the value of attribute top_p.
Class Method Summary collapse
-
.from_hash(source) ⇒ Object
Build from a Hash (raw client request or deserialized wire payload).
Instance Method Summary collapse
-
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
Instance Attribute Details
#frequency_penalty ⇒ Object (readonly)
Returns the value of attribute frequency_penalty
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def frequency_penalty @frequency_penalty end |
#max_thinking_tokens ⇒ Object (readonly)
Returns the value of attribute max_thinking_tokens
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def max_thinking_tokens @max_thinking_tokens end |
#max_tokens ⇒ Object (readonly)
Returns the value of attribute max_tokens
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def max_tokens @max_tokens end |
#presence_penalty ⇒ Object (readonly)
Returns the value of attribute presence_penalty
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def presence_penalty @presence_penalty end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def response_format @response_format end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def seed @seed end |
#stop_sequences ⇒ Object (readonly)
Returns the value of attribute stop_sequences
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def stop_sequences @stop_sequences end |
#temperature ⇒ Object (readonly)
Returns the value of attribute temperature
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def temperature @temperature end |
#top_k ⇒ Object (readonly)
Returns the value of attribute top_k
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def top_k @top_k end |
#top_p ⇒ Object (readonly)
Returns the value of attribute top_p
11 12 13 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 11 def top_p @top_p end |
Class Method Details
.from_hash(source) ⇒ Object
Build from a Hash (raw client request or deserialized wire payload). Accepts both canonical key names and common provider spellings.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 22 def self.from_hash(source) return nil if source.nil? || source.empty? h = source.transform_keys(&:to_sym) # Normalize common provider key variations h[:max_tokens] ||= h.delete(:max_output_tokens) || h.delete(:num_predict) h[:max_thinking_tokens] ||= h.delete(:budget_tokens) || h.delete(:thinking_budget) h[:stop_sequences] ||= h.delete(:stop) # Filter to known keys only filtered = h.slice(*PARAMS_KNOWN_KEYS) # Return nil if all known values are nil return nil if filtered.all? { |_, v| v.nil? } new( max_tokens: filtered[:max_tokens], max_thinking_tokens: filtered[:max_thinking_tokens], temperature: filtered[:temperature], top_p: filtered[:top_p], top_k: filtered[:top_k], stop_sequences: filtered[:stop_sequences], seed: filtered[:seed], frequency_penalty: filtered[:frequency_penalty], presence_penalty: filtered[:presence_penalty], response_format: filtered[:response_format] ) end |
Instance Method Details
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
53 54 55 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 53 def to_h super.compact end |