Skip to content

The agent engineering platform.

Allow no token limit for ChatGPT API (#1481)

kahkengdf6865cd5265
diff --git a/langchain/llms/openai.py b/langchain/llms/openai.py
index 6289f25663..adc0c55edd 100644
--- a/langchain/llms/openai.py
+++ b/langchain/llms/openai.py
@@ -619,6 +619,9 @@ class OpenAIChat(BaseLLM, BaseModel):
if "stop" in params:
raise ValueError("`stop` found in both the input and default params.")
params["stop"] = stop
+ if params.get("max_tokens") == -1:
+ # for ChatGPT api, omitting max_tokens is equivalent to having no limit
+ del params["max_tokens"]
return messages, params
def _generate(