Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,4 @@
|
|
1 |
-
|
2 |
-
@app.on_event("startup")
|
3 |
-
async def startup_event():
|
4 |
-
"""服务启动时初始化"""
|
5 |
-
logger.info(f"OpenAI API代理服务已启动,可以接受请求")
|
6 |
-
logger.info(f"支持多token轮询,请在Authorization头中使用英文逗号分隔多个token")
|
7 |
-
logger.info(f"服务地址: http://127.0.0.1:7860")
|
8 |
-
logger.info(f"OpenAI API格式请求示例: POST http://127.0.0.1:7860/v1/chat/completions")
|
9 |
-
logger.info(f"可用模型查询: GET http://127.0.0.1:7860/v1/models")import json
|
10 |
import time
|
11 |
import asyncio
|
12 |
import uvicorn
|
@@ -128,7 +120,7 @@ async def check_account_balance(api_key, token_index=None):
|
|
128 |
try:
|
129 |
# 获取账户余额信息
|
130 |
response = requests.get(
|
131 |
-
f"{DEEPSIDER_API_BASE.replace('/
|
132 |
headers=headers
|
133 |
)
|
134 |
|
@@ -402,6 +394,13 @@ async def get_account_balance(request: Request, admin_key: str = Header(None, al
|
|
402 |
|
403 |
return result
|
404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
# 错误处理器
|
406 |
@app.exception_handler(404)
|
407 |
async def not_found_handler(request, exc):
|
|
|
1 |
+
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import time
|
3 |
import asyncio
|
4 |
import uvicorn
|
|
|
120 |
try:
|
121 |
# 获取账户余额信息
|
122 |
response = requests.get(
|
123 |
+
f"{DEEPSIDER_API_BASE.replace('/v1', '')}/quota/retrieve",
|
124 |
headers=headers
|
125 |
)
|
126 |
|
|
|
394 |
|
395 |
return result
|
396 |
|
397 |
+
# 模拟模型的路由
|
398 |
+
@app.get("/v1/engines")
|
399 |
+
@app.get("/v1/engines/{engine_id}")
|
400 |
+
async def engines_handler():
|
401 |
+
"""兼容旧的引擎API"""
|
402 |
+
raise HTTPException(status_code=404, detail="引擎API已被弃用 请使用模型API")
|
403 |
+
|
404 |
# 错误处理器
|
405 |
@app.exception_handler(404)
|
406 |
async def not_found_handler(request, exc):
|