response to log
This commit is contained in:
parent
481bed92cd
commit
0e142811f4
@ -194,15 +194,24 @@ M.parse_messages = function(opts)
|
|||||||
|
|
||||||
return final_messages
|
return final_messages
|
||||||
end
|
end
|
||||||
|
local path = "/tmp/avante/avante_requests.log"
|
||||||
|
local file = io.open(path, "a")
|
||||||
|
if not file then error("无法打开日志文件: " .. path) end
|
||||||
|
|
||||||
M.parse_response = function(ctx, data_stream, _, opts)
|
M.parse_response = function(ctx, data_stream, _, opts)
|
||||||
|
local log_file = io.open("/tmp/avante/avante_requests.log", "a")
|
||||||
|
if not log_file then error("无法打开日志文件: /tmp/avante/avante_requests.log") end
|
||||||
|
|
||||||
if data_stream:match('"%[DONE%]":') then
|
if data_stream:match('"%[DONE%]":') then
|
||||||
opts.on_stop({ reason = "complete" })
|
opts.on_stop({ reason = "complete" })
|
||||||
|
log_file:write("Response completed at: " .. os.date() .. "\n")
|
||||||
|
log_file:close()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if data_stream:match('"delta":') then
|
if data_stream:match('"delta":') then
|
||||||
---@type OpenAIChatResponse
|
---@type OpenAIChatResponse
|
||||||
local jsn = vim.json.decode(data_stream)
|
local jsn = vim.json.decode(data_stream)
|
||||||
|
log_file:write("Response data: " .. data_stream .. "\n")
|
||||||
if jsn.choices and jsn.choices[1] then
|
if jsn.choices and jsn.choices[1] then
|
||||||
local choice = jsn.choices[1]
|
local choice = jsn.choices[1]
|
||||||
if choice.finish_reason == "stop" or choice.finish_reason == "eos_token" then
|
if choice.finish_reason == "stop" or choice.finish_reason == "eos_token" then
|
||||||
@ -242,6 +251,7 @@ M.parse_response = function(ctx, data_stream, _, opts)
|
|||||||
tool_use.input_json = tool_use.input_json .. tool_call["function"].arguments
|
tool_use.input_json = tool_use.input_json .. tool_call["function"].arguments
|
||||||
end
|
end
|
||||||
elseif choice.delta.content then
|
elseif choice.delta.content then
|
||||||
|
log_file:write("Content delta: " .. choice.delta.content .. "\n")
|
||||||
if
|
if
|
||||||
ctx.returned_think_start_tag ~= nil and (ctx.returned_think_end_tag == nil or not ctx.returned_think_end_tag)
|
ctx.returned_think_start_tag ~= nil and (ctx.returned_think_end_tag == nil or not ctx.returned_think_end_tag)
|
||||||
then
|
then
|
||||||
@ -263,8 +273,13 @@ M.parse_response = function(ctx, data_stream, _, opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.parse_response_without_stream = function(data, _, opts)
|
M.parse_response_without_stream = function(data, _, opts)
|
||||||
|
local log_file = io.open("/tmp/avante/avante_requests.log", "a")
|
||||||
|
if not log_file then error("无法打开日志文件: /tmp/avante/avante_requests.log") end
|
||||||
|
|
||||||
---@type OpenAIChatResponse
|
---@type OpenAIChatResponse
|
||||||
local json = vim.json.decode(data)
|
local json = vim.json.decode(data)
|
||||||
|
log_file:write("Non-stream response: " .. data .. "\n")
|
||||||
|
log_file:close()
|
||||||
if json.choices and json.choices[1] then
|
if json.choices and json.choices[1] then
|
||||||
local choice = json.choices[1]
|
local choice = json.choices[1]
|
||||||
if choice.message and choice.message.content then
|
if choice.message and choice.message.content then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user