fix(factory.py): handle missing 'content' in cohere assistant messages

Update cohere_messages_pt_v2 function to check for 'content' existence
This commit is contained in:
miraclebakelaser 2024-08-27 19:38:37 +09:00
parent 3ec8a0d25d
commit 97f714d2b0

View file

@ -1781,7 +1781,7 @@ def cohere_messages_pt_v2(
assistant_tool_calls: List[ToolCallObject] = [] assistant_tool_calls: List[ToolCallObject] = []
## MERGE CONSECUTIVE ASSISTANT CONTENT ## ## MERGE CONSECUTIVE ASSISTANT CONTENT ##
while msg_i < len(messages) and messages[msg_i]["role"] == "assistant": while msg_i < len(messages) and messages[msg_i]["role"] == "assistant":
if isinstance(messages[msg_i]["content"], list): if messages[msg_i].get("content", None) is not None and isinstance(messages[msg_i]["content"], list):
for m in messages[msg_i]["content"]: for m in messages[msg_i]["content"]:
if m.get("type", "") == "text": if m.get("type", "") == "text":
assistant_content += m["text"] assistant_content += m["text"]