fix(cohere_chat.py): handle tool_result + user message being passed in

This commit is contained in:
Krrish Dholakia 2024-07-29 21:38:21 -07:00
parent 6f34998cab
commit 259e3b1245
2 changed files with 6 additions and 0 deletions

View file

@ -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,

View file

@ -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)