3.2 KiB
3.2 KiB
Graph-RAG-Agent 服务未运行问题解决方案
问题描述
错误信息:
连接错误: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /chat/stream
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001DD24E19F60>:
Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))
这表明 graph-rag-agent 服务没有在 8000 端口运行。
解决步骤
1. 首先恢复 CORS 支持
由于你恢复了原始文件,需要重新添加 CORS 支持:
cd ~/graph-rag-agent/server
cp main.py.cors_backup main.py
或者手动编辑 main.py,在导入部分添加:
from fastapi.middleware.cors import CORSMiddleware
在 app = FastAPI(...) 之后添加:
# 配置 CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 允许所有源
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
2. 检查依赖是否安装
cd ~/graph-rag-agent
pip install -r requirements.txt
3. 检查 Neo4j 是否运行
# Windows PowerShell
netstat -an | findstr 7687
# 或在 WSL/Linux 中
sudo lsof -i :7687
4. 启动 graph-rag-agent 服务
在 Windows 中:
cd C:\path\to\graph-rag-agent
python -m uvicorn server.main:app --reload --host 0.0.0.0 --port 8000
在 WSL/Linux 中:
cd ~/graph-rag-agent
python -m uvicorn server.main:app --reload --host 0.0.0.0 --port 8000
5. 常见启动问题
问题 1:ModuleNotFoundError
ModuleNotFoundError: No module named 'xxx'
解决:安装缺失的模块
pip install xxx
问题 2:Neo4j 连接失败
neo4j.exceptions.ServiceUnavailable: Unable to connect to localhost:7687
解决:
- 启动 Neo4j 服务
- 检查 config/settings.py 中的 Neo4j 配置
问题 3:端口被占用
[Errno 48] Address already in use
解决:
- 查找占用端口的进程:
# Windows netstat -ano | findstr :8000 # Linux/Mac lsof -i :8000 - 终止进程或使用其他端口
6. 验证服务是否启动
-
在浏览器访问:
http://localhost:8000/docs应该看到 FastAPI 的 API 文档页面
-
使用 curl 测试:
curl http://localhost:8000/ -
测试 CORS:
curl -I -X OPTIONS http://localhost:8000/chat \ -H "Origin: http://localhost:3000" \ -H "Access-Control-Request-Method: POST"
7. 完整启动流程
- 启动 Neo4j(如果需要)
- 恢复 CORS 配置
- 启动 graph-rag-agent:
cd ~/graph-rag-agent python -m uvicorn server.main:app --reload --host 0.0.0.0 --port 8000 - 启动前端(在另一个终端):
cd ~/yundage-backserver-test python -m http.server 3000 - 访问前端:http://localhost:3000
调试建议
- 查看 graph-rag-agent 的启动日志,看是否有错误
- 确保所有依赖都已正确安装
- 检查防火墙设置是否阻止了 8000 端口
- 如果在 WSL 中运行,确保 Windows 防火墙允许 WSL 访问