Module: OllamaChat::StateSelectors

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

Overview

A module that provides state selection functionality for OllamaChat.

The StateSelectors module encapsulates the StateSelector class, which manages configurable states with selection and display capabilities. It is used to handle various settings in the chat application such as document policies and think modes, allowing users to dynamically configure different aspects of the chat session behavior.

Defined Under Namespace

Modules: Common Classes: DatabaseStateSelector, StateSelector

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#context_format ⇒ OllamaChat::StateSelector (readonly)

The context_format reader returns the context format selector for the chat session.

Returns:

  • (OllamaChat::StateSelector) —

    the context format selector object that manages the format used for project context generation (e.g., 'JSON', 'TOON')



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

def context_format
  @context_format
end

#document_policy ⇒ OllamaChat::StateSelector (readonly)

The document_policy reader returns the document policy selector for the chat session.

Returns:

  • (OllamaChat::StateSelector) —

    the document policy selector object that manages the policy for handling document references in user text



254
255
256
# File 'lib/ollama_chat/state_selectors.rb', line 254

def document_policy
  @document_policy
end

#think_mode ⇒ OllamaChat::StateSelector (readonly)

The think_mode reader returns the think mode selector for the chat session.

Returns:

  • (OllamaChat::StateSelector) —

    the think mode selector object that manages the thinking mode setting for the Ollama model interactions



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

def think_mode
  @think_mode
end

#voices ⇒ OllamaChat::StateSelector (readonly)

The voices reader returns the voice selector for the chat session.

Returns:

  • (OllamaChat::StateSelector) —

    the voice selector object that manages the currently selected voice for the chat session



266
267
268
# File 'lib/ollama_chat/state_selectors.rb', line 266

def voices
  @voices
end

Instance Method Details

#setup_state_selectors(config) ⇒ Object

Sets up state selectors for document policy and think mode based on the provided configuration.

Parameters:

  • config (ComplexConfig::Settings) —

    the configuration object containing settings for document policy and think mode



281
282
283
284
285
286
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
# File 'lib/ollama_chat/state_selectors.rb', line 281

def setup_state_selectors(config)
  @document_policy = DatabaseStateSelector.new(
    chat:      self,
    attribute: :document_policy,
    name:      'Document policy',
    states:    OllamaChat::Parsing::DOCUMENT_POLICY_STATES,
    off:       OllamaChat::Parsing::DOCUMENT_POLICY_STATES[0, 1],
  )
  @think_mode = DatabaseStateSelector.new(
    chat:      self,
    attribute: :think_mode,
    name:      'Think mode',
    states:    -> chat { chat.think_mode_states },
    off:       -> chat { chat.think_mode_states[0, 1] },
  )
  @voices = DatabaseStateSelector.new(
    chat:        self,
    attribute:   :current_voice,
    name:        'Voice',
    states:      -> chat {
                  Array(voice_handler.ask_and_send(
                    :voices, chat:, model: chat.config.voice.model?
                  ))
                },
    allow_empty: true
  )
  @context_format = DatabaseStateSelector.new(
    chat:      self,
    attribute: :context_format,
    name:      'Context format',
    states:    %w[ JSON TOON ],
  )
end