Merge pull request #5773 from HaldiH/main

fix: Chat completion 401 when no Authorization header
This commit is contained in:
Timothy Jaeryang Baek 2024-09-27 21:34:58 +02:00 committed by GitHub
commit 6e9db3e3c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 4 deletions

View File

@ -761,10 +761,22 @@ class PipelineMiddleware(BaseHTTPMiddleware):
# Parse string to JSON # Parse string to JSON
data = json.loads(body_str) if body_str else {} data = json.loads(body_str) if body_str else {}
try:
user = get_current_user( user = get_current_user(
request, request,
get_http_authorization_cred(request.headers["Authorization"]), get_http_authorization_cred(request.headers["Authorization"]),
) )
except KeyError as e:
if len(e.args) > 1:
return JSONResponse(
status_code=e.args[0],
content={"detail": e.args[1]},
)
else:
return JSONResponse(
status_code=status.HTTP_401_UNAUTHORIZED,
content={"detail": "Not authenticated"},
)
try: try:
data = filter_pipeline(data, user) data = filter_pipeline(data, user)