Module: OllamaChat::ThinkControl

Included in:
Chat
Defined in:
lib/ollama_chat/think_control.rb

Overview

A module that provides thinking control functionality for OllamaChat.

The ThinkControl module encapsulates methods for managing the 'think' mode setting in OllamaChat sessions. It handles the selection of different thinking modes, checking the current state, and displaying the current think mode status.

Instance Method Summary collapse

Instance Method Details

#normalize_think_state(state) ⇒ String

Normalizes a raw thinking value from the Ollama show response into a canonical state string, since different models report thinking.values and thinking.default either as booleans ([false, true], hybrid models) or as strings (["low", "high", "max"]).

Parameters:

  • state (Boolean, String, nil) —

    the raw value as reported by Ollama

Returns:

  • (String) —

    the canonical state ('enabled', 'disabled', or the value coerced to a string)



47
48
49
50
51
52
53
# File 'lib/ollama_chat/think_control.rb', line 47

def normalize_think_state(state)
  case state
  when true       then 'enabled'
  when false, nil then 'disabled'
  else                 state.to_s
  end
end

#think ⇒ String

The think method returns the current think mode selection.

Returns:

  • (String) —

    the selected think mode value



58
59
60
61
62
63
64
65
66
# File 'lib/ollama_chat/think_control.rb', line 58

def think
  if think_mode.off?
    false
  elsif think_mode.selected == 'enabled'
    true
  else
    think_mode.selected
  end
end

#think? ⇒ TrueClass, FalseClass

The think? method checks if the think mode is enabled.

Returns:

  • (TrueClass, FalseClass) —

    true if think mode is enabled, false otherwise



71
72
73
# File 'lib/ollama_chat/think_control.rb', line 71

def think?
  think_mode.on?
end

#think_loud? ⇒ TrueClass, FalseClass

The think_loud? method checks if both think mode and think loud mode are enabled.

Returns:

  • (TrueClass, FalseClass) —

    true if think mode is enabled and think loud mode is on, false otherwise



80
81
82
# File 'lib/ollama_chat/think_control.rb', line 80

def think_loud?
  think? && think_loud.on?
end

#think_mode_states ⇒ Array<String>

The think_mode_states method returns the valid think mode states for the chat's current model, with disabled always included.

This is the single seam where per-model awareness enters: the lazy states: lambda of the think_mode selector resolves through this method, so the offered states can track the active model's capabilities without the selector itself being rebuilt.

The supported states may be:

  • disabled: The thinking process is inactive.
  • enabled: The thinking process is active with default settings.
  • low: A minimal or subtle thinking intensity.
  • medium: A balanced approach to thinking and reasoning.
  • high: An intensive, detailed, or highly verbose thinking mode.
  • max: The maximum thinking intensity, where supported by the model. Some models treat high and max as equivalent (e.g., Qwen3.8 maps both to its xhigh reasoning effort).

Not every model supports every level; the concrete set returned may be a subset of the above depending on the model.

Returns:

  • (Array<String>) —

    the frozen list of valid think mode states



31
32
33
34
35
36
37
# File 'lib/ollama_chat/think_control.rb', line 31

def think_mode_states
  states =  %w[ disabled ] + (
    @model_metadata&.thinking.full?(:values) ||
    %w[ enabled low medium high max ]
  )
  states.map { normalize_think_state(_1) }.uniq.freeze
end