From d730687fc8ea099aaa91aa58b6f454e84f23a831 Mon Sep 17 00:00:00 2001 From: chiwoo Date: Wed, 29 Oct 2025 23:51:09 +0900 Subject: [PATCH 1/4] Openai Compatible api for Reasoning LLM models --- python/dify_plugin/entities/model/__init__.py | 1 + .../interfaces/model/openai_compatible/llm.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/python/dify_plugin/entities/model/__init__.py b/python/dify_plugin/entities/model/__init__.py index c07eeece..bc792144 100644 --- a/python/dify_plugin/entities/model/__init__.py +++ b/python/dify_plugin/entities/model/__init__.py @@ -22,6 +22,7 @@ class DefaultParameterName(Enum): PRESENCE_PENALTY = "presence_penalty" FREQUENCY_PENALTY = "frequency_penalty" MAX_TOKENS = "max_tokens" + MAX_COMPLETION_TOKENS = "max_completion_tokens" RESPONSE_FORMAT = "response_format" JSON_SCHEMA = "json_schema" diff --git a/python/dify_plugin/interfaces/model/openai_compatible/llm.py b/python/dify_plugin/interfaces/model/openai_compatible/llm.py index e26c7464..50c11dd2 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/llm.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/llm.py @@ -180,7 +180,11 @@ def validate_credentials(self, model: str, credentials: dict) -> None: endpoint_url += "/" # prepare the payload for a simple ping to the model - data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": 5} + if credentials.get("reasoning_thought_support") == "supported": + # for reasoning thought support, they use max_completion_tokens + data = {"model": credentials.get("endpoint_model_name", model), "max_completion_tokens": 5} + else: + data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": 5} completion_type = LLMMode.value_of(credentials["mode"]) @@ -256,6 +260,12 @@ def get_customizable_model_schema(self, model: str, credentials: dict) -> AIMode """ features = [] + # for reasoning thought support, they use max_completion_tokens + def get_max_token_param(): + if credentials.get("reasoning_thought_support") == "supported": + return {"name": DefaultParameterName.MAX_COMPLETION_TOKENS.value, "label": "Max Completion Tokens"} + return {"name": DefaultParameterName.MAX_TOKENS.value, "label": "Max Tokens"} + function_calling_type = credentials.get("function_calling_type", "no_call") if function_calling_type == "function_call": features.append(ModelFeature.TOOL_CALL) @@ -338,7 +348,7 @@ def get_customizable_model_schema(self, model: str, credentials: dict) -> AIMode max=2, ), ParameterRule( - name=DefaultParameterName.MAX_TOKENS.value, + name=get_max_token_param(), label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"), help=I18nObject( en_US="Maximum length of tokens for the model response.", From 414659737fa1d0a1323803a1b94979678ecf98d5 Mon Sep 17 00:00:00 2001 From: chiwoo Date: Wed, 29 Oct 2025 23:59:04 +0900 Subject: [PATCH 2/4] update python/README.md for version update --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index eb43a218..09916b6b 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dify_plugin" -version = "0.5.1" +version = "0.6.1" description = "Dify Plugin SDK" authors = [{ name = "langgenius", email = "hello@dify.ai" }] dependencies = [ From 791d29f3e0b207774560dcc80bd24ea56645be76 Mon Sep 17 00:00:00 2001 From: chiwoo Date: Thu, 30 Oct 2025 01:01:35 +0900 Subject: [PATCH 3/4] editing critical code --- .../interfaces/model/openai_compatible/llm.py | 14 ++++++++------ python/pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/llm.py b/python/dify_plugin/interfaces/model/openai_compatible/llm.py index 50c11dd2..cab9cc33 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/llm.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/llm.py @@ -261,10 +261,12 @@ def get_customizable_model_schema(self, model: str, credentials: dict) -> AIMode features = [] # for reasoning thought support, they use max_completion_tokens - def get_max_token_param(): - if credentials.get("reasoning_thought_support") == "supported": - return {"name": DefaultParameterName.MAX_COMPLETION_TOKENS.value, "label": "Max Completion Tokens"} - return {"name": DefaultParameterName.MAX_TOKENS.value, "label": "Max Tokens"} + if credentials.get("reasoning_thought_support") == "supported": + max_token_param_name = DefaultParameterName.MAX_COMPLETION_TOKENS.value + max_token_param_label = "Max Completion Tokens" + else: + max_token_param_name = DefaultParameterName.MAX_TOKENS.value + max_token_param_label = "Max Tokens" function_calling_type = credentials.get("function_calling_type", "no_call") if function_calling_type == "function_call": @@ -348,8 +350,8 @@ def get_max_token_param(): max=2, ), ParameterRule( - name=get_max_token_param(), - label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"), + name=max_token_param_name, + label=I18nObject(en_US=max_token_param_label, zh_Hans="最大标记"), help=I18nObject( en_US="Maximum length of tokens for the model response.", zh_Hans="模型回答的tokens的最大长度。", diff --git a/python/pyproject.toml b/python/pyproject.toml index 09916b6b..eb43a218 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dify_plugin" -version = "0.6.1" +version = "0.5.1" description = "Dify Plugin SDK" authors = [{ name = "langgenius", email = "hello@dify.ai" }] dependencies = [ From b1fe8896589dd0cb86da37bccb59d429bdb4e45a Mon Sep 17 00:00:00 2001 From: Maries Date: Mon, 20 Oct 2025 14:41:22 +0800 Subject: [PATCH 4/4] fix: apply reviewer feedback --- python/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 54cbf487..eb43a218 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dify_plugin" -version = "0.5.0" +version = "0.5.1" description = "Dify Plugin SDK" authors = [{ name = "langgenius", email = "hello@dify.ai" }] dependencies = [