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.



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

#capabilitiesArray<String> (readonly)

Returns capability strings.

Returns:

  • (Array<String>)

    capability strings



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

def capabilities
  @capabilities
end

#context_windowInteger? (readonly)

Returns maximum context window in tokens.

Returns:

  • (Integer, nil)

    maximum context window in tokens



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

def context_window
  @context_window
end

#created_atString? (readonly)

Returns creation/publication date.

Returns:

  • (String, nil)

    creation/publication date



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

def created_at
  @created_at
end

#familyString? (readonly)

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

Returns:

  • (String, nil)

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



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

def family
  @family
end

#idString (readonly)

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

Returns:

  • (String)

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



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

def id
  @id
end

#knowledge_cutoffDate? (readonly)

Returns knowledge cutoff date.

Returns:

  • (Date, nil)

    knowledge cutoff date



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

def knowledge_cutoff
  @knowledge_cutoff
end

#max_output_tokensInteger? (readonly)

Returns maximum output tokens.

Returns:

  • (Integer, nil)

    maximum output tokens



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

def max_output_tokens
  @max_output_tokens
end

#metadataHash (readonly)

Returns additional metadata.

Returns:

  • (Hash)

    additional metadata



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

def 
  @metadata
end

#modalitiesHash (readonly)

Returns input/output modalities.

Returns:

  • (Hash)

    input/output modalities



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

def modalities
  @modalities
end

#nameString (readonly)

Returns human-readable model name.

Returns:

  • (String)

    human-readable model name



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

def name
  @name
end

#pricingHash (readonly)

Returns pricing information.

Returns:

  • (Hash)

    pricing information



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

def pricing
  @pricing
end

#providerString (readonly)

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

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true if this is an embedding model



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

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



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

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

#inspectString

Returns:

  • (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.

Parameters:

  • capability (String, Symbol)

    capability name

Returns:

  • (Boolean)


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

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

#to_hHash

Returns serialized model info.

Returns:

  • (Hash)

    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

#typeString

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

Returns:

  • (String)

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



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

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