Class: Ollama::ModelProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama/model_profile.rb

Overview

Maps model name patterns to a capability profile. The profile drives prompt adaptation, streaming event routing, history sanitization policy, and model-aware option defaults.

Usage:

profile = Ollama::ModelProfile.for("gemma4:31b-cloud")
profile.thinking?           # => true
profile.history_policy      # => :exclude_thoughts
profile.default_options     # => { temperature: 1.0, top_p: 0.95, top_k: 64 }

Constant Summary collapse

FAMILIES =
{
  gemma4: {
    pattern: /\bgemma[_-]?4\b/i,
    thinking: true,
    multimodal: %i[text image],
    audio: false,
    tool_calling: true,
    structured_output: true,
    stream_reasoning: true,
    keep_reasoning_separate: true,
    history_policy: :exclude_thoughts,
    think_trigger: :system_prompt_tag,
    think_tag: "<|think|>",
    default_temperature: 1.0,
    default_top_p: 0.95,
    default_top_k: 64,
    context_window: 128_000,
    modality_order: %i[image audio text]
  },
  deepseek: {
    pattern: /\bdeepseek\b/i,
    thinking: true,
    multimodal: %i[text],
    audio: false,
    tool_calling: false,
    structured_output: true,
    stream_reasoning: true,
    keep_reasoning_separate: true,
    history_policy: :exclude_thoughts,
    think_trigger: :flag,
    default_temperature: 0.6,
    default_top_p: 0.95,
    context_window: 64_000,
    modality_order: %i[text]
  },
  qwen: {
    pattern: /\bqwen\d*/i,
    thinking: true,
    multimodal: %i[text image],
    audio: false,
    tool_calling: true,
    structured_output: true,
    stream_reasoning: true,
    keep_reasoning_separate: true,
    history_policy: :exclude_thoughts,
    think_trigger: :flag,
    default_temperature: 0.7,
    default_top_p: 0.95,
    context_window: 128_000,
    modality_order: %i[image text]
  },
  embedding: {
    pattern: /\b(?:nomic-embed|mxbai-embed|bge-|embed-|minilm)\b/i,
    thinking: false,
    multimodal: %i[text],
    audio: false,
    tool_calling: false,
    structured_output: false,
    stream_reasoning: false,
    keep_reasoning_separate: false,
    history_policy: :none,
    context_window: 8_192,
    modality_order: %i[text]
  }
}.freeze
GENERIC_PROFILE =
{
  thinking: false,
  multimodal: %i[text],
  audio: false,
  tool_calling: true,
  structured_output: true,
  stream_reasoning: false,
  keep_reasoning_separate: false,
  history_policy: :none,
  context_window: 8_192,
  default_temperature: 0.2,
  default_top_p: 0.9,
  modality_order: %i[text]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name, family, capabilities) ⇒ ModelProfile

Returns a new instance of ModelProfile.



97
98
99
100
101
# File 'lib/ollama/model_profile.rb', line 97

def initialize(model_name, family, capabilities)
  @model_name = model_name.to_s
  @family = family
  @capabilities = capabilities.freeze
end

Instance Attribute Details

#familyObject (readonly)

Returns the value of attribute family.



95
96
97
# File 'lib/ollama/model_profile.rb', line 95

def family
  @family
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



95
96
97
# File 'lib/ollama/model_profile.rb', line 95

def model_name
  @model_name
end

Class Method Details

.for(model_name) ⇒ ModelProfile

Detect the capability profile for a model name.

Parameters:

  • model_name (String)

Returns:



106
107
108
109
110
111
112
113
114
115
# File 'lib/ollama/model_profile.rb', line 106

def self.for(model_name)
  name = model_name.to_s
  FAMILIES.each do |family, profile|
    next unless profile[:pattern]&.match?(name)

    caps = profile.except(:pattern)
    return new(name, family, caps)
  end
  new(name, :generic, GENERIC_PROFILE)
end

Instance Method Details

#context_windowObject



126
# File 'lib/ollama/model_profile.rb', line 126

def context_window  = @capabilities[:context_window]

#default_optionsHash

Model-family-recommended inference options. Returns only keys that have values defined for this family.

Returns:

  • (Hash)


138
139
140
141
142
143
144
# File 'lib/ollama/model_profile.rb', line 138

def default_options
  {
    temperature: @capabilities[:default_temperature],
    top_p: @capabilities[:default_top_p],
    top_k: @capabilities[:default_top_k]
  }.compact
end

#history_policyObject



123
# File 'lib/ollama/model_profile.rb', line 123

def history_policy  = @capabilities[:history_policy] || :none

#inspectObject



150
151
152
153
# File 'lib/ollama/model_profile.rb', line 150

def inspect
  "#<#{self.class.name} model=#{@model_name.inspect} family=#{@family} " \
    "thinking=#{thinking?} multimodal=#{multimodal?} tool_calling=#{tool_calling?}>"
end

#modality_orderObject



127
# File 'lib/ollama/model_profile.rb', line 127

def modality_order  = @capabilities[:modality_order] || %i[text]

#multimodal?Boolean

Returns:

  • (Boolean)


118
# File 'lib/ollama/model_profile.rb', line 118

def multimodal?       = (@capabilities[:multimodal]&.length.to_i > 1)

#stream_reasoning?Boolean

Returns:

  • (Boolean)


120
# File 'lib/ollama/model_profile.rb', line 120

def stream_reasoning? = !!@capabilities[:stream_reasoning]

#structured_output?Boolean

Returns:

  • (Boolean)


121
# File 'lib/ollama/model_profile.rb', line 121

def structured_output? = !!@capabilities[:structured_output]

#supports_modality?(type) ⇒ Boolean

Whether the model supports a given input modality.

Parameters:

  • type (Symbol)

    :text, :image, or :audio

Returns:

  • (Boolean)


131
132
133
# File 'lib/ollama/model_profile.rb', line 131

def supports_modality?(type)
  (@capabilities[:multimodal] || []).include?(type.to_sym)
end

#think_tagObject



125
# File 'lib/ollama/model_profile.rb', line 125

def think_tag       = @capabilities[:think_tag]

#think_triggerObject



124
# File 'lib/ollama/model_profile.rb', line 124

def think_trigger   = @capabilities[:think_trigger]

#thinking?Boolean

Returns:

  • (Boolean)


117
# File 'lib/ollama/model_profile.rb', line 117

def thinking?         = !!@capabilities[:thinking]

#to_hObject



146
147
148
# File 'lib/ollama/model_profile.rb', line 146

def to_h
  @capabilities.merge(model: @model_name, family: @family)
end

#tool_calling?Boolean

Returns:

  • (Boolean)


119
# File 'lib/ollama/model_profile.rb', line 119

def tool_calling?     = !!@capabilities[:tool_calling]