diff --git a/dsLightRag/Start.py b/dsLightRag/Start.py index bae5d5a0..92e6f22b 100644 --- a/dsLightRag/Start.py +++ b/dsLightRag/Start.py @@ -54,10 +54,10 @@ app = FastAPI(lifespan=lifespan) # 挂载静态文件目录 app.mount("/static", StaticFiles(directory="Static"), name="static") -@app.post("/api/rag", response_model=None) +@app.post("/api/rag") async def rag(request: fastapi.Request): data = await request.json() - query = data.get('query', '') + query = data.get("query") working_dir = "./Test/Math" # 使用与T2_Query.py相同的目录 async def generate_response_stream(query: str): @@ -69,17 +69,15 @@ async def rag(request: fastapi.Request): if not chunk: continue - # 正确的SSE格式应该是单层data:前缀 + # 确保SSE格式正确 yield f"data: {json.dumps({'reply': chunk})}\n\n" - - # 打印到控制台用于调试 print(chunk, end='', flush=True) except Exception as e: yield f"data: {json.dumps({'error': str(e)})}\n\n" finally: if 'rag' in locals(): - await rag.finalize() + await rag.finalize_storages() return EventSourceResponse(generate_response_stream(query=query)) diff --git a/dsLightRag/static/ai.html b/dsLightRag/static/ai.html index 8c8f0889..eedf9dd7 100644 --- a/dsLightRag/static/ai.html +++ b/dsLightRag/static/ai.html @@ -308,15 +308,15 @@ function submitQuestion() { const question = document.getElementById('questionInput').value.trim(); const answerArea = document.getElementById('answerArea'); - + if (!question) { alert('请输入问题!'); return; } - + // 添加加载动画 answerArea.innerHTML = '