Class: Ollama::PromptAdapters::Gemma4
- Defined in:
- lib/ollama/prompt_adapters/gemma4.rb
Overview
Gemma 4 prompt adapter.
Gemma 4 activates thinking by prepending <|think|> to the system prompt content rather than via a think: true API flag. This adapter injects that tag automatically when think: true is requested.
Multimodal ordering: image/audio parts are expected before text, which is handled by MultimodalInput before messages are built.
Constant Summary collapse
- THINK_TAG =
"<|think|>"
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#adapt_messages(messages, think: false) ⇒ Object
Inject <|think|> into the system message when think is enabled.
-
#inject_think_flag? ⇒ Boolean
Gemma 4 uses the system-prompt tag — do NOT send think: true to API.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Ollama::PromptAdapters::Base
Instance Method Details
#adapt_messages(messages, think: false) ⇒ Object
Inject <|think|> into the system message when think is enabled. If there is no system message, a bare system message is prepended.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ollama/prompt_adapters/gemma4.rb', line 18 def (, think: false) return unless think idx = .index { |m| role_of(m) == "system" } if idx msg = [idx] content = content_of(msg) return if content.start_with?(THINK_TAG) updated = msg.dup set_content(updated, "#{THINK_TAG}#{content}") = .dup [idx] = updated else system_msg = { role: "system", content: THINK_TAG } = [system_msg] + end end |
#inject_think_flag? ⇒ Boolean
Gemma 4 uses the system-prompt tag — do NOT send think: true to API.
40 41 42 |
# File 'lib/ollama/prompt_adapters/gemma4.rb', line 40 def inject_think_flag? false end |