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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#thinktrue, ... (readonly)

The think method returns the current state of the think mode.

Returns:

  • (true, false, String)

    the think mode



11
12
13
# File 'lib/ollama_chat/think_control.rb', line 11

def think
  @think
end

Instance Method Details

#choose_think_modeObject

The choose_think_mode method presents a menu to select a think mode.

This method displays available think modes to the user and sets the selected mode as the current think mode for the chat session.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ollama_chat/think_control.rb', line 17

def choose_think_mode
  think_modes = %w[ off on low medium high [EXIT] ]
  case chosen = OllamaChat::Utils::Chooser.choose(think_modes)
  when '[EXIT]', nil
    STDOUT.puts "Exiting chooser."
  when 'off'
    @think = false
  when 'on'
    @think = true
  when 'low', 'medium', 'high'
    @think = chosen
  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



35
36
37
# File 'lib/ollama_chat/think_control.rb', line 35

def think?
  !!think
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



61
62
63
# File 'lib/ollama_chat/think_control.rb', line 61

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

#think_modeString

The think_mode method returns the current think mode status as a string.

Returns:

  • (String)

    returns ‘enabled’ if think mode is true, the think mode value if it’s a string, or ‘disabled’ if think mode is false or nil



43
44
45
# File 'lib/ollama_chat/think_control.rb', line 43

def think_mode
  think == true ? 'enabled' : think || 'disabled'
end

#think_showObject

The think_show method displays the current think mode status.

This method checks the current think mode setting and outputs a message indicating whether think mode is enabled, disabled, or set to a specific mode level (low, medium, high).



52
53
54
# File 'lib/ollama_chat/think_control.rb', line 52

def think_show
  STDOUT.puts "Think mode is #{bold(think_mode)}."
end