Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,13 +59,14 @@ def get_model(model_name: str):
|
|
| 59 |
return models[model_name]
|
| 60 |
|
| 61 |
# 验证API密钥
|
| 62 |
-
def verify_api_key(
|
| 63 |
logger.info("验证API密钥")
|
| 64 |
-
logger.info(f"
|
| 65 |
-
if not
|
| 66 |
logger.warning("未提供有效的API密钥格式")
|
| 67 |
raise HTTPException(status_code=401, detail="未提供有效的API密钥")
|
| 68 |
-
|
|
|
|
| 69 |
logger.warning("无效的API密钥")
|
| 70 |
raise HTTPException(status_code=401, detail="无效的API密钥")
|
| 71 |
logger.info("API密钥验证通过")
|
|
@@ -89,7 +90,7 @@ class EmbeddingResponse(BaseModel):
|
|
| 89 |
model: str
|
| 90 |
usage: dict = {"prompt_tokens": 0, "total_tokens": 0}
|
| 91 |
|
| 92 |
-
@app.post("/embeddings", response_model=EmbeddingResponse)
|
| 93 |
async def create_embedding(
|
| 94 |
request: Request, # 接收Request对象
|
| 95 |
req: EmbeddingRequest,
|
|
@@ -135,7 +136,7 @@ async def create_embedding(
|
|
| 135 |
raise HTTPException(status_code=500, detail=error_msg)
|
| 136 |
|
| 137 |
# 健康检查接口也打印完整请求
|
| 138 |
-
@app.post("/
|
| 139 |
async def v1_check(request: Request):
|
| 140 |
logger.info("\n===== v1请求信息 =====")
|
| 141 |
logger.info(f"请求方法: {request.method}")
|
|
@@ -146,7 +147,7 @@ async def v1_check(request: Request):
|
|
| 146 |
logger.info("===============================\n")
|
| 147 |
return {"status": "healthy", "models": list(MODEL_MAPPING.keys())}
|
| 148 |
|
| 149 |
-
@app.get("/")
|
| 150 |
async def health_check(request: Request):
|
| 151 |
logger.info("\n===== 健康检查请求信息 =====")
|
| 152 |
logger.info(f"请求方法: {request.method}")
|
|
|
|
| 59 |
return models[model_name]
|
| 60 |
|
| 61 |
# 验证API密钥
|
| 62 |
+
def verify_api_key(authorization: Optional[str] = None):
|
| 63 |
logger.info("验证API密钥")
|
| 64 |
+
logger.info(f"Authorization头部内容: {authorization}")
|
| 65 |
+
if not authorization or not authorization.startswith("Bearer "):
|
| 66 |
logger.warning("未提供有效的API密钥格式")
|
| 67 |
raise HTTPException(status_code=401, detail="未提供有效的API密钥")
|
| 68 |
+
api_key = authorization[len("Bearer "):]
|
| 69 |
+
if api_key != os.getenv("API_KEY"):
|
| 70 |
logger.warning("无效的API密钥")
|
| 71 |
raise HTTPException(status_code=401, detail="无效的API密钥")
|
| 72 |
logger.info("API密钥验证通过")
|
|
|
|
| 90 |
model: str
|
| 91 |
usage: dict = {"prompt_tokens": 0, "total_tokens": 0}
|
| 92 |
|
| 93 |
+
@app.post("/v1/embeddings", response_model=EmbeddingResponse)
|
| 94 |
async def create_embedding(
|
| 95 |
request: Request, # 接收Request对象
|
| 96 |
req: EmbeddingRequest,
|
|
|
|
| 136 |
raise HTTPException(status_code=500, detail=error_msg)
|
| 137 |
|
| 138 |
# 健康检查接口也打印完整请求
|
| 139 |
+
@app.post("/embeddings")
|
| 140 |
async def v1_check(request: Request):
|
| 141 |
logger.info("\n===== v1请求信息 =====")
|
| 142 |
logger.info(f"请求方法: {request.method}")
|
|
|
|
| 147 |
logger.info("===============================\n")
|
| 148 |
return {"status": "healthy", "models": list(MODEL_MAPPING.keys())}
|
| 149 |
|
| 150 |
+
@app.get("/health")
|
| 151 |
async def health_check(request: Request):
|
| 152 |
logger.info("\n===== 健康检查请求信息 =====")
|
| 153 |
logger.info(f"请求方法: {request.method}")
|