From 867bf70f1a62463ff5fec38edd4c0f190503ea5b Mon Sep 17 00:00:00 2001 From: -LAN- Date: Mon, 11 Nov 2024 16:06:53 +0800 Subject: [PATCH] fix(model_runtime): ensure compatibility with O1 models by adjusting token parameters (#10537) --- api/core/model_runtime/model_providers/openai/llm/llm.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/core/model_runtime/model_providers/openai/llm/llm.py b/api/core/model_runtime/model_providers/openai/llm/llm.py index 922e5e1314..68317d7179 100644 --- a/api/core/model_runtime/model_providers/openai/llm/llm.py +++ b/api/core/model_runtime/model_providers/openai/llm/llm.py @@ -617,6 +617,10 @@ class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel): # o1 compatibility block_as_stream = False if model.startswith("o1"): + if "max_tokens" in model_parameters: + model_parameters["max_completion_tokens"] = model_parameters["max_tokens"] + del model_parameters["max_tokens"] + if stream: block_as_stream = True stream = False