diff --git a/litellm/llms/cohere_chat.py b/litellm/llms/cohere_chat.py index 9321d6f8b..a0a9a9874 100644 --- a/litellm/llms/cohere_chat.py +++ b/litellm/llms/cohere_chat.py @@ -233,6 +233,11 @@ def completion( optional_params["tool_results"] = [most_recent_message] elif isinstance(most_recent_message, str): optional_params["message"] = most_recent_message + + ## check if chat history message is 'user' and 'tool_results' is given -> force_single_step=True, else cohere api fails + if len(chat_history) > 0 and chat_history[-1]["role"] == "USER": + optional_params["force_single_step"] = True + data = { "model": model, "chat_history": chat_history, diff --git a/litellm/llms/prompt_templates/factory.py b/litellm/llms/prompt_templates/factory.py index 99b3f97e1..191eb3392 100644 --- a/litellm/llms/prompt_templates/factory.py +++ b/litellm/llms/prompt_templates/factory.py @@ -1632,6 +1632,7 @@ def cohere_messages_pt_v2( Note: - cannot specify message if the last entry in chat history contains tool results - message must be at least 1 token long or tool results must be specified. + - cannot specify tool_results if the last entry in chat history contains a user message """ tool_calls: List = get_all_tool_calls(messages=messages)