refactor: 统一导入方式,移除 sys.path 操作
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m22s

- 重构所有模块导入,移除 sys.path.insert
- 统一使用 from backend.xxx 的绝对导入方式
- rag_core 包内使用相对导入(from .xxx)
- 移动 visualize_graph.py 到 tools/ 目录
- 添加必要的 __init__.py 文件
- 清理废弃文档和脚本
This commit is contained in:
2026-05-04 12:55:45 +08:00
parent 82dde7113e
commit 4209386c77
24 changed files with 43 additions and 809 deletions

View File

@@ -7,15 +7,6 @@
import sys
import os
# 添加必要的路径
project_root = os.path.dirname(os.path.abspath(__file__))
frontend_src = os.path.join(project_root, "frontend", "src")
backend_dir = os.path.join(project_root, "backend")
sys.path.insert(0, project_root)
sys.path.insert(0, frontend_src)
sys.path.insert(0, backend_dir)
print("=" * 60)
print("前端导入测试")
print("=" * 60)
@@ -32,7 +23,7 @@ except Exception as e:
# 测试 2: 导入配置
print("\n[测试 2] 导入配置...")
try:
from config import config
from frontend.src.config import config
print(f"✅ config 导入成功: page_title={config.page_title}")
except Exception as e:
print(f"❌ 导入失败: {e}")
@@ -40,7 +31,7 @@ except Exception as e:
# 测试 3: 导入状态管理
print("\n[测试 3] 导入状态管理...")
try:
from state import AppState
from frontend.src.state import AppState
print("✅ AppState 导入成功")
except Exception as e:
print(f"❌ 导入失败: {e}")
@@ -48,7 +39,7 @@ except Exception as e:
# 测试 4: 导入 API 客户端
print("\n[测试 4] 导入 API 客户端...")
try:
from api_client import api_client
from frontend.src.api_client import api_client
print("✅ api_client 导入成功")
except Exception as e:
print(f"❌ 导入失败: {e}")
@@ -56,9 +47,9 @@ except Exception as e:
# 测试 5: 导入组件
print("\n[测试 5] 导入组件...")
try:
from components.sidebar import render_sidebar
from components.chat_area import render_chat_area
from components.info_panel import render_info_panel
from frontend.src.components.sidebar import render_sidebar
from frontend.src.components.chat_area import render_chat_area
from frontend.src.components.info_panel import render_info_panel
print("✅ 所有组件导入成功")
except Exception as e:
print(f"❌ 导入失败: {e}")