From 36b7dbb8d0cb3b05eea3b07ddd7306ecbf823806 Mon Sep 17 00:00:00 2001 From: takatost Date: Thu, 11 Apr 2024 21:32:18 +0800 Subject: [PATCH] fix: cohere tool call does not support single tool (#3373) --- api/core/model_runtime/model_providers/cohere/llm/llm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/core/model_runtime/model_providers/cohere/llm/llm.py b/api/core/model_runtime/model_providers/cohere/llm/llm.py index 186afddafc..cc8e5b0eae 100644 --- a/api/core/model_runtime/model_providers/cohere/llm/llm.py +++ b/api/core/model_runtime/model_providers/cohere/llm/llm.py @@ -323,6 +323,9 @@ class CohereLargeLanguageModel(LargeLanguageModel): model_parameters['stop_sequences'] = stop if tools: + if len(tools) == 1: + raise ValueError("Cohere tool call requires at least two tools to be specified.") + model_parameters['tools'] = self._convert_tools(tools) message, chat_histories, tool_results \ @@ -476,8 +479,6 @@ class CohereLargeLanguageModel(LargeLanguageModel): index += 1 elif isinstance(chunk, StreamedChatResponse_ToolCallsGeneration): chunk = cast(StreamedChatResponse_ToolCallsGeneration, chunk) - - tool_calls = [] if chunk.tool_calls: for cohere_tool_call in chunk.tool_calls: tool_call = AssistantPromptMessage.ToolCall(