Class: Ollama::ModelProfile
- Inherits:
-
Object
- Object
- Ollama::ModelProfile
- 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. # => { 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
-
#family ⇒ Object
readonly
Returns the value of attribute family.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
Class Method Summary collapse
-
.for(model_name) ⇒ ModelProfile
Detect the capability profile for a model name.
Instance Method Summary collapse
- #context_window ⇒ Object
-
#default_options ⇒ Hash
Model-family-recommended inference options.
- #history_policy ⇒ Object
-
#initialize(model_name, family, capabilities) ⇒ ModelProfile
constructor
A new instance of ModelProfile.
- #inspect ⇒ Object
- #modality_order ⇒ Object
- #multimodal? ⇒ Boolean
- #stream_reasoning? ⇒ Boolean
- #structured_output? ⇒ Boolean
-
#supports_modality?(type) ⇒ Boolean
Whether the model supports a given input modality.
- #think_tag ⇒ Object
- #think_trigger ⇒ Object
- #thinking? ⇒ Boolean
- #to_h ⇒ Object
- #tool_calling? ⇒ Boolean
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
#family ⇒ Object (readonly)
Returns the value of attribute family.
95 96 97 |
# File 'lib/ollama/model_profile.rb', line 95 def family @family end |
#model_name ⇒ Object (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.
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_window ⇒ Object
126 |
# File 'lib/ollama/model_profile.rb', line 126 def context_window = @capabilities[:context_window] |
#default_options ⇒ Hash
Model-family-recommended inference options. Returns only keys that have values defined for this family.
138 139 140 141 142 143 144 |
# File 'lib/ollama/model_profile.rb', line 138 def { temperature: @capabilities[:default_temperature], top_p: @capabilities[:default_top_p], top_k: @capabilities[:default_top_k] }.compact end |
#history_policy ⇒ Object
123 |
# File 'lib/ollama/model_profile.rb', line 123 def history_policy = @capabilities[:history_policy] || :none |
#inspect ⇒ Object
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_order ⇒ Object
127 |
# File 'lib/ollama/model_profile.rb', line 127 def modality_order = @capabilities[:modality_order] || %i[text] |
#multimodal? ⇒ Boolean
118 |
# File 'lib/ollama/model_profile.rb', line 118 def multimodal? = (@capabilities[:multimodal]&.length.to_i > 1) |
#stream_reasoning? ⇒ Boolean
120 |
# File 'lib/ollama/model_profile.rb', line 120 def stream_reasoning? = !!@capabilities[:stream_reasoning] |
#structured_output? ⇒ 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.
131 132 133 |
# File 'lib/ollama/model_profile.rb', line 131 def supports_modality?(type) (@capabilities[:multimodal] || []).include?(type.to_sym) end |
#think_tag ⇒ Object
125 |
# File 'lib/ollama/model_profile.rb', line 125 def think_tag = @capabilities[:think_tag] |
#think_trigger ⇒ Object
124 |
# File 'lib/ollama/model_profile.rb', line 124 def think_trigger = @capabilities[:think_trigger] |
#thinking? ⇒ Boolean
117 |
# File 'lib/ollama/model_profile.rb', line 117 def thinking? = !!@capabilities[:thinking] |
#to_h ⇒ Object
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
119 |
# File 'lib/ollama/model_profile.rb', line 119 def tool_calling? = !!@capabilities[:tool_calling] |