Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(factory.py): handle assistant null content

Krrish Dholakia6333b04be3a6
diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py
index f39273c1a2f..4e552b3b078 100644
--- a/litellm/llms/prompt_templates/factory.py
+++ b/litellm/llms/prompt_templates/factory.py
@@ -1705,7 +1705,9 @@ def cohere_messages_pt_v2(
for m in messages[msg_i]["content"]:
if m.get("type", "") == "text":
assistant_content += m["text"]
- else:
+ elif messages[msg_i].get("content") is not None and isinstance(
+ messages[msg_i]["content"], str
+ ):
assistant_content += messages[msg_i]["content"]
if messages[msg_i].get(
"tool_calls", []