Class: OllamaChat::Database::Models::Session
- Inherits:
-
Object
- Object
- OllamaChat::Database::Models::Session
- Includes:
- Duplicatable, SessionLocking
- Defined in:
- lib/ollama_chat/database/models/session.rb
Overview
Represents a persistent chat session in the database, managing the configuration, state, and message history for an individual chat interaction.
This model utilizes Sequel plugins to handle timestamps, object touching, and the JSON serialization of complex attributes such as ‘tools_default_enabled` and `model_options`.
Class Method Summary collapse
-
.with_defaults(chat) ⇒ OllamaChat::Database::Models::Session
The with_defaults method is a factory method that initializes a new Session model instance with a set of default values derived from the.
Instance Method Summary collapse
-
#age(now: Time.now) ⇒ Tins::Duration
Calculates the age of the session based on the last update timestamp.
-
#created_at(value) ⇒ Time?
The timestamp when the session was created.
-
#current_collection(value) ⇒ String?
The name of the currently active document collection.
-
#current_model(value) ⇒ String?
The name of the model currently active in this session.
-
#current_system_prompt(value) ⇒ String?
The text of the current system prompt.
-
#current_voice(value) ⇒ String
The name of the voice currently in use.
-
#default_persona_name(value) ⇒ String?
The identifier of the persona set as default for this session.
-
#document_policy(value) ⇒ String
The policy for handling document references (must be one of ‘DOCUMENT_POLICY_STATES`).
-
#embedding_enabled(value) ⇒ Boolean
Whether embedding/RAG capabilities are enabled.
-
#id(value) ⇒ Integer
The primary key for the session.
-
#location_enabled(value) ⇒ Boolean
Whether location-based information is enabled.
-
#locked_by_pid(value) ⇒ Integer?
The process ID that currently holds a lock on this session.
-
#markdown_enabled(value) ⇒ Boolean
Whether Markdown rendering is enabled for the session.
-
#messages(value) ⇒ String
The full conversation history, stored in JSONL format.
-
#model_options(value) ⇒ String?
A JSON-serialized string containing model-specific options.
-
#name(value) ⇒ String
The unique name of the session.
-
#runtime_info_enabled(value) ⇒ Boolean
Whether runtime information is displayed during the session.
-
#stream_enabled(value) ⇒ Boolean
Whether the response should be streamed.
-
#think_loud_enabled(value) ⇒ Boolean
Whether thinking annotations are displayed in the output.
-
#think_mode(value) ⇒ String
The current thinking mode (must be one of ‘THINK_MODE_STATES`).
-
#think_strip_enabled(value) ⇒ Boolean
Whether thinking content should be stripped from the final output.
-
#tools_default_enabled(value) ⇒ String?
A JSON-serialized string containing default settings for tools.
-
#tools_enabled(value) ⇒ Boolean
Indicates whether tool calling is enabled.
-
#updated_at(value) ⇒ Time?
The timestamp of the last update to the session.
-
#validate ⇒ Object
Validates the session instance.
-
#voice_enabled(value) ⇒ Boolean
Whether voice output is enabled.
-
#working_directory(value) ⇒ String
The directory used as the working context for this session.
Methods included from Duplicatable
Methods included from SessionLocking
#lock, #lock?, #locked?, #unlock
Class Method Details
.with_defaults(chat) ⇒ OllamaChat::Database::Models::Session
The with_defaults method is a factory method that initializes a new Session model instance with a set of default values derived from the
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ollama_chat/database/models/session.rb', line 121 def self.with_defaults(chat) tools_default_enabled = chat.config.tools.functions.to_h. each_with_object({}) { |(name, f), h| h[name.to_s] = f[:default] } current_model = chat.initial_model = chat.(current_model) attributes = { name: "New Session #{Tins::Token.new}", current_model: , current_collection: chat.initial_collection, default_persona_name: chat.initial_persona_name, current_system_prompt: chat.initial_system_prompt, tools_enabled: chat.config.tools.enabled, tools_default_enabled: , think_mode: chat.config.think.mode, think_loud_enabled: chat.config.think.loud, embedding_enabled: chat.config..enabled, document_policy: chat.config.document_policy, runtime_info_enabled: chat.config.runtime_info.enabled, think_strip_enabled: chat.config.think.strip, markdown_enabled: chat.config.markdown, stream_enabled: chat.config.stream, location_enabled: chat.config.location.enabled, voice_enabled: chat.config.voice.enabled, model_options: , current_voice: chat.config.voice.default, working_directory: Dir.pwd, messages: '', } new(attributes) end |
Instance Method Details
#age(now: Time.now) ⇒ Tins::Duration
Calculates the age of the session based on the last update timestamp.
35 36 37 |
# File 'lib/ollama_chat/database/models/session.rb', line 35 def age(now: Time.now) Tins::Duration.new(updated_at ? now - updated_at : 0) end |
#created_at=(value) ⇒ Time?
Returns The timestamp when the session was created.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#current_collection=(value) ⇒ String?
Returns The name of the currently active document collection.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#current_model=(value) ⇒ String?
Returns The name of the model currently active in this session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#current_system_prompt=(value) ⇒ String?
Returns The text of the current system prompt.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#current_voice=(value) ⇒ String
Returns The name of the voice currently in use.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#default_persona_name=(value) ⇒ String?
Returns The identifier of the persona set as default for this session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#document_policy=(value) ⇒ String
Returns The policy for handling document references (must be one of ‘DOCUMENT_POLICY_STATES`).
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#embedding_enabled=(value) ⇒ Boolean
Returns Whether embedding/RAG capabilities are enabled.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#id=(value) ⇒ Integer
Returns The primary key for the session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#location_enabled=(value) ⇒ Boolean
Returns Whether location-based information is enabled.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#locked_by_pid=(value) ⇒ Integer?
Returns The process ID that currently holds a lock on this session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#markdown_enabled=(value) ⇒ Boolean
Returns Whether Markdown rendering is enabled for the session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#messages=(value) ⇒ String
Returns The full conversation history, stored in JSONL format.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#model_options=(value) ⇒ String?
Returns A JSON-serialized string containing model-specific options.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#name=(value) ⇒ String
Returns The unique name of the session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#runtime_info_enabled=(value) ⇒ Boolean
Returns Whether runtime information is displayed during the session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#stream_enabled=(value) ⇒ Boolean
Returns Whether the response should be streamed.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#think_loud_enabled=(value) ⇒ Boolean
Returns Whether thinking annotations are displayed in the output.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#think_mode=(value) ⇒ String
Returns The current thinking mode (must be one of ‘THINK_MODE_STATES`).
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#think_strip_enabled=(value) ⇒ Boolean
Returns Whether thinking content should be stripped from the final output.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#tools_default_enabled=(value) ⇒ String?
Returns A JSON-serialized string containing default settings for tools.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#tools_enabled=(value) ⇒ Boolean
Returns Indicates whether tool calling is enabled.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#updated_at=(value) ⇒ Time?
Returns The timestamp of the last update to the session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#validate ⇒ Object
Validates the session instance.
Ensures that the ‘name` and essential timestamps (`updated_at`, `created_at`) are present to ensure session age calculations can be performed without Nil errors.
22 23 24 25 26 27 28 |
# File 'lib/ollama_chat/database/models/session.rb', line 22 def validate super validates_presence :name validates_unique :name validates_presence :updated_at validates_presence :created_at end |
#voice_enabled=(value) ⇒ Boolean
Returns Whether voice output is enabled.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|
#working_directory=(value) ⇒ String
Returns The directory used as the working context for this session.
|
|
# File 'lib/ollama_chat/database/models/session.rb', line 39
|