-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun_api.py
More file actions
65 lines (56 loc) · 2.05 KB
/
Copy pathrun_api.py
File metadata and controls
65 lines (56 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
启动多智能体研究系统 Web API 服务器
访问 http://localhost:8000 使用 Web UI
访问 http://localhost:8000/docs 查看 API 文档
"""
import os
import sys
# Windows GBK 控制台 emoji 兼容
import io
try:
if hasattr(sys.stdout, 'buffer'):
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace', line_buffering=True)
if hasattr(sys.stderr, 'buffer'):
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace', line_buffering=True)
except Exception:
pass
# 添加项目根目录到路径
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, ROOT_DIR)
# 检查环境变量
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("ZHIPU_API_KEY", "")
if not api_key:
print("❌ 错误:请设置 ZHIPU_API_KEY 环境变量")
print(" 在 .env 文件中添加:ZHIPU_API_KEY=your_key")
sys.exit(1)
# 检查依赖
try:
import fastapi
import uvicorn
except ImportError:
print("❌ 缺少依赖,请运行:")
print(" pip install fastapi uvicorn[standard] sse-starlette aiofiles")
sys.exit(1)
if __name__ == "__main__":
import uvicorn
host = os.getenv("API_HOST", "0.0.0.0")
port = int(os.getenv("API_PORT", "8000"))
print(f"""
╔══════════════════════════════════════════╗
║ 多智能体研究系统 v2.0 启动中 ║
╠══════════════════════════════════════════╣
║ Web UI: http://localhost:{port} ║
║ API 文档: http://localhost:{port}/docs ║
║ 健康检查: http://localhost:{port}/api/health ║
╚══════════════════════════════════════════╝
""")
uvicorn.run(
"api.app:app",
host=host,
port=port,
reload=False,
log_level="info",
access_log=True
)