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
Canonical sampling and limit parameters for a request. Per G18: all standard/useful params are first-class, mapped per provider by translators. Canonical keys only (O03a): provider spellings are translated at the edges.
Constant Summary collapse
- BUILD_SITE =
'Canonical::Params.build'- FROM_HASH_SITE =
'Canonical::Params.from_hash'- NEW_SITE =
'Canonical::Params.new'
Instance Attribute Summary collapse
-
#frequency_penalty ⇒ Object
readonly
Returns the value of attribute frequency_penalty.
-
#max_tokens ⇒ Object
readonly
Returns the value of attribute max_tokens.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#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
-
.build(max_tokens: nil, temperature: nil, top_p: nil, top_k: nil, stop_sequences: nil, seed: nil, frequency_penalty: nil, presence_penalty: nil, response_format: nil, metadata: {}) ⇒ Object
rubocop:disable Metrics/ParameterLists -- factory methods have many params Build from keyword args (primary constructor).
-
.from_hash(source) ⇒ Object
Build from a Hash (raw client request or deserialized wire payload).
Instance Method Summary collapse
-
#as_json ⇒ Object
MultiJson/Oj/::JSON callback — prevents Data.define #inspect leak into JSON.
-
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
- #to_json ⇒ Object
Instance Attribute Details
#frequency_penalty ⇒ Object (readonly)
Returns the value of attribute frequency_penalty
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def frequency_penalty @frequency_penalty end |
#max_tokens ⇒ Object (readonly)
Returns the value of attribute max_tokens
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def max_tokens @max_tokens end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def @metadata end |
#presence_penalty ⇒ Object (readonly)
Returns the value of attribute presence_penalty
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def presence_penalty @presence_penalty end |
#response_format ⇒ Object (readonly)
Returns the value of attribute response_format
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def response_format @response_format end |
#seed ⇒ Object (readonly)
Returns the value of attribute seed
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def seed @seed end |
#stop_sequences ⇒ Object (readonly)
Returns the value of attribute stop_sequences
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def stop_sequences @stop_sequences end |
#temperature ⇒ Object (readonly)
Returns the value of attribute temperature
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def temperature @temperature end |
#top_k ⇒ Object (readonly)
Returns the value of attribute top_k
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def top_k @top_k end |
#top_p ⇒ Object (readonly)
Returns the value of attribute top_p
13 14 15 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 13 def top_p @top_p end |
Class Method Details
.build(max_tokens: nil, temperature: nil, top_p: nil, top_k: nil, stop_sequences: nil, seed: nil, frequency_penalty: nil, presence_penalty: nil, response_format: nil, metadata: {}) ⇒ Object
rubocop:disable Metrics/ParameterLists -- factory methods have many params Build from keyword args (primary constructor).
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 20 def self.build( max_tokens: nil, temperature: nil, top_p: nil, top_k: nil, stop_sequences: nil, seed: nil, frequency_penalty: nil, presence_penalty: nil, response_format: nil, metadata: {} ) new( max_tokens:, temperature:, top_p:, top_k:, stop_sequences:, seed:, frequency_penalty:, presence_penalty:, response_format:, metadata: Strict.(, self::BUILD_SITE) ) end |
.from_hash(source) ⇒ Object
Build from a Hash (raw client request or deserialized wire payload). Canonical member keys only; unknown keys fold into metadata (04 L5). from_hash({}) is a valid all-nil Params (the no-params object), never nil.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 36 def self.from_hash(source) Strict.require_hash!(source, self::FROM_HASH_SITE) hash = Strict.symbolize_keys(source) = Strict.fold_unknowns!(self, self::FROM_HASH_SITE, hash) build( max_tokens: hash[:max_tokens], temperature: hash[:temperature], top_p: hash[:top_p], top_k: hash[:top_k], stop_sequences: hash[:stop_sequences], seed: hash[:seed], frequency_penalty: hash[:frequency_penalty], presence_penalty: hash[:presence_penalty], response_format: hash[:response_format], metadata: ) end |
Instance Method Details
#as_json ⇒ Object
MultiJson/Oj/::JSON callback — prevents Data.define #inspect leak into JSON.
60 61 62 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 60 def as_json(*) to_h end |
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
55 56 57 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 55 def to_h super.compact end |
#to_json ⇒ Object
64 65 66 |
# File 'lib/legion/extensions/llm/canonical/params.rb', line 64 def to_json(*) to_h.to_json(*) end |