From 6f66376bb8a4116330fe867d9dff83f938f7aa14 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Thu, 26 Oct 2023 12:02:15 -0700 Subject: [PATCH] AutoGPT: require function call if only 1 function is given --- .../autogpt/autogpt/core/resource/model_providers/openai.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autogpts/autogpt/autogpt/core/resource/model_providers/openai.py b/autogpts/autogpt/autogpt/core/resource/model_providers/openai.py index 37a672ea..4167b7c1 100644 --- a/autogpts/autogpt/autogpt/core/resource/model_providers/openai.py +++ b/autogpts/autogpt/autogpt/core/resource/model_providers/openai.py @@ -347,6 +347,9 @@ class OpenAIProvider( if functions: if OPEN_AI_CHAT_MODELS[model_name].has_function_call_api: completion_kwargs["functions"] = [f.schema for f in functions] + if len(functions) == 1: + # force the model to call the only specified function + completion_kwargs["function_call"] = {"name": functions[0].name} else: # Provide compatibility with older models _functions_compat_fix_kwargs(functions, completion_kwargs)