Class: Ask::ModelInfo

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ask/models.rb', line 47

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

#capabilitiesArray<String> (readonly)

Returns capability strings.

Returns:

  • (Array<String>)

    capability strings



24
25
26
# File 'lib/ask/models.rb', line 24

def capabilities
  @capabilities
end

#context_windowInteger? (readonly)

Returns maximum context window in tokens.

Returns:

  • (Integer, nil)

    maximum context window in tokens



27
28
29
# File 'lib/ask/models.rb', line 27

def context_window
  @context_window
end

#created_atString? (readonly)

Returns creation/publication date.

Returns:

  • (String, nil)

    creation/publication date



42
43
44
# File 'lib/ask/models.rb', line 42

def created_at
  @created_at
end

#familyString? (readonly)

Returns model family (e.g. “gpt”, “claude”).

Returns:

  • (String, nil)

    model family (e.g. “gpt”, “claude”)



21
22
23
# File 'lib/ask/models.rb', line 21

def family
  @family
end

#idString (readonly)

Returns model identifier (e.g. “gpt-4o”).

Returns:

  • (String)

    model identifier (e.g. “gpt-4o”)



12
13
14
# File 'lib/ask/models.rb', line 12

def id
  @id
end

#knowledge_cutoffDate? (readonly)

Returns knowledge cutoff date.

Returns:

  • (Date, nil)

    knowledge cutoff date



39
40
41
# File 'lib/ask/models.rb', line 39

def knowledge_cutoff
  @knowledge_cutoff
end

#max_output_tokensInteger? (readonly)

Returns maximum output tokens.

Returns:

  • (Integer, nil)

    maximum output tokens



30
31
32
# File 'lib/ask/models.rb', line 30

def max_output_tokens
  @max_output_tokens
end

#metadataHash (readonly)

Returns additional metadata.

Returns:

  • (Hash)

    additional metadata



45
46
47
# File 'lib/ask/models.rb', line 45

def 
  @metadata
end

#modalitiesHash (readonly)

Returns input/output modalities.

Returns:

  • (Hash)

    input/output modalities



33
34
35
# File 'lib/ask/models.rb', line 33

def modalities
  @modalities
end

#nameString (readonly)

Returns human-readable model name.

Returns:

  • (String)

    human-readable model name



15
16
17
# File 'lib/ask/models.rb', line 15

def name
  @name
end

#pricingHash (readonly)

Returns pricing information.

Returns:

  • (Hash)

    pricing information



36
37
38
# File 'lib/ask/models.rb', line 36

def pricing
  @pricing
end

#providerString (readonly)

Returns provider slug (e.g. “openai”).

Returns:

  • (String)

    provider slug (e.g. “openai”)



18
19
20
# File 'lib/ask/models.rb', line 18

def provider
  @provider
end

Instance Method Details

#audio?Boolean

Returns true if this model supports audio output.

Returns:

  • (Boolean)

    true if this model supports audio output



73
# File 'lib/ask/models.rb', line 73

def audio? = modalities.dig(:output)&.include?("audio")

#chat?Boolean

Returns true if this is a chat model.

Returns:

  • (Boolean)

    true if this is a chat model



67
# File 'lib/ask/models.rb', line 67

def chat? = type == "chat"

#embedding?Boolean

Returns true if this is an embedding model.

Returns:

  • (Boolean)

    true if this is an embedding model



70
# File 'lib/ask/models.rb', line 70

def embedding? = type == "embedding" || modalities.dig(:output)&.include?("embeddings")

#image?Boolean

Returns true if this model supports image output.

Returns:

  • (Boolean)

    true if this model supports image output



76
# File 'lib/ask/models.rb', line 76

def image? = modalities.dig(:output)&.include?("image")

#inspectString

Returns:

  • (String)


109
110
111
# File 'lib/ask/models.rb', line 109

def inspect
  "#<Ask::ModelInfo id=#{@id.inspect} provider=#{@provider.inspect}>"
end

#supports?(capability) ⇒ Boolean

Check if this model supports a given capability.

Parameters:

  • capability (String, Symbol)

    capability name

Returns:

  • (Boolean)


81
82
83
# File 'lib/ask/models.rb', line 81

def supports?(capability)
  capabilities.include?(capability.to_s)
end

#to_hHash

Returns serialized model info.

Returns:

  • (Hash)

    serialized model info



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ask/models.rb', line 91

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

#typeString

Returns model type (“chat”, “embedding”, “audio”, “image”).

Returns:

  • (String)

    model type (“chat”, “embedding”, “audio”, “image”)



86
87
88
# File 'lib/ask/models.rb', line 86

def type
  @metadata[:type] || infer_type
end