Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

AutoGPT: require function call if only 1 function is given

Reinier van der Leer6f66376bb8a4
diff --git a/autogpts/autogpt/autogpt/core/resource/model_providers/openai.py b/autogpts/autogpt/autogpt/core/resource/model_providers/openai.py
index 37a672ea97..4167b7c19e 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)