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.

Add fallback token limit in llm.utils.create_chat_completion (#4839)

Luke975094fcdd13
diff --git a/autogpt/llm/utils/__init__.py b/autogpt/llm/utils/__init__.py
index 4176531442..1d4f4f97e9 100644
--- a/autogpt/llm/utils/__init__.py
+++ b/autogpt/llm/utils/__init__.py
@@ -115,6 +115,8 @@ def create_chat_completion(
model = prompt.model.name
if temperature is None:
temperature = config.temperature
+ if max_tokens is None:
+ max_tokens = OPEN_AI_CHAT_MODELS[model].max_tokens - prompt.token_length
logger.debug(
f"{Fore.GREEN}Creating chat completion with model {model}, temperature {temperature}, max_tokens {max_tokens}{Fore.RESET}"