-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (65 loc) · 1.77 KB
/
main.py
File metadata and controls
80 lines (65 loc) · 1.77 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
Deep Think API 主应用
FastAPI 应用程序入口
"""
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
from config import config
from api.v1 import chat, models
# 配置日志
logging.basicConfig(
level=getattr(logging, config.log_level),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""应用生命周期管理"""
logger.info("Starting Deep Think API...")
logger.info(f"Loaded {len(config.list_models())} models")
yield
logger.info("Shutting down Deep Think API...")
# 创建 FastAPI 应用
app = FastAPI(
title="Deep Think API",
description="OpenAI-compatible API with DeepThink and UltraThink reasoning engines",
version="1.0.0",
lifespan=lifespan,
)
# 配置 CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 注册路由
app.include_router(chat.router, tags=["Chat"])
app.include_router(models.router, tags=["Models"])
@app.get("/")
async def root():
"""根端点"""
return {
"name": "Deep Think API",
"version": "1.0.0",
"description": "OpenAI-compatible API with DeepThink and UltraThink reasoning engines",
"endpoints": {
"chat": "/v1/chat/completions",
"models": "/v1/models",
}
}
@app.get("/health")
async def health():
"""健康检查"""
return {"status": "healthy"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host=config.host,
port=config.port,
log_level=config.log_level.lower(),
)