重构代码,实现相对导入
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 5m26s

This commit is contained in:
2026-04-21 10:26:37 +08:00
parent 37e021e302
commit 726236eaff
68 changed files with 119 additions and 3990 deletions

View File

@@ -0,0 +1,4 @@
# Frontend - Lightweight dependencies only
streamlit==1.39.0
requests==2.32.3
python-dotenv==1.2.2

View File

@@ -3,7 +3,7 @@ AI Agent 前端模块
采用分层架构设计包含配置状态API客户端和UI组件
"""
from frontend.logger import debug, info, warning, error
from .logger import debug, info, warning, error
__version__ = "2.0.0"
__all__ = ["debug", "info", "warning", "error"]

View File

@@ -7,9 +7,9 @@ import json
from typing import List, Dict, Any, Generator
import requests
# 使用对导入
from frontend.config import config
from frontend.logger import error, warning
# 使用对导入
from .config import config
from .logger import error, warning
class APIClient:

View File

@@ -6,10 +6,10 @@
import re
import streamlit as st
# 使用对导入
from frontend.state import AppState
from frontend.api_client import api_client
from frontend.config import config
# 使用对导入
from ..state import AppState
from ..api_client import api_client
from ..config import config
def render_chat_area():
@@ -325,7 +325,7 @@ def _handle_ai_response():
# 消息发送完毕后,静默刷新历史记录列表
# (因为可能生成了新对话,或者旧对话摘要已更新)
from frontend.components.sidebar import _refresh_threads
from .sidebar import _refresh_threads
_refresh_threads()
# 强制重绘页面,使侧边栏立即显示最新记录

View File

@@ -5,8 +5,8 @@
import streamlit as st
# 使用对导入
from frontend.state import AppState
# 使用对导入
from ..state import AppState
def render_info_panel():

View File

@@ -6,9 +6,9 @@
import streamlit as st
from datetime import datetime
# 使用对导入
from frontend.state import AppState
from frontend.api_client import api_client
# 使用对导入
from ..state import AppState
from ..api_client import api_client
def render_sidebar():
"""渲染左侧栏"""

View File

@@ -7,16 +7,17 @@ import sys
import os
# 添加项目根目录到 Python 路径,支持绝对导入
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 现在的结构: frontend/src/frontend_main.py所以要获取 frontend/ 目录作为根
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import streamlit as st
# 使用对导入
from frontend.config import config
from frontend.state import AppState
from frontend.components.sidebar import render_sidebar
from frontend.components.chat_area import render_chat_area
from frontend.components.info_panel import render_info_panel
# 使用对导入
from .config import config
from .state import AppState
from .components.sidebar import render_sidebar
from .components.chat_area import render_chat_area
from .components.info_panel import render_info_panel
# =============================================================================

View File

@@ -7,7 +7,7 @@ import uuid
from typing import List, Dict, Any
import streamlit as st
from frontend.config import config
from .config import config
class AppState: