Module: OllamaChat::History
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/history.rb
Instance Method Summary collapse
-
#chat_history_filename ⇒ Object
Returns the full path of the chat history filename based on the configuration.
-
#clear_history ⇒ Object
Clears all entries from Readline::HISTORY.
-
#init_chat_history ⇒ Object
Initializes the chat history by loading it from a file if it exists, and then loads the history into Readline::HISTORY.
-
#save_history ⇒ Object
Saves the current chat history to a file in JSON format.
Instance Method Details
#chat_history_filename ⇒ Object
Returns the full path of the chat history filename based on the configuration.
4 5 6 |
# File 'lib/ollama_chat/history.rb', line 4 def chat_history_filename File.(config.chat_history_filename) end |
#clear_history ⇒ Object
Clears all entries from Readline::HISTORY.
26 27 28 |
# File 'lib/ollama_chat/history.rb', line 26 def clear_history Readline::HISTORY.clear end |
#init_chat_history ⇒ Object
Initializes the chat history by loading it from a file if it exists, and then loads the history into Readline::HISTORY.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ollama_chat/history.rb', line 10 def init_chat_history if File.exist?(chat_history_filename) File.open(chat_history_filename, ?r) do |history| history_data = JSON.load(history) clear_history Readline::HISTORY.push(*history_data) end end end |
#save_history ⇒ Object
Saves the current chat history to a file in JSON format.
21 22 23 |
# File 'lib/ollama_chat/history.rb', line 21 def save_history File.secure_write(chat_history_filename, JSON.dump(Readline::HISTORY)) end |