fix(proxy_server.py): drop none values in streaming response

This commit is contained in:
Krrish Dholakia 2024-02-27 14:37:29 -08:00
parent 05e096ce25
commit 57998c28dc
2 changed files with 15 additions and 11 deletions

View file

@ -2115,10 +2115,9 @@ async def async_data_generator(response, user_api_key_dict):
try:
start_time = time.time()
async for chunk in response:
verbose_proxy_logger.debug(f"returned chunk: {chunk}")
assert isinstance(chunk, litellm.ModelResponse)
chunk = chunk.model_dump_json(exclude_none=True)
try:
yield f"data: {json.dumps(chunk.model_dump(exclude_none=True))}\n\n"
yield f"data: {chunk}\n\n"
except Exception as e:
yield f"data: {str(e)}\n\n"