fix: fetch llm tool no longer depends on system libssl.so (#1404)

This commit is contained in:
yetone
2025-02-26 17:36:01 +08:00
committed by GitHub
parent ef78c36e98
commit 6f98cb0ed6
11 changed files with 169 additions and 36 deletions

View File

@@ -19,7 +19,7 @@ function M.setup() vim.defer_fn(M._init_html2md_lib, 1000) end
function M.fetch_md(url)
local html2md_lib = M._init_html2md_lib()
if not html2md_lib then return "", "Failed to load avante_html2md" end
if not html2md_lib then return nil, "Failed to load avante_html2md" end
return html2md_lib.fetch_md(url)
end

View File

@@ -28,6 +28,7 @@ function H.load_path()
local ok, LazyConfig = pcall(require, "lazy.core.config")
if ok then
Utils.debug("LazyConfig loaded")
local name = "avante.nvim"
local function load_path() require("avante_lib").load() end
@@ -406,7 +407,6 @@ function M.setup(opts)
local uri = "file://" .. Utils.get_project_root()
if uri:sub(-1) ~= "/" then uri = uri .. "/" end
RagService.add_resource(uri)
Utils.info("Added project root to Rag Service")
end, 5000)
end
add_resource_with_delay = function()

View File

@@ -380,8 +380,8 @@ end
function M.fetch(opts, on_log)
if on_log then on_log("url: " .. opts.url) end
local Html2Md = require("avante.html2md")
local res = Html2Md.fetch_md(opts.url)
if res == nil then return nil, "Failed to fetch markdown" end
local res, err = Html2Md.fetch_md(opts.url)
if err then return nil, err end
return res, nil
end

View File

@@ -135,7 +135,6 @@ end
---@field message string
---@param uri string
---@return AvanteRagServiceAddResourceResponse | nil
function M.add_resource(uri)
uri = M.to_container_uri(uri)
local resource_name = uri:match("([^/]+)/$")
@@ -171,20 +170,23 @@ function M.add_resource(uri)
end
end
end
local resp = curl.post(M.get_rag_service_url() .. "/api/v1/add_resource", {
headers = {
["Content-Type"] = "application/json",
},
body = vim.json.encode({
name = resource_name,
uri = uri,
}),
})
if resp.status ~= 200 then
Utils.error("failed to add resource: " .. resp.body)
return
end
return vim.json.decode(resp.body)
local cmd = {
"curl",
"-X",
"POST",
M.get_rag_service_url() .. "/api/v1/add_resource",
"-H",
"Content-Type: application/json",
"-d",
vim.json.encode({ name = resource_name, uri = uri }),
}
vim.system(cmd, { text = true }, function(output)
if output.code == 0 then
Utils.debug(string.format("Added resource: %s", uri))
else
Utils.error(string.format("Failed to add resource: %s; output: %s", uri, output.stderr))
end
end)
end
function M.remove_resource(uri)