Class: Ask::ModelInfo
- Inherits:
-
Object
- Object
- Ask::ModelInfo
- Defined in:
- lib/ask/models.rb
Overview
Model metadata: capabilities, pricing, context window, modalities. Immutable value object representing a single model entry.
Instance Attribute Summary collapse
-
#capabilities ⇒ Array<String>
readonly
Capability strings.
-
#context_window ⇒ Integer?
readonly
Maximum context window in tokens.
-
#created_at ⇒ String?
readonly
Creation/publication date.
-
#family ⇒ String?
readonly
Model family (e.g. “gpt”, “claude”).
-
#id ⇒ String
readonly
Model identifier (e.g. “gpt-4o”).
-
#knowledge_cutoff ⇒ Date?
readonly
Knowledge cutoff date.
-
#max_output_tokens ⇒ Integer?
readonly
Maximum output tokens.
-
#metadata ⇒ Hash
readonly
Additional metadata.
-
#modalities ⇒ Hash
readonly
Input/output modalities.
-
#name ⇒ String
readonly
Human-readable model name.
-
#pricing ⇒ Hash
readonly
Pricing information.
-
#provider ⇒ String
readonly
Provider slug (e.g. “openai”).
Instance Method Summary collapse
-
#audio? ⇒ Boolean
True if this model supports audio output.
-
#chat? ⇒ Boolean
True if this is a chat model.
-
#embedding? ⇒ Boolean
True if this is an embedding model.
-
#image? ⇒ Boolean
True if this model supports image output.
-
#initialize(id:, name: nil, provider:, family: nil, capabilities: [], context_window: nil, max_output_tokens: nil, modalities: {}, pricing: {}, knowledge_cutoff: nil, created_at: nil, metadata: {}) ⇒ ModelInfo
constructor
A new instance of ModelInfo.
- #inspect ⇒ String
-
#supports?(capability) ⇒ Boolean
Check if this model supports a given capability.
-
#to_h ⇒ Hash
Serialized model info.
-
#type ⇒ String
Model type (“chat”, “embedding”, “audio”, “image”).
Constructor Details
#initialize(id:, name: nil, provider:, family: nil, capabilities: [], context_window: nil, max_output_tokens: nil, modalities: {}, pricing: {}, knowledge_cutoff: nil, created_at: nil, metadata: {}) ⇒ ModelInfo
Returns a new instance of ModelInfo.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ask/models.rb', line 48 def initialize(id:, name: nil, provider:, family: nil, capabilities: [], context_window: nil, max_output_tokens: nil, modalities: {}, pricing: {}, knowledge_cutoff: nil, created_at: nil, metadata: {}) @id = id @name = name || id @provider = provider.to_s @family = family @capabilities = Array(capabilities).map(&:to_s) @context_window = context_window @max_output_tokens = max_output_tokens @modalities = modalities @pricing = pricing @knowledge_cutoff = knowledge_cutoff @created_at = created_at @metadata = freeze end |
Instance Attribute Details
#capabilities ⇒ Array<String> (readonly)
Returns capability strings.
25 26 27 |
# File 'lib/ask/models.rb', line 25 def capabilities @capabilities end |
#context_window ⇒ Integer? (readonly)
Returns maximum context window in tokens.
28 29 30 |
# File 'lib/ask/models.rb', line 28 def context_window @context_window end |
#created_at ⇒ String? (readonly)
Returns creation/publication date.
43 44 45 |
# File 'lib/ask/models.rb', line 43 def created_at @created_at end |
#family ⇒ String? (readonly)
Returns model family (e.g. “gpt”, “claude”).
22 23 24 |
# File 'lib/ask/models.rb', line 22 def family @family end |
#id ⇒ String (readonly)
Returns model identifier (e.g. “gpt-4o”).
13 14 15 |
# File 'lib/ask/models.rb', line 13 def id @id end |
#knowledge_cutoff ⇒ Date? (readonly)
Returns knowledge cutoff date.
40 41 42 |
# File 'lib/ask/models.rb', line 40 def knowledge_cutoff @knowledge_cutoff end |
#max_output_tokens ⇒ Integer? (readonly)
Returns maximum output tokens.
31 32 33 |
# File 'lib/ask/models.rb', line 31 def max_output_tokens @max_output_tokens end |
#metadata ⇒ Hash (readonly)
Returns additional metadata.
46 47 48 |
# File 'lib/ask/models.rb', line 46 def @metadata end |
#modalities ⇒ Hash (readonly)
Returns input/output modalities.
34 35 36 |
# File 'lib/ask/models.rb', line 34 def modalities @modalities end |
#name ⇒ String (readonly)
Returns human-readable model name.
16 17 18 |
# File 'lib/ask/models.rb', line 16 def name @name end |
#pricing ⇒ Hash (readonly)
Returns pricing information.
37 38 39 |
# File 'lib/ask/models.rb', line 37 def pricing @pricing end |
#provider ⇒ String (readonly)
Returns provider slug (e.g. “openai”).
19 20 21 |
# File 'lib/ask/models.rb', line 19 def provider @provider end |
Instance Method Details
#audio? ⇒ Boolean
Returns true if this model supports audio output.
74 |
# File 'lib/ask/models.rb', line 74 def audio? = modalities.dig(:output)&.include?("audio") |
#chat? ⇒ Boolean
Returns true if this is a chat model.
68 |
# File 'lib/ask/models.rb', line 68 def chat? = type == "chat" |
#embedding? ⇒ Boolean
Returns true if this is an embedding model.
71 |
# File 'lib/ask/models.rb', line 71 def = type == "embedding" || modalities.dig(:output)&.include?("embeddings") |
#image? ⇒ Boolean
Returns true if this model supports image output.
77 |
# File 'lib/ask/models.rb', line 77 def image? = modalities.dig(:output)&.include?("image") |
#inspect ⇒ String
110 111 112 |
# File 'lib/ask/models.rb', line 110 def inspect "#<Ask::ModelInfo id=#{@id.inspect} provider=#{@provider.inspect}>" end |
#supports?(capability) ⇒ Boolean
Check if this model supports a given capability.
82 83 84 |
# File 'lib/ask/models.rb', line 82 def supports?(capability) capabilities.include?(capability.to_s) end |
#to_h ⇒ Hash
Returns serialized model info.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ask/models.rb', line 92 def to_h { id: @id, name: @name, provider: @provider, family: @family, capabilities: @capabilities, context_window: @context_window, max_output_tokens: @max_output_tokens, modalities: @modalities, pricing: @pricing, knowledge_cutoff: @knowledge_cutoff, created_at: @created_at, metadata: @metadata }.compact end |
#type ⇒ String
Returns model type (“chat”, “embedding”, “audio”, “image”).
87 88 89 |
# File 'lib/ask/models.rb', line 87 def type @metadata[:type] || infer_type end |