mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
fix _read_request_body (#7706)
This commit is contained in:
parent
71e679246a
commit
7923cb1a64
1 changed files with 3 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
|
import orjson
|
||||||
from fastapi import Request, UploadFile, status
|
from fastapi import Request, UploadFile, status
|
||||||
|
|
||||||
from litellm._logging import verbose_proxy_logger
|
from litellm._logging import verbose_proxy_logger
|
||||||
|
@ -32,13 +33,10 @@ async def _read_request_body(request: Optional[Request]) -> Dict:
|
||||||
if not body:
|
if not body:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
# Decode the body to a string
|
|
||||||
body_str = body.decode()
|
|
||||||
|
|
||||||
# Attempt JSON parsing (safe for untrusted input)
|
# Attempt JSON parsing (safe for untrusted input)
|
||||||
return json.loads(body_str)
|
return orjson.loads(body)
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
except (json.JSONDecodeError, orjson.JSONDecodeError):
|
||||||
# Log detailed information for debugging
|
# Log detailed information for debugging
|
||||||
verbose_proxy_logger.exception("Invalid JSON payload received.")
|
verbose_proxy_logger.exception("Invalid JSON payload received.")
|
||||||
return {}
|
return {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue