feat: RAG service (#1220)

This commit is contained in:
yetone
2025-02-23 01:37:26 +08:00
committed by GitHub
parent 437d36920d
commit fd84c91cdb
32 changed files with 2339 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ local Selection = require("avante.selection")
local Suggestion = require("avante.suggestion")
local Config = require("avante.config")
local Diff = require("avante.diff")
local RagService = require("avante.rag_service")
---@class Avante
local M = {
@@ -383,6 +384,41 @@ function M.setup(opts)
H.signs()
M.did_setup = true
local function run_rag_service()
local started_at = os.time()
local add_resource_with_delay
local function add_resource()
local is_ready = RagService.is_ready()
if not is_ready then
local elapsed = os.time() - started_at
if elapsed > 1000 * 60 * 15 then
Utils.warn("Rag Service is not ready, giving up")
return
end
add_resource_with_delay()
return
end
vim.defer_fn(function()
Utils.info("Adding project root to Rag Service ...")
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()
vim.defer_fn(function() add_resource() end, 5000)
end
vim.schedule(function()
Utils.info("Starting Rag Service ...")
RagService.launch_rag_service()
Utils.info("Launched Rag Service")
add_resource_with_delay()
end)
end
if Config.rag_service.enabled then run_rag_service() end
end
return M