add request log
This commit is contained in:
parent
be74f25b82
commit
07abe12f54
@ -130,6 +130,13 @@ M._defaults = {
|
|||||||
temperature = 0,
|
temperature = 0,
|
||||||
max_tokens = 4096,
|
max_tokens = 4096,
|
||||||
},
|
},
|
||||||
|
baidu = {
|
||||||
|
endpoint = "https://dashscope.aliyuncs.com/compatible-mode/v1/",
|
||||||
|
model = "deepseek-v3",
|
||||||
|
timeout = 30000, -- Timeout in milliseconds
|
||||||
|
temperature = 0,
|
||||||
|
max_tokens = 4096,
|
||||||
|
},
|
||||||
---To add support for custom provider, follow the format below
|
---To add support for custom provider, follow the format below
|
||||||
---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details
|
---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details
|
||||||
---@type {[string]: AvanteProvider}
|
---@type {[string]: AvanteProvider}
|
||||||
|
@ -39,6 +39,8 @@ M.parse_response = function(ctx, data_stream, _, opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local Log = require("avante.utils.log")
|
||||||
|
|
||||||
M.parse_curl_args = function(provider, prompt_opts)
|
M.parse_curl_args = function(provider, prompt_opts)
|
||||||
local base, body_opts = P.parse_config(provider)
|
local base, body_opts = P.parse_config(provider)
|
||||||
|
|
||||||
@ -58,7 +60,7 @@ M.parse_curl_args = function(provider, prompt_opts)
|
|||||||
headers["Authorization"] = "Bearer " .. api_key
|
headers["Authorization"] = "Bearer " .. api_key
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
local request = {
|
||||||
url = Utils.url_join(base.endpoint, "/chat/completions"),
|
url = Utils.url_join(base.endpoint, "/chat/completions"),
|
||||||
proxy = base.proxy,
|
proxy = base.proxy,
|
||||||
insecure = base.allow_insecure,
|
insecure = base.allow_insecure,
|
||||||
@ -70,6 +72,11 @@ M.parse_curl_args = function(provider, prompt_opts)
|
|||||||
enable_citation = base.enable_citation,
|
enable_citation = base.enable_citation,
|
||||||
}, body_opts),
|
}, body_opts),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Log the request details
|
||||||
|
Log.log_request(request.url, request.headers, request.body)
|
||||||
|
|
||||||
|
return request
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
30
lua/avante/utils/log.lua
Normal file
30
lua/avante/utils/log.lua
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
local log_file = vim.fn.stdpath("cache") .. "/avante_requests.log"
|
||||||
|
|
||||||
|
function M.log_request(url, headers, body)
|
||||||
|
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
|
||||||
|
local log_entry = string.format(
|
||||||
|
[[
|
||||||
|
[%s] Request Details:
|
||||||
|
URL: %s
|
||||||
|
Headers:
|
||||||
|
%s
|
||||||
|
Body:
|
||||||
|
%s
|
||||||
|
]],
|
||||||
|
timestamp,
|
||||||
|
url,
|
||||||
|
vim.inspect(headers),
|
||||||
|
vim.inspect(body)
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Append to log file
|
||||||
|
local file = io.open(log_file, "a")
|
||||||
|
if file then
|
||||||
|
file:write(log_entry .. "\n\n")
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
Loading…
x
Reference in New Issue
Block a user