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.
Defined Under Namespace
Modules: CheckSwitch, PerformCallbacks Classes: CombinedSwitch, DatabaseSwitch, Switch
Instance Attribute Summary collapse
-
#context_manifest ⇒ Object
readonly
Controls whether context files are generated in manifest mode (metadata only, no file content).
-
#embedding ⇒ Object
readonly
Returns the value of attribute embedding.
-
#embedding_enabled ⇒ Object
readonly
Returns the value of attribute embedding_enabled.
-
#embedding_paused ⇒ Object
readonly
Returns the value of attribute embedding_paused.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#markdown ⇒ Object
readonly
Returns the value of attribute markdown.
-
#memory_trigger ⇒ Object
readonly
Controls whether the session's memory trigger is active.
-
#runtime_info ⇒ Object
readonly
Controls the visibility of runtime information in the chat.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#think_loud ⇒ Object
readonly
Returns the value of attribute think_loud.
-
#think_strip ⇒ Object
readonly
Determines whether the
thinkingcontent is stripped from the message payload before it is sent to the Ollama API. -
#tools_support ⇒ Object
readonly
Controls tool support (off → skip all, on → honour per‑tool state).
-
#voice ⇒ Object
readonly
Returns the value of attribute voice.
Instance Method Summary collapse
-
#setup_switches ⇒ Object
Initializes the various switches for configuring the application's behavior.
Instance Attribute Details
#context_manifest ⇒ Object (readonly)
Controls whether context files are generated in manifest mode (metadata only, no file content).
343 344 345 |
# File 'lib/ollama_chat/switches.rb', line 343 def context_manifest @context_manifest end |
#embedding ⇒ Object (readonly)
Returns the value of attribute embedding.
304 305 306 |
# File 'lib/ollama_chat/switches.rb', line 304 def @embedding end |
#embedding_enabled ⇒ Object (readonly)
Returns the value of attribute embedding_enabled.
308 309 310 |
# File 'lib/ollama_chat/switches.rb', line 308 def @embedding_enabled end |
#embedding_paused ⇒ Object (readonly)
Returns the value of attribute embedding_paused.
312 313 314 |
# File 'lib/ollama_chat/switches.rb', line 312 def @embedding_paused end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
316 317 318 |
# File 'lib/ollama_chat/switches.rb', line 316 def location @location end |
#markdown ⇒ Object (readonly)
Returns the value of attribute markdown.
281 282 283 |
# File 'lib/ollama_chat/switches.rb', line 281 def markdown @markdown end |
#memory_trigger ⇒ Object (readonly)
Controls whether the session's memory trigger is active. The enabled
state is read from and written to the session's trigger hash; the
switch is a no-op when no trigger is configured.
336 337 338 |
# File 'lib/ollama_chat/switches.rb', line 336 def memory_trigger @memory_trigger end |
#runtime_info ⇒ Object (readonly)
Controls the visibility of runtime information in the chat.
322 323 324 |
# File 'lib/ollama_chat/switches.rb', line 322 def runtime_info @runtime_info end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
277 278 279 |
# File 'lib/ollama_chat/switches.rb', line 277 def stream @stream end |
#think_loud ⇒ Object (readonly)
Returns the value of attribute think_loud.
285 286 287 |
# File 'lib/ollama_chat/switches.rb', line 285 def think_loud @think_loud end |
#think_strip ⇒ Object (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.
296 297 298 |
# File 'lib/ollama_chat/switches.rb', line 296 def think_strip @think_strip end |
#tools_support ⇒ Object (readonly)
Controls tool support (off → skip all, on → honour per‑tool state).
328 329 330 |
# File 'lib/ollama_chat/switches.rb', line 328 def tools_support @tools_support end |
#voice ⇒ Object (readonly)
Returns the value of attribute voice.
300 301 302 |
# File 'lib/ollama_chat/switches.rb', line 300 def voice @voice end |
Instance Method Details
#setup_switches ⇒ Object
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.
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 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/ollama_chat/switches.rb', line 350 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..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 = -> * { refresh_system_prompt } @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.", } ) @memory_trigger = Switch.new( value: -> new_value = OllamaChat::Switches::Switch::UNSET { if new_value == OllamaChat::Switches::Switch::UNSET chat.session.trigger_enabled? else chat.session.set_trigger_enabled(new_value) nil end }, msg: { true => "Memory trigger active.", false => "Memory trigger inactive.", }, ) @context_manifest = DatabaseSwitch.new( chat: self, attribute: :context_manifest_enabled, msg: { true => "Context manifest enabled.", false => "Context manifest disabled.", } ) end |