fix(utils.py): handle api assistant returning 'null' role

Fixes https://github.com/BerriAI/litellm/issues/3621
This commit is contained in:
Krrish Dholakia 2024-05-13 16:45:12 -07:00
parent 8c37c47c8d
commit 240c9550f0
3 changed files with 47 additions and 1 deletions

View file

@ -7709,7 +7709,7 @@ def convert_to_model_response_object(
for idx, choice in enumerate(response_object["choices"]):
message = Message(
content=choice["message"].get("content", None),
role=choice["message"]["role"],
role=choice["message"]["role"] or "assistant",
function_call=choice["message"].get("function_call", None),
tool_calls=choice["message"].get("tool_calls", None),
)