Module: OllamaChat::MessageEditing
- Included in:
- Chat
- Defined in:
- lib/ollama_chat/message_editing.rb
Overview
A module that provides message editing functionality for OllamaChat.
The MessageEditing module encapsulates methods for modifying existing chat messages using an external editor.
Instance Method Summary collapse
-
#change_response ⇒ String?
private
The change_response method opens the last message (usually the assistant’s response) in an external editor for modification.
Instance Method Details
#change_response ⇒ String? (private)
The change_response method opens the last message (usually the assistant’s response) in an external editor for modification.
This method retrieves the last message from the conversation, writes its content to a temporary file, opens that file in the configured editor, and then updates the message with the edited content upon successful completion.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ollama_chat/message_editing.rb', line 17 def change_response if = @messages.last Tempfile.open do |tmp| tmp.write(.content) tmp.flush if result = edit_file(tmp.path) new_content = File.read(tmp.path) = @messages..pop.as_json [:content] = new_content @messages << Ollama::Message.from_hash() STDOUT.puts "Message edited and updated." return new_content else STDERR.puts "Editor failed to edit message." end end else STDERR.puts "No message available to change." end nil end |