sanbo commited on
Commit ·
f090454
1
Parent(s): 1cb2206
update sth at 2025-10-09 16:50:51
Browse files- Dockerfile +12 -0
- app/core/openai.py +5 -5
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY .. .
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["python", "main.py"]
|
app/core/openai.py
CHANGED
|
@@ -92,7 +92,7 @@ async def handle_non_stream_response(stream_response, request: OpenAIRequest) ->
|
|
| 92 |
return JSONResponse(content=response_data.model_dump(exclude_none=True))
|
| 93 |
|
| 94 |
|
| 95 |
-
@router.get("/v1/models")
|
| 96 |
async def list_models():
|
| 97 |
"""List available models from all providers"""
|
| 98 |
try:
|
|
@@ -114,7 +114,7 @@ async def list_models():
|
|
| 114 |
return fallback_response
|
| 115 |
|
| 116 |
|
| 117 |
-
@router.post("/v1/chat/completions")
|
| 118 |
async def chat_completions(request: OpenAIRequest, authorization: str = Header(...)):
|
| 119 |
"""Handle chat completion requests with multi-provider architecture"""
|
| 120 |
role = request.messages[0].role if request.messages else "unknown"
|
|
@@ -178,7 +178,7 @@ async def chat_completions(request: OpenAIRequest, authorization: str = Header(.
|
|
| 178 |
# Token pool management endpoints
|
| 179 |
|
| 180 |
|
| 181 |
-
@router.get("/v1/token-pool/status")
|
| 182 |
async def get_token_pool_status():
|
| 183 |
"""获取token池状态信息"""
|
| 184 |
try:
|
|
@@ -208,7 +208,7 @@ async def get_token_pool_status():
|
|
| 208 |
raise HTTPException(status_code=500, detail=f"Failed to get token pool status: {str(e)}")
|
| 209 |
|
| 210 |
|
| 211 |
-
@router.post("/v1/token-pool/health-check")
|
| 212 |
async def trigger_health_check():
|
| 213 |
"""手动触发token池健康检查"""
|
| 214 |
try:
|
|
@@ -245,7 +245,7 @@ async def trigger_health_check():
|
|
| 245 |
raise HTTPException(status_code=500, detail=f"Health check failed: {str(e)}")
|
| 246 |
|
| 247 |
|
| 248 |
-
@router.post("/v1/token-pool/update")
|
| 249 |
async def update_token_pool_endpoint(tokens: List[str]):
|
| 250 |
"""动态更新token池"""
|
| 251 |
try:
|
|
|
|
| 92 |
return JSONResponse(content=response_data.model_dump(exclude_none=True))
|
| 93 |
|
| 94 |
|
| 95 |
+
@router.get("/api/v1/models")
|
| 96 |
async def list_models():
|
| 97 |
"""List available models from all providers"""
|
| 98 |
try:
|
|
|
|
| 114 |
return fallback_response
|
| 115 |
|
| 116 |
|
| 117 |
+
@router.post("/api/v1/chat/completions")
|
| 118 |
async def chat_completions(request: OpenAIRequest, authorization: str = Header(...)):
|
| 119 |
"""Handle chat completion requests with multi-provider architecture"""
|
| 120 |
role = request.messages[0].role if request.messages else "unknown"
|
|
|
|
| 178 |
# Token pool management endpoints
|
| 179 |
|
| 180 |
|
| 181 |
+
@router.get("/api/v1/token-pool/status")
|
| 182 |
async def get_token_pool_status():
|
| 183 |
"""获取token池状态信息"""
|
| 184 |
try:
|
|
|
|
| 208 |
raise HTTPException(status_code=500, detail=f"Failed to get token pool status: {str(e)}")
|
| 209 |
|
| 210 |
|
| 211 |
+
@router.post("/api/v1/token-pool/health-check")
|
| 212 |
async def trigger_health_check():
|
| 213 |
"""手动触发token池健康检查"""
|
| 214 |
try:
|
|
|
|
| 245 |
raise HTTPException(status_code=500, detail=f"Health check failed: {str(e)}")
|
| 246 |
|
| 247 |
|
| 248 |
+
@router.post("/api/v1/token-pool/update")
|
| 249 |
async def update_token_pool_endpoint(tokens: List[str]):
|
| 250 |
"""动态更新token池"""
|
| 251 |
try:
|