Module: OllamaChat::SessionManagement
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/session_management.rb
Overview
The OllamaChat::SessionHandling module provides methods for managing chat sessions, including creating, listing, switching, renaming, and deleting sessions.
It integrates closely with the database-backed Session model and ensures that session data is persisted correctly, especially the conversation history.
Instance Attribute Summary collapse
-
#session ⇒ OllamaChat::Database::Models::Session
readonly
The session reader returns the current session object.
Instance Method Summary collapse
-
#load_links_from_session ⇒ Array<String>
Loads the collection of links from the current session.
-
#store_links_in_session(links) ⇒ Object
Persists a collection of links to the session in the database.
-
#store_messages_in_session ⇒ Object
Persists the current conversation messages to the database.
Instance Attribute Details
#session ⇒ OllamaChat::Database::Models::Session (readonly)
The session reader returns the current session object.
49 50 51 |
# File 'lib/ollama_chat/session_management.rb', line 49 def session @session end |
Instance Method Details
#load_links_from_session ⇒ Array<String>
Loads the collection of links from the current session.
This method reads the links attribute from the session and
deserializes it from JSONL format.
40 41 42 43 |
# File 'lib/ollama_chat/session_management.rb', line 40 def load_links_from_session input = StringIO.new(session.links) OllamaChat::Utils::JSONJSONLIO.new('as.jsonl').read_io(input:) end |
#store_links_in_session(links) ⇒ Object
Persists a collection of links to the session in the database.
This method serializes the links into JSONL format and updates the
links attribute of the current session.
25 26 27 28 29 30 31 32 |
# File 'lib/ollama_chat/session_management.rb', line 25 def store_links_in_session(links) output = StringIO.new OllamaChat::Utils::JSONJSONLIO.new('as.jsonl').write_io( output:, collection: links ) session.update(links: output.string) self end |
#store_messages_in_session ⇒ Object
Persists the current conversation messages to the database.
This method serializes the current message list into JSONL format and
updates the messages attribute of the current session.
12 13 14 15 16 17 |
# File 'lib/ollama_chat/session_management.rb', line 12 def output = StringIO.new .write_conversation_jsonl(output) session.update(messages: output.string) self end |