refactor(message): add helper to update contents of simple text message
Add update_content() helper so code outside of history module does not need to know details of the message structure.
This commit is contained in:
@@ -53,4 +53,11 @@ function M:new_assistant_synthetic(item) return M:new_synthetic("assistant", ite
|
||||
---@return avante.HistoryMessage
|
||||
function M:new_user_synthetic(item) return M:new_synthetic("user", item) end
|
||||
|
||||
---Updates content of a message as long as it is a simple text (or empty).
|
||||
---@param new_content string
|
||||
function M:update_content(new_content)
|
||||
assert(type(self.message.content) == "string", "can only update content of simple string messages")
|
||||
self.message.content = new_content
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -979,7 +979,7 @@ function M._stream(opts)
|
||||
opts.on_chunk(prefix .. "\n" .. msg_content .. "\n")
|
||||
end
|
||||
if opts.on_messages_add and message then
|
||||
message.message.content = "\n\n" .. msg_content
|
||||
message:update_content("\n\n" .. msg_content)
|
||||
opts.on_messages_add({ message })
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user