#!/bin/bash # 最终启动检查和启动脚本 echo "================================" echo "A股AI分析Agent - 最终检查" echo "================================" echo "" cd /Users/aaron/source_code/Stock_Agent/backend # 激活虚拟环境 if [ ! -d "venv" ]; then echo "❌ 虚拟环境不存在,请先运行 ../install.sh" exit 1 fi source venv/bin/activate # 快速导入测试 echo "1. 测试模块导入..." python3 << 'EOF' try: # 测试基础模块 from app.config import get_settings print(" ✓ 配置模块") from app.models.database import Base, Message print(" ✓ 数据库模型") from app.services.cache_service import cache_service print(" ✓ 缓存服务") from app.services.tushare_service import tushare_service print(" ✓ Tushare服务") from app.utils.stock_names import search_stock_by_name print(" ✓ 股票名称库") from app.services.llm_service import llm_service print(" ✓ LLM服务") from app.agent.enhanced_agent import enhanced_agent print(" ✓ 增强版Agent") print("\n所有模块导入成功!") except Exception as e: print(f"\n❌ 导入失败: {e}") import traceback traceback.print_exc() exit(1) EOF if [ $? -ne 0 ]; then echo "" echo "模块导入失败,请检查错误信息" exit 1 fi # 检查配置 echo "" echo "2. 检查配置..." python3 << 'EOF' from app.config import get_settings settings = get_settings() print(f" Tushare Token: {'✓ 已配置' if settings.tushare_token else '❌ 未配置'}") print(f" 智谱AI Key: {'✓ 已配置' if settings.zhipuai_api_key else '❌ 未配置'}") print(f" 数据库: {settings.database_url}") print(f" 监听: {settings.api_host}:{settings.api_port}") if not settings.tushare_token: print("\n⚠️ 警告: Tushare Token未配置,数据查询功能将不可用") if not settings.zhipuai_api_key: print("⚠️ 警告: 智谱AI Key未配置,将使用规则模式(无AI分析)") EOF echo "" echo "3. 测试股票名称识别..." python3 << 'EOF' from app.utils.stock_names import search_stock_by_name test_cases = [ ("中国卫通", "601698"), ("贵州茅台", "600519"), ("比亚迪", "002594"), ("宁德时代", "300750") ] for name, expected in test_cases: result = search_stock_by_name(name) status = "✓" if result == expected else "❌" print(f" {status} {name} -> {result}") EOF echo "" echo "================================" echo "检查完成!准备启动..." echo "================================" echo "" echo "访问地址:" echo " 前端: http://localhost:8000" echo " API: http://localhost:8000/docs" echo "" echo "按 Ctrl+C 停止服务" echo "" # 启动应用 python3 -m app.main