Class: Smith::Agent::ModelReference
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Smith::Agent::ModelReference
- Defined in:
- lib/smith/agent/model_reference.rb
Class Method Summary collapse
- .coerce(value, provider: nil) ⇒ Object
-
.parse(value) ⇒ Object
Inverse of #to_s: the first slash separates provider from model, so a reference whose model id itself contains slashes round-trips ("openrouter/openai/gpt-5" -> provider :openrouter, model "openai/gpt-5").
Instance Method Summary collapse
- #chat_options ⇒ Object
-
#initialize(attributes) ⇒ ModelReference
constructor
A new instance of ModelReference.
- #key ⇒ Object
-
#same_candidate?(other) ⇒ Boolean
True when the two references can address the same physical model: an unqualified reference delegates provider selection to RubyLLM, so it can resolve to any provider serving the same model id.
- #to_s ⇒ Object
Constructor Details
#initialize(attributes) ⇒ ModelReference
Returns a new instance of ModelReference.
24 25 26 27 |
# File 'lib/smith/agent/model_reference.rb', line 24 def initialize(attributes) super freeze end |
Class Method Details
.coerce(value, provider: nil) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/smith/agent/model_reference.rb', line 29 def self.coerce(value, provider: nil) return value if value.is_a?(self) return from_hash(value) if value.is_a?(Hash) return parse(value) if provider.nil? && value.is_a?(String) && value.include?("/") new(model_id: value, provider:) end |
.parse(value) ⇒ Object
Inverse of #to_s: the first slash separates provider from model,
so a reference whose model id itself contains slashes round-trips
("openrouter/openai/gpt-5" -> provider :openrouter,
model "openai/gpt-5"). An explicit provider: keyword keeps the
string literal and is never re-split.
48 49 50 51 52 53 |
# File 'lib/smith/agent/model_reference.rb', line 48 def self.parse(value) provider, model_id = value.split("/", 2) raise ArgumentError, "provider segment in #{value.inspect} must not be blank" if provider.empty? new(model_id:, provider:) end |
Instance Method Details
#chat_options ⇒ Object
67 68 69 |
# File 'lib/smith/agent/model_reference.rb', line 67 def { model: model_id, provider: }.compact.freeze end |
#key ⇒ Object
55 56 57 |
# File 'lib/smith/agent/model_reference.rb', line 55 def key [provider, model_id].freeze end |
#same_candidate?(other) ⇒ Boolean
True when the two references can address the same physical model: an unqualified reference delegates provider selection to RubyLLM, so it can resolve to any provider serving the same model id.
62 63 64 65 |
# File 'lib/smith/agent/model_reference.rb', line 62 def same_candidate?(other) model_id == other.model_id && (provider.nil? || other.provider.nil? || provider == other.provider) end |
#to_s ⇒ Object
71 72 73 |
# File 'lib/smith/agent/model_reference.rb', line 71 def to_s provider ? "#{provider}/#{model_id}" : model_id end |