Class: Aireview::ModelCandidate
- Inherits:
-
Struct
- Object
- Struct
- Aireview::ModelCandidate
- Defined in:
- lib/aireview/model_candidate.rb
Overview
A model in a stage chain: provider, name, request size limit and, for a server of your own, its address. Compared by provider, name and address — the limit depends on the stage.
Instance Attribute Summary collapse
-
#api_base ⇒ Object
Returns the value of attribute api_base.
-
#max_prompt_chars ⇒ Object
Returns the value of attribute max_prompt_chars.
-
#model ⇒ Object
Returns the value of attribute model.
-
#provider ⇒ Object
Returns the value of attribute provider.
Class Method Summary collapse
-
.api_base(value, name) ⇒ Object
api_base of a model or a stage: an http(s) address or nothing.
-
.parse_item(item) ⇒ Object
A "provider/name" string or a bare name (the provider is separated by a slash because Ollama tags contain a colon), or a hash with model.
Instance Method Summary collapse
-
#key_source ⇒ Object
Models sharing keys: a provider's own API, or one server of your own.
-
#names ⇒ Object
Every way a start or a CLI override may name this model: bare, "provider/name", or the full name with the address.
- #same_model?(other) ⇒ Boolean
-
#to_s ⇒ Object
The address is part of the name, scheme included: two servers with the same model (http and https ones too) are two models for quarantine, reserves and the review key.
Instance Attribute Details
#api_base ⇒ Object
Returns the value of attribute api_base
13 14 15 |
# File 'lib/aireview/model_candidate.rb', line 13 def api_base @api_base end |
#max_prompt_chars ⇒ Object
Returns the value of attribute max_prompt_chars
13 14 15 |
# File 'lib/aireview/model_candidate.rb', line 13 def max_prompt_chars @max_prompt_chars end |
#model ⇒ Object
Returns the value of attribute model
13 14 15 |
# File 'lib/aireview/model_candidate.rb', line 13 def model @model end |
#provider ⇒ Object
Returns the value of attribute provider
13 14 15 |
# File 'lib/aireview/model_candidate.rb', line 13 def provider @provider end |
Class Method Details
.api_base(value, name) ⇒ Object
api_base of a model or a stage: an http(s) address or nothing.
39 40 41 42 43 44 |
# File 'lib/aireview/model_candidate.rb', line 39 def self.api_base(value, name) return nil if value.nil? || value.to_s.strip.empty? return value.to_s.strip if value.to_s.strip.match?(%r{\Ahttps?://\S+\z}) raise ConfigError, "#{name} must be an http(s) URL, got #{value.inspect}" end |
.parse_item(item) ⇒ Object
A "provider/name" string or a bare name (the provider is separated by a slash because Ollama tags contain a colon), or a hash with model.
48 49 50 51 52 53 54 55 |
# File 'lib/aireview/model_candidate.rb', line 48 def self.parse_item(item) return item unless item.is_a?(String) provider, model = item.split('/', 2) return {'provider' => provider, 'model' => model} if model && KNOWN_PROVIDERS.include?(provider) {'model' => item} end |
Instance Method Details
#key_source ⇒ Object
Models sharing keys: a provider's own API, or one server of your own.
34 35 36 |
# File 'lib/aireview/model_candidate.rb', line 34 def key_source api_base ? "#{provider}@#{api_base}" : provider.to_s end |
#names ⇒ Object
Every way a start or a CLI override may name this model: bare, "provider/name", or the full name with the address. One list for the config check and for picking the model, so they cannot disagree.
25 26 27 |
# File 'lib/aireview/model_candidate.rb', line 25 def names [model.to_s, "#{provider}/#{model}", to_s].uniq end |
#same_model?(other) ⇒ Boolean
29 30 31 |
# File 'lib/aireview/model_candidate.rb', line 29 def same_model?(other) to_s == other.to_s end |
#to_s ⇒ Object
The address is part of the name, scheme included: two servers with the same model (http and https ones too) are two models for quarantine, reserves and the review key.
17 18 19 20 |
# File 'lib/aireview/model_candidate.rb', line 17 def to_s name = "#{provider}/#{model}" api_base ? "#{name}@#{api_base.chomp('/')}" : name end |