refactor(history): change HistoryMessage:new() to accept role and item
Change the constructor to accept role and a single content item instead of raw AvanteLLMMessage instance. This will help when we will start changing message.content from being a string or a list of tables to just a string or a single table.
This commit is contained in:
@@ -135,27 +135,24 @@ function M:is_disable_stream() return false end
|
||||
---@param tool_calls avante.OllamaToolCall[]
|
||||
---@param opts AvanteLLMStreamOptions
|
||||
function M:add_tool_use_messages(tool_calls, opts)
|
||||
local msgs = {}
|
||||
for _, tool_call in ipairs(tool_calls) do
|
||||
local id = Utils.uuid()
|
||||
local func = tool_call["function"]
|
||||
local msg = HistoryMessage:new({
|
||||
role = "assistant",
|
||||
content = {
|
||||
{
|
||||
type = "tool_use",
|
||||
name = func.name,
|
||||
id = id,
|
||||
input = func.arguments,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
state = "generated",
|
||||
uuid = id,
|
||||
})
|
||||
table.insert(msgs, msg)
|
||||
if opts.on_messages_add then
|
||||
local msgs = {}
|
||||
for _, tool_call in ipairs(tool_calls) do
|
||||
local id = Utils.uuid()
|
||||
local func = tool_call["function"]
|
||||
local msg = HistoryMessage:new("assistant", {
|
||||
type = "tool_use",
|
||||
name = func.name,
|
||||
id = id,
|
||||
input = func.arguments,
|
||||
}, {
|
||||
state = "generated",
|
||||
uuid = id,
|
||||
})
|
||||
table.insert(msgs, msg)
|
||||
end
|
||||
opts.on_messages_add(msgs)
|
||||
end
|
||||
if opts.on_messages_add then opts.on_messages_add(msgs) end
|
||||
end
|
||||
|
||||
function M:parse_stream_data(ctx, data, opts)
|
||||
|
||||
Reference in New Issue
Block a user