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

Reinier van der Leer244393e4ef4e
diff --git a/autogpt/llm/utils/__init__.py b/autogpt/llm/utils/__init__.py
index 756c4bd55d..fd7ba49f3f 100644
--- a/autogpt/llm/utils/__init__.py
+++ b/autogpt/llm/utils/__init__.py
@@ -17,6 +17,7 @@ from autogpt.logs import logger
from ..api_manager import ApiManager
from ..base import ChatSequence, Message
+from ..providers.openai import OPEN_AI_CHAT_MODELS
from .token_counter import *
@@ -205,6 +206,8 @@ def create_chat_completion(
model = prompt.model.name
if temperature is None:
temperature = cfg.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}"