From 589e4d652dba1d9cd58b7fa37e3d6789815c33f0 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Tue, 15 Jul 2025 19:39:08 +0800 Subject: [PATCH] 'commit' --- dsLightRag/Start.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dsLightRag/Start.py b/dsLightRag/Start.py index d9ef745a..3fd9b84c 100644 --- a/dsLightRag/Start.py +++ b/dsLightRag/Start.py @@ -1,4 +1,6 @@ import json +import os.path +import shutil import subprocess import tempfile import urllib @@ -17,7 +19,6 @@ from starlette.staticfiles import StaticFiles from Util.LightRagUtil import * from Util.PostgreSQLUtil import init_postgres_pool - # 想更详细地控制日志输出 logger = logging.getLogger('lightrag') logger.setLevel(logging.INFO) @@ -30,7 +31,6 @@ async def lifespan(app: FastAPI): yield - app = FastAPI(lifespan=lifespan) # 挂载静态文件目录 @@ -98,10 +98,14 @@ async def rag(request: fastapi.Request): """ # 使用PG库后,这个是没有用的,但目前的项目代码要求必传,就写一个吧。 - WORKING_DIR = f"./output" + WORKING_DIR = workspace + if os.path.exists(WORKING_DIR): + shutil.rmtree(WORKING_DIR) + os.makedirs(WORKING_DIR) async def generate_response_stream(query: str): try: + logger.info("workspace=" + workspace) rag = await initialize_pg_rag(WORKING_DIR=WORKING_DIR, workspace=workspace) resp = await rag.aquery( query=query, @@ -314,7 +318,7 @@ async def get_sources(page: int = 1, limit: int = 10): """, limit, offset ) - + sources = [ { "id": row[0], @@ -324,7 +328,7 @@ async def get_sources(page: int = 1, limit: int = 10): } for row in rows ] - + return { "code": 0, "data": { @@ -357,7 +361,7 @@ async def get_articles(page: int = 1, limit: int = 10): """, limit, offset ) - + articles = [ { "id": row[0], @@ -369,7 +373,7 @@ async def get_articles(page: int = 1, limit: int = 10): } for row in rows ] - + return { "code": 0, "data": {