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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cohere_chat.py): handle tool_result + user message being passed in
Krrish Dholakia259e3b124512
diff --git a/litellm/llms/cohere_chat.py b/litellm/llms/cohere_chat.pyindex 9321d6f8b3c..a0a9a987492 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.pyindex 99b3f97e1de..191eb33921d 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)