From df9bd36caba86051e856ea2a3ca25abd4d2e0f7b Mon Sep 17 00:00:00 2001 From: Joe <79627742+ZhouhaoJiang@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:34:44 +0800 Subject: [PATCH] fix: claude-3-5-sonnet-20240620 max token error (#6843) --- .../anthropic/llm/claude-3-5-sonnet-20240620.yaml | 1 - api/core/model_runtime/model_providers/anthropic/llm/llm.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/core/model_runtime/model_providers/anthropic/llm/claude-3-5-sonnet-20240620.yaml b/api/core/model_runtime/model_providers/anthropic/llm/claude-3-5-sonnet-20240620.yaml index e02c5517fe..64ae3abf64 100644 --- a/api/core/model_runtime/model_providers/anthropic/llm/claude-3-5-sonnet-20240620.yaml +++ b/api/core/model_runtime/model_providers/anthropic/llm/claude-3-5-sonnet-20240620.yaml @@ -26,7 +26,6 @@ parameter_rules: required: false - name: max_tokens use_template: max_tokens - required: true default: 8192 min: 1 max: 8192 diff --git a/api/core/model_runtime/model_providers/anthropic/llm/llm.py b/api/core/model_runtime/model_providers/anthropic/llm/llm.py index 107efe4867..19ce401999 100644 --- a/api/core/model_runtime/model_providers/anthropic/llm/llm.py +++ b/api/core/model_runtime/model_providers/anthropic/llm/llm.py @@ -116,7 +116,8 @@ class AnthropicLargeLanguageModel(LargeLanguageModel): # Add the new header for claude-3-5-sonnet-20240620 model extra_headers = {} if model == "claude-3-5-sonnet-20240620": - extra_headers["anthropic-beta"] = "max-tokens-3-5-sonnet-2024-07-15" + if model_parameters.get('max_tokens') > 4096: + extra_headers["anthropic-beta"] = "max-tokens-3-5-sonnet-2024-07-15" if tools: extra_model_kwargs['tools'] = [