resolve conflicts
Browse files
main.py
CHANGED
@@ -1215,15 +1215,19 @@ def verify_admin_api_key(credentials: HTTPAuthorizationCredentials = Depends(sec
|
|
1215 |
raise HTTPException(status_code=403, detail="Permission denied")
|
1216 |
return token
|
1217 |
|
1218 |
-
|
|
|
|
|
|
|
|
|
1219 |
async def request_model(request: RequestModel, api_index: int = Depends(verify_api_key)):
|
1220 |
return await model_handler.request_model(request, api_index)
|
1221 |
|
1222 |
-
@
|
1223 |
async def options_handler():
|
1224 |
return JSONResponse(status_code=200, content={"detail": "OPTIONS allowed"})
|
1225 |
|
1226 |
-
@
|
1227 |
async def list_models(api_index: int = Depends(verify_api_key)):
|
1228 |
models = post_all_models(api_index, app.state.config)
|
1229 |
return JSONResponse(content={
|
@@ -1231,28 +1235,28 @@ async def list_models(api_index: int = Depends(verify_api_key)):
|
|
1231 |
"data": models
|
1232 |
})
|
1233 |
|
1234 |
-
@
|
1235 |
async def images_generations(
|
1236 |
request: ImageGenerationRequest,
|
1237 |
api_index: int = Depends(verify_api_key)
|
1238 |
):
|
1239 |
return await model_handler.request_model(request, api_index, endpoint="/v1/images/generations")
|
1240 |
|
1241 |
-
@
|
1242 |
async def embeddings(
|
1243 |
request: EmbeddingRequest,
|
1244 |
api_index: int = Depends(verify_api_key)
|
1245 |
):
|
1246 |
return await model_handler.request_model(request, api_index, endpoint="/v1/embeddings")
|
1247 |
|
1248 |
-
@
|
1249 |
async def audio_speech(
|
1250 |
request: TextToSpeechRequest,
|
1251 |
api_index: str = Depends(verify_api_key)
|
1252 |
):
|
1253 |
return await model_handler.request_model(request, api_index, endpoint="/v1/audio/speech")
|
1254 |
|
1255 |
-
@
|
1256 |
async def moderations(
|
1257 |
request: ModerationRequest,
|
1258 |
api_index: int = Depends(verify_api_key)
|
@@ -1261,7 +1265,7 @@ async def moderations(
|
|
1261 |
|
1262 |
from fastapi import UploadFile, File, Form, HTTPException
|
1263 |
import io
|
1264 |
-
@
|
1265 |
async def audio_transcriptions(
|
1266 |
file: UploadFile = File(...),
|
1267 |
model: str = Form(...),
|
@@ -1287,7 +1291,7 @@ async def audio_transcriptions(
|
|
1287 |
traceback.print_exc()
|
1288 |
raise HTTPException(status_code=500, detail=f"Error processing audio file: {str(e)}")
|
1289 |
|
1290 |
-
@
|
1291 |
def generate_api_key():
|
1292 |
# Define the character set (only alphanumeric)
|
1293 |
chars = string.ascii_letters + string.digits
|
@@ -1301,7 +1305,7 @@ from datetime import datetime, timedelta, timezone
|
|
1301 |
from sqlalchemy import func, desc, case
|
1302 |
from fastapi import Query
|
1303 |
|
1304 |
-
@
|
1305 |
async def get_stats(
|
1306 |
request: Request,
|
1307 |
token: str = Depends(verify_admin_api_key),
|
@@ -2070,6 +2074,8 @@ async def delete_row(row_id: str):
|
|
2070 |
|
2071 |
return await root()
|
2072 |
|
|
|
|
|
2073 |
app.include_router(frontend_router, tags=["frontend"])
|
2074 |
|
2075 |
# async def on_fetch(request, env):
|
|
|
1215 |
raise HTTPException(status_code=403, detail="Permission denied")
|
1216 |
return token
|
1217 |
|
1218 |
+
# 创建一个新的路由器并设置前缀
|
1219 |
+
v1_router = APIRouter(prefix="/api")
|
1220 |
+
|
1221 |
+
# 将现有的 /v1 路由移动到新路由器
|
1222 |
+
@v1_router.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
1223 |
async def request_model(request: RequestModel, api_index: int = Depends(verify_api_key)):
|
1224 |
return await model_handler.request_model(request, api_index)
|
1225 |
|
1226 |
+
@v1_router.options("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
1227 |
async def options_handler():
|
1228 |
return JSONResponse(status_code=200, content={"detail": "OPTIONS allowed"})
|
1229 |
|
1230 |
+
@v1_router.get("/v1/models", dependencies=[Depends(rate_limit_dependency)])
|
1231 |
async def list_models(api_index: int = Depends(verify_api_key)):
|
1232 |
models = post_all_models(api_index, app.state.config)
|
1233 |
return JSONResponse(content={
|
|
|
1235 |
"data": models
|
1236 |
})
|
1237 |
|
1238 |
+
@v1_router.post("/v1/images/generations", dependencies=[Depends(rate_limit_dependency)])
|
1239 |
async def images_generations(
|
1240 |
request: ImageGenerationRequest,
|
1241 |
api_index: int = Depends(verify_api_key)
|
1242 |
):
|
1243 |
return await model_handler.request_model(request, api_index, endpoint="/v1/images/generations")
|
1244 |
|
1245 |
+
@v1_router.post("/v1/embeddings", dependencies=[Depends(rate_limit_dependency)])
|
1246 |
async def embeddings(
|
1247 |
request: EmbeddingRequest,
|
1248 |
api_index: int = Depends(verify_api_key)
|
1249 |
):
|
1250 |
return await model_handler.request_model(request, api_index, endpoint="/v1/embeddings")
|
1251 |
|
1252 |
+
@v1_router.post("/v1/audio/speech", dependencies=[Depends(rate_limit_dependency)])
|
1253 |
async def audio_speech(
|
1254 |
request: TextToSpeechRequest,
|
1255 |
api_index: str = Depends(verify_api_key)
|
1256 |
):
|
1257 |
return await model_handler.request_model(request, api_index, endpoint="/v1/audio/speech")
|
1258 |
|
1259 |
+
@v1_router.post("/v1/moderations", dependencies=[Depends(rate_limit_dependency)])
|
1260 |
async def moderations(
|
1261 |
request: ModerationRequest,
|
1262 |
api_index: int = Depends(verify_api_key)
|
|
|
1265 |
|
1266 |
from fastapi import UploadFile, File, Form, HTTPException
|
1267 |
import io
|
1268 |
+
@v1_router.post("/v1/audio/transcriptions", dependencies=[Depends(rate_limit_dependency)])
|
1269 |
async def audio_transcriptions(
|
1270 |
file: UploadFile = File(...),
|
1271 |
model: str = Form(...),
|
|
|
1291 |
traceback.print_exc()
|
1292 |
raise HTTPException(status_code=500, detail=f"Error processing audio file: {str(e)}")
|
1293 |
|
1294 |
+
@v1_router.get("/v1/generate-api-key", dependencies=[Depends(rate_limit_dependency)])
|
1295 |
def generate_api_key():
|
1296 |
# Define the character set (only alphanumeric)
|
1297 |
chars = string.ascii_letters + string.digits
|
|
|
1305 |
from sqlalchemy import func, desc, case
|
1306 |
from fastapi import Query
|
1307 |
|
1308 |
+
@v1_router.get("/v1/stats", dependencies=[Depends(rate_limit_dependency)])
|
1309 |
async def get_stats(
|
1310 |
request: Request,
|
1311 |
token: str = Depends(verify_admin_api_key),
|
|
|
2074 |
|
2075 |
return await root()
|
2076 |
|
2077 |
+
# 在文件末尾添加路由器到应用
|
2078 |
+
app.include_router(v1_router, tags=["v1"])
|
2079 |
app.include_router(frontend_router, tags=["frontend"])
|
2080 |
|
2081 |
# async def on_fetch(request, env):
|