Module: OllamaChat::Conversation
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/conversation.rb
Overview
A module that provides conversation persistence functionality for the OllamaChat::Chat class.
This module encapsulates the logic for saving and loading chat conversations to/from JSON files. It delegates the actual file operations to the ‘messages` object, which is expected to respond to `save_conversation` and `load_conversation` methods.
Instance Method Summary collapse
-
#load_conversation(filename) ⇒ Object
Loads a conversation from a JSON file and replaces the current message history.
-
#save_conversation(filename) ⇒ Object
Saves the current conversation to a JSON file.
Instance Method Details
#load_conversation(filename) ⇒ Object
Loads a conversation from a JSON file and replaces the current message history.
This method delegates to the ‘messages` object’s ‘load_conversation` method, which handles deserialization of messages from JSON format. After loading, if there are more than one message, it lists the last two messages for confirmation.
to load
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ollama_chat/conversation.rb', line 47 def load_conversation(filename) success = .load_conversation(filename) if .size > 1 .list_conversation(2) end if success STDOUT.puts "Loaded conversation from #{filename.inspect}." else STDERR.puts "Loading conversation from #{filename.inspect} failed." end end |
#save_conversation(filename) ⇒ Object
Saves the current conversation to a JSON file.
This method delegates to the ‘messages` object’s ‘save_conversation` method, which handles the actual serialization of messages into JSON format.
be saved
26 27 28 29 30 31 32 |
# File 'lib/ollama_chat/conversation.rb', line 26 def save_conversation(filename) if .save_conversation(filename) STDOUT.puts "Saved conversation to #{filename.inspect}." else STDERR.puts "Saving conversation to #{filename.inspect} failed." end end |