Spaces:
Running
Running
fix: 移除app.py中的直接模型加载代码
Browse files- 删除旧的测试代码中的直接模型实例化
- 模型加载现在通过TravelAssistant类管理
- 修复启动时的认证错误
app.py
CHANGED
|
@@ -1,45 +1,39 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
import
|
| 4 |
-
import
|
| 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 |
-
decoded = processor.decode(generation, skip_special_tokens=True)
|
| 41 |
-
print(decoded)
|
| 42 |
-
|
| 43 |
-
# **Overall Impression:** The image is a close-up shot of a vibrant garden scene,
|
| 44 |
-
# focusing on a cluster of pink cosmos flowers and a busy bumblebee.
|
| 45 |
-
# It has a slightly soft, natural feel, likely captured in daylight.
|
|
|
|
| 1 |
+
# app.py - 正确的版本
|
| 2 |
+
from fastapi import FastAPI, HTTPException
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from fastapi.responses import JSONResponse
|
| 5 |
+
from utils.validators import ChatRequest, ChatResponse
|
| 6 |
+
from utils.logger import log
|
| 7 |
+
from modules.travel_assistant import TravelAssistant
|
| 8 |
+
import traceback
|
| 9 |
+
|
| 10 |
+
# --- FastAPI 应用设置 ---
|
| 11 |
+
app = FastAPI(
|
| 12 |
+
title="Modular Travel Assistant API",
|
| 13 |
+
description="一个采用模块化和分层架构的旅行助手API",
|
| 14 |
+
version="2.0.0",
|
| 15 |
+
docs_url="/docs",
|
| 16 |
+
redoc_url="/redoc"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
app.add_middleware(
|
| 20 |
+
CORSMiddleware,
|
| 21 |
+
allow_origins=["*"],
|
| 22 |
+
allow_credentials=True,
|
| 23 |
+
allow_methods=["*"],
|
| 24 |
+
allow_headers=["*"],
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# --- 全局服务实例 ---
|
| 28 |
+
try:
|
| 29 |
+
log.info("🔄 开始初始化 Travel Assistant 服务...")
|
| 30 |
+
assistant = TravelAssistant() # 这里才是正确的模型加载方式
|
| 31 |
+
SERVICE_READY = True
|
| 32 |
+
log.info("🚀 FastAPI 应用启动成功,服务已就绪。")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
assistant = None
|
| 35 |
+
SERVICE_READY = False
|
| 36 |
+
log.critical(f"💥 FATAL: 服务初始化失败: {e}")
|
| 37 |
+
log.critical(f"💥 错误详情: {traceback.format_exc()}")
|
| 38 |
+
|
| 39 |
+
# ... 其余的API端点代码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|