Spaces:
Paused
Paused
Update api/utils.py
Browse files- api/utils.py +4 -5
api/utils.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
from datetime import datetime
|
| 2 |
-
from http.client import HTTPException
|
| 3 |
import json
|
| 4 |
from typing import Any, Dict, Optional
|
| 5 |
import uuid
|
|
@@ -7,7 +6,7 @@ import uuid
|
|
| 7 |
import httpx
|
| 8 |
from api import validate
|
| 9 |
from api.config import MODEL_MAPPING, headers
|
| 10 |
-
from fastapi import Depends, security
|
| 11 |
from fastapi.security import HTTPAuthorizationCredentials
|
| 12 |
|
| 13 |
from api.config import APP_SECRET, BASE_URL
|
|
@@ -39,7 +38,7 @@ def create_chat_completion_data(
|
|
| 39 |
|
| 40 |
def verify_app_secret(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
| 41 |
if credentials.credentials != APP_SECRET:
|
| 42 |
-
raise HTTPException(403, "Invalid APP_SECRET")
|
| 43 |
return credentials.credentials
|
| 44 |
|
| 45 |
|
|
@@ -123,10 +122,10 @@ async def process_streaming_response(request: ChatRequest):
|
|
| 123 |
yield "data: [DONE]\n\n"
|
| 124 |
except httpx.HTTPStatusError as e:
|
| 125 |
logger.error(f"HTTP error occurred: {e}")
|
| 126 |
-
raise HTTPException(e.response.status_code, str(e))
|
| 127 |
except httpx.RequestError as e:
|
| 128 |
logger.error(f"Error occurred during request: {e}")
|
| 129 |
-
raise HTTPException(500, str(e))
|
| 130 |
|
| 131 |
|
| 132 |
async def process_non_streaming_response(request: ChatRequest):
|
|
|
|
| 1 |
from datetime import datetime
|
|
|
|
| 2 |
import json
|
| 3 |
from typing import Any, Dict, Optional
|
| 4 |
import uuid
|
|
|
|
| 6 |
import httpx
|
| 7 |
from api import validate
|
| 8 |
from api.config import MODEL_MAPPING, headers
|
| 9 |
+
from fastapi import Depends, security, HTTPException
|
| 10 |
from fastapi.security import HTTPAuthorizationCredentials
|
| 11 |
|
| 12 |
from api.config import APP_SECRET, BASE_URL
|
|
|
|
| 38 |
|
| 39 |
def verify_app_secret(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
| 40 |
if credentials.credentials != APP_SECRET:
|
| 41 |
+
raise HTTPException(status_code=403, detail="Invalid APP_SECRET")
|
| 42 |
return credentials.credentials
|
| 43 |
|
| 44 |
|
|
|
|
| 122 |
yield "data: [DONE]\n\n"
|
| 123 |
except httpx.HTTPStatusError as e:
|
| 124 |
logger.error(f"HTTP error occurred: {e}")
|
| 125 |
+
raise HTTPException(status_code=e.response.status_code, detail=str(e))
|
| 126 |
except httpx.RequestError as e:
|
| 127 |
logger.error(f"Error occurred during request: {e}")
|
| 128 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 129 |
|
| 130 |
|
| 131 |
async def process_non_streaming_response(request: ChatRequest):
|