Skip to content

Commit 919d3dc

Browse files
committed
fix: add MAX_COMPLETION_TOKEN into PARAMETER_RULE_TEMPLATE
2 parents b1fe889 + 791d29f commit 919d3dc

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

python/dify_plugin/entities/model/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class DefaultParameterName(Enum):
2222
PRESENCE_PENALTY = "presence_penalty"
2323
FREQUENCY_PENALTY = "frequency_penalty"
2424
MAX_TOKENS = "max_tokens"
25+
MAX_COMPLETION_TOKENS = "max_completion_tokens"
2526
RESPONSE_FORMAT = "response_format"
2627
JSON_SCHEMA = "json_schema"
2728

@@ -139,6 +140,23 @@ def value_of(cls, value: Any) -> "DefaultParameterName":
139140
"max": 2048,
140141
"precision": 0,
141142
},
143+
DefaultParameterName.MAX_COMPLETION_TOKENS: {
144+
"label": {
145+
"en_US": "Max Completion Tokens",
146+
"zh_Hans": "最大完成标记",
147+
},
148+
"type": "int",
149+
"help": {
150+
"en_US": "Specifies the upper limit on the length of generated results. "
151+
"If the generated results are truncated, you can increase this parameter.",
152+
"zh_Hans": "指定生成结果长度的上限。如果生成结果截断,可以调大该参数。",
153+
},
154+
"required": False,
155+
"default": 64,
156+
"min": 1,
157+
"max": 2048,
158+
"precision": 0,
159+
},
142160
DefaultParameterName.RESPONSE_FORMAT: {
143161
"label": {
144162
"en_US": "Response Format",

python/dify_plugin/interfaces/model/openai_compatible/llm.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
180180
endpoint_url += "/"
181181

182182
# prepare the payload for a simple ping to the model
183-
data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": 5}
183+
if credentials.get("reasoning_thought_support") == "supported":
184+
# for reasoning thought support, they use max_completion_tokens
185+
data = {"model": credentials.get("endpoint_model_name", model), "max_completion_tokens": 5}
186+
else:
187+
data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": 5}
184188

185189
completion_type = LLMMode.value_of(credentials["mode"])
186190

@@ -256,6 +260,14 @@ def get_customizable_model_schema(self, model: str, credentials: dict) -> AIMode
256260
"""
257261
features = []
258262

263+
# for reasoning thought support, they use max_completion_tokens
264+
if credentials.get("reasoning_thought_support") == "supported":
265+
max_token_param_name = DefaultParameterName.MAX_COMPLETION_TOKENS.value
266+
max_token_param_label = "Max Completion Tokens"
267+
else:
268+
max_token_param_name = DefaultParameterName.MAX_TOKENS.value
269+
max_token_param_label = "Max Tokens"
270+
259271
function_calling_type = credentials.get("function_calling_type", "no_call")
260272
if function_calling_type == "function_call":
261273
features.append(ModelFeature.TOOL_CALL)
@@ -338,8 +350,8 @@ def get_customizable_model_schema(self, model: str, credentials: dict) -> AIMode
338350
max=2,
339351
),
340352
ParameterRule(
341-
name=DefaultParameterName.MAX_TOKENS.value,
342-
label=I18nObject(en_US="Max Tokens", zh_Hans="最大标记"),
353+
name=max_token_param_name,
354+
label=I18nObject(en_US=max_token_param_label, zh_Hans="最大标记"),
343355
help=I18nObject(
344356
en_US="Maximum length of tokens for the model response.",
345357
zh_Hans="模型回答的tokens的最大长度。",

0 commit comments

Comments
 (0)