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, PerformCallbacks Classes: CombinedSwitch, DatabaseSwitch, Switch

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#embeddingObject (readonly)

Returns the value of attribute embedding.



256
257
258
# File 'lib/ollama_chat/switches.rb', line 256

def embedding
  @embedding
end

#embedding_enabledObject (readonly)

Returns the value of attribute embedding_enabled.



260
261
262
# File 'lib/ollama_chat/switches.rb', line 260

def embedding_enabled
  @embedding_enabled
end

#embedding_pausedObject (readonly)

Returns the value of attribute embedding_paused.



264
265
266
# File 'lib/ollama_chat/switches.rb', line 264

def embedding_paused
  @embedding_paused
end

#locationObject (readonly)

Returns the value of attribute location.



268
269
270
# File 'lib/ollama_chat/switches.rb', line 268

def location
  @location
end

#markdownObject (readonly)

Returns the value of attribute markdown.



233
234
235
# File 'lib/ollama_chat/switches.rb', line 233

def markdown
  @markdown
end

#runtime_infoObject (readonly)

Controls the visibility of runtime information in the chat.



274
275
276
# File 'lib/ollama_chat/switches.rb', line 274

def runtime_info
  @runtime_info
end

#streamObject (readonly)

Returns the value of attribute stream.



229
230
231
# File 'lib/ollama_chat/switches.rb', line 229

def stream
  @stream
end

#think_loudObject (readonly)

Returns the value of attribute think_loud.



237
238
239
# File 'lib/ollama_chat/switches.rb', line 237

def think_loud
  @think_loud
end

#think_stripObject (readonly)

Determines whether the ‘thinking` content is stripped from the message payload before it is sent to the Ollama API.

Enabling this (‘true`) optimizes payload size and prevents the model from being confused by its own internal reasoning traces from previous turns. Disabling this (`false`) preserves the model’s “chain of thought” history.



248
249
250
# File 'lib/ollama_chat/switches.rb', line 248

def think_strip
  @think_strip
end

#tools_supportObject (readonly)

Controls tool support (off → skip all, on → honour per‑tool state).



280
281
282
# File 'lib/ollama_chat/switches.rb', line 280

def tools_support
  @tools_support
end

#voiceObject (readonly)

Returns the value of attribute voice.



252
253
254
# File 'lib/ollama_chat/switches.rb', line 252

def voice
  @voice
end

Instance Method Details

#setup_switchesObject

Initializes the various switches for configuring the application’s behavior.

This method creates and configures the database and local switch objects that control streaming, thinking, markdown output, voice output, embedding, and location settings.



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/ollama_chat/switches.rb', line 287

def setup_switches
  @stream = DatabaseSwitch.new(
    chat: self,
    attribute: :stream_enabled,
    msg: {
      true  => "Streaming enabled.",
      false => "Streaming disabled.",
    }
  )

  @think_loud = DatabaseSwitch.new(
    chat: self,
    attribute: :think_loud_enabled,
    msg: {
      true  => "Thinking out loud, show thinking annotations.",
      false => "Thinking silently, don't show thinking annotations.",
    }
  )

  @think_strip = DatabaseSwitch.new(
    chat: self,
    attribute: :think_strip_enabled,
    msg: {
      true  => "Stripping thinking content is enabled.",
      false => "Stripping thinking content is disabled.",
    }
  )

  @markdown = DatabaseSwitch.new(
    chat: self,
    attribute: :markdown_enabled,
    msg: {
      true  => "Using #{italic{'ANSI'}} markdown to output content.",
      false => "Using plaintext for outputting content.",
    }
  )

  @voice = DatabaseSwitch.new(
    chat: self,
    attribute: :voice_enabled,
    msg: {
      true  => "Voice output enabled.",
      false => "Voice output disabled.",
    }
  )

  @embedding_enabled = DatabaseSwitch.new(
    chat: self,
    attribute: :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 = DatabaseSwitch.new(
    chat: self,
    attribute: :location_enabled,
    msg: {
      true  => "Location enabled.",
      false => "Location disabled.",
    }
  )

  reset_system_prompt = -> * {
    messages.set_system_prompt(messages.system_name)
  }

  @runtime_info = DatabaseSwitch.new(
    chat: self,
    attribute: :runtime_info_enabled,
    msg: {
      true  => "Runtime Information enabled.",
      false => "Runtime Information disabled.",
    },
    callbacks: {
      [ false, true ] => reset_system_prompt,
      [ true, false ] => reset_system_prompt,
    }
  )

  @tools_support = DatabaseSwitch.new(
    chat:      self,
    attribute: :tools_enabled,
    msg: {
      true  => "Tools support enabled.",
      false => "Tools support disabled.",
    }
  )
end