Module: OllamaChat::Switches

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

Overview

A module that provides switch functionality for configuring application behavior.

The Switches module encapsulates various toggle switches used throughout the OllamaChat application to control different features and settings such as streaming, thinking, markdown output, voice output, embedding, and location information. These switches allow users to dynamically enable or disable specific functionalities during a chat session.

Examples:

Toggling a switch on/off

switch = OllamaChat::Switches::Switch.new(value: false, msg: { true => 'Enabled', false => 'Disabled' })
switch.toggle  # Turns the switch on
switch.toggle  # Turns the switch off

Defined Under Namespace

Modules: CheckSwitch Classes: CombinedSwitch, Switch

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#embeddingOllamaChat::Switches::CombinedSwitch (readonly)

The embedding attribute reader returns the embedding switch object.

instance

Returns:



160
161
162
# File 'lib/ollama_chat/switches.rb', line 160

def embedding
  @embedding
end

#embedding_enabledOllamaChat::Switches::Switch (readonly)

The embedding_enabled reader returns the embedding enabled switch instance.

instance

Returns:



166
167
168
# File 'lib/ollama_chat/switches.rb', line 166

def embedding_enabled
  @embedding_enabled
end

#embedding_pausedOllamaChat::Switches::Switch (readonly)

The embedding_paused method returns the current state of the embedding pause flag.

Returns:



171
172
173
# File 'lib/ollama_chat/switches.rb', line 171

def embedding_paused
  @embedding_paused
end

#locationOllamaChat::Switches::Switch (readonly)

The location method returns the current location setting.

Returns:



176
177
178
# File 'lib/ollama_chat/switches.rb', line 176

def location
  @location
end

#markdownOllamaChat::Switches::Switch (readonly)

The markdown attribute reader returns the markdown switch object. The voice reader returns the voice switch instance.

Returns:



149
150
151
# File 'lib/ollama_chat/switches.rb', line 149

def markdown
  @markdown
end

#streamOllamaChat::Switches::Switch (readonly)

The think method returns the current state of the stream switch.

Returns:



138
139
140
# File 'lib/ollama_chat/switches.rb', line 138

def stream
  @stream
end

#thinkOllamaChat::Switches::Switch (readonly)

The think method returns the current state of the thinking switch.

Returns:



143
144
145
# File 'lib/ollama_chat/switches.rb', line 143

def think
  @think
end

#voiceOllamaChat::Switches::Switch (readonly)

The voice reader returns the voice switch instance.

Returns:



154
155
156
# File 'lib/ollama_chat/switches.rb', line 154

def voice
  @voice
end

Instance Method Details

#setup_switches(config) ⇒ Object

The setup_switches method initializes various switches for configuring the application’s behavior.

This method creates and configures multiple switch objects that control different aspects of the application, such as streaming, thinking, markdown output, voice output, embedding, and location settings.

containing settings for the switches

Parameters:

  • config (ComplexConfig::Settings)

    the configuration object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/ollama_chat/switches.rb', line 187

def setup_switches(config)
  @stream = Switch.new(
    value: config.stream,
    msg: {
      true  => "Streaming enabled.",
      false => "Streaming disabled.",
    }
  )

  @think = Switch.new(
    value: config.think,
    msg: {
      true  => "Thinking enabled.",
      false => "Thinking disabled.",
    }
  )

  @markdown = Switch.new(
    value: config.markdown,
    msg: {
      true  => "Using #{italic{'ANSI'}} markdown to output content.",
      false => "Using plaintext for outputting content.",
    }
  )

  @voice = Switch.new(
    value: config.voice.enabled,
    msg: {
      true  => "Voice output enabled.",
      false => "Voice output disabled.",
    }
  )

  @embedding_enabled = Switch.new(
    value: config.embedding.enabled,
    msg: {
      true  => "Embedding enabled.",
      false => "Embedding disabled.",
    }
  )

  @embedding_paused = Switch.new(
    value: config.embedding.paused,
    msg: {
      true  => "Embedding paused.",
      false => "Embedding resumed.",
    }
  )

  @embedding = CombinedSwitch.new(
    value: -> { @embedding_enabled.on? && @embedding_paused.off? },
    msg: {
      true  => "Embedding is currently performed.",
      false => "Embedding is currently not performed.",
    }
  )

  @location = Switch.new(
    value: config.location.enabled,
    msg: {
      true  => "Location and localtime enabled.",
      false => "Location and localtime disabled.",
    }
  )
end