Class: Insika::ModelSelection
- Inherits:
-
Data
- Object
- Data
- Insika::ModelSelection
- Defined in:
- lib/insika/model_selection.rb
Overview
The RESOLVED model decision for a turn (ModelResolver output). Immutable snapshot carried on the TurnState, applied to the RubyLLM chat at stage 5 and surfaced in the turn's usage for telemetry/billing.
Fields:
model -> the resolved model id (String) | nil (RubyLLM's own default)
provider -> Symbol | nil (nil => RubyLLM infers from the model registry)
source -> :chat | :agent | :platform_default (WHERE the model came from)
pinned -> true when the model is a USER pin (per-chat override). A pin
"fails HIGH": no silent fallback (OpenClaw semantics). An agent
model / platform default is NOT pinned -> fallbacks apply.
params -> generation params (Hash of symbols: temperature/max_tokens/thinking)
fallbacks -> ordered [{ model:, provider: }] to try when NOT pinned. The
mid-turn ROTATION across this chain (plus the profile's own
reliability["fallback"] refs) is WS3's Reliability coordinator;
here the chain is resolved + surfaced (source/pinned) for it.
Constant Summary collapse
- THINKING_LEVELS =
The selectable reasoning values (4-layer). Blank/absent = inherit the broader layer; these are the explicit choices. Shared with the Studio forms. Defined on the class OUTSIDE the Data.define block on purpose: a constant assigned inside the block would land in the enclosing lexical scope (Insika), not on ModelSelection.
%w[off on low medium high].freeze
Instance Attribute Summary collapse
-
#fallbacks ⇒ Object
readonly
Returns the value of attribute fallbacks.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#pinned ⇒ Object
readonly
Returns the value of attribute pinned.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#apply_params(chat) ⇒ Object
Applies the generation params to a RubyLLM chat (or any object exposing the same
with_*fluent API). -
#assume_model_exists? ⇒ Boolean
provider present => tell RubyLLM to trust the id (skip the registry lookup), matching the pre-v2 create_chat behavior.
-
#initialize(model:, provider: nil, source: :platform_default, pinned: false, params: {}, fallbacks: []) ⇒ ModelSelection
constructor
A new instance of ModelSelection.
- #pinned? ⇒ Boolean
Constructor Details
#initialize(model:, provider: nil, source: :platform_default, pinned: false, params: {}, fallbacks: []) ⇒ ModelSelection
Returns a new instance of ModelSelection.
21 22 23 24 |
# File 'lib/insika/model_selection.rb', line 21 def initialize(model:, provider: nil, source: :platform_default, pinned: false, params: {}, fallbacks: []) super end |
Instance Attribute Details
#fallbacks ⇒ Object (readonly)
Returns the value of attribute fallbacks
20 21 22 |
# File 'lib/insika/model_selection.rb', line 20 def fallbacks @fallbacks end |
#model ⇒ Object (readonly)
Returns the value of attribute model
20 21 22 |
# File 'lib/insika/model_selection.rb', line 20 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params
20 21 22 |
# File 'lib/insika/model_selection.rb', line 20 def params @params end |
#pinned ⇒ Object (readonly)
Returns the value of attribute pinned
20 21 22 |
# File 'lib/insika/model_selection.rb', line 20 def pinned @pinned end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider
20 21 22 |
# File 'lib/insika/model_selection.rb', line 20 def provider @provider end |
#source ⇒ Object (readonly)
Returns the value of attribute source
20 21 22 |
# File 'lib/insika/model_selection.rb', line 20 def source @source end |
Instance Method Details
#apply_params(chat) ⇒ Object
Applies the generation params to a RubyLLM chat (or any object exposing the
same with_* fluent API). Pure and duck-typed: a with_* the target does
not expose is skipped (a fake chat in specs need only implement the ones it
asserts). RubyLLM raises on a nil arg, so only PRESENT params are applied.
Returns the chat (the with_* calls mutate and return self).
37 38 39 40 41 42 43 |
# File 'lib/insika/model_selection.rb', line 37 def apply_params(chat) p = params || {} apply(chat, :with_temperature, p[:temperature]) if numeric?(p[:temperature]) apply_payload_params(chat, p) apply_effort(chat, p[:thinking]) if present?(p[:thinking]) chat end |
#assume_model_exists? ⇒ Boolean
provider present => tell RubyLLM to trust the id (skip the registry lookup), matching the pre-v2 create_chat behavior.
30 |
# File 'lib/insika/model_selection.rb', line 30 def assume_model_exists? = !provider.nil? |
#pinned? ⇒ Boolean
26 |
# File 'lib/insika/model_selection.rb', line 26 def pinned? = pinned |