Module: OllamaChat::History

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

Instance Method Summary collapse

Instance Method Details

#chat_history_filenameObject



2
3
4
# File 'lib/ollama_chat/history.rb', line 2

def chat_history_filename
  File.expand_path(config.chat_history_filename)
end

#clear_historyObject



20
21
22
# File 'lib/ollama_chat/history.rb', line 20

def clear_history
  Readline::HISTORY.clear
end

#init_chat_historyObject



6
7
8
9
10
11
12
13
14
# File 'lib/ollama_chat/history.rb', line 6

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_historyObject



16
17
18
# File 'lib/ollama_chat/history.rb', line 16

def save_history
  File.secure_write(chat_history_filename, JSON.dump(Readline::HISTORY))
end