Skip to content

Commit ee8ea3d

Browse files
fix: increase max_tokens from 5 to 16 for some specific models like gpt-5-codex in ping test, add PING_MAX_TOKENS configuration for model validation ping requests (#235)
1 parent 60e8059 commit ee8ea3d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

python/dify_plugin/config/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class DifyPluginEnv(BaseSettings):
4040

4141
DIFY_PLUGIN_DAEMON_URL: str = Field(default="http://localhost:5002", description="backwards invocation address")
4242

43+
PING_MAX_TOKENS: int = Field(
44+
default=16,
45+
description="Maximum tokens for model validation ping request. Some providers require at least 16 tokens.",
46+
)
47+
4348
model_config = SettingsConfigDict(
4449
# read from dotenv format config file
4550
env_file=".env",

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
172172
:return:
173173
"""
174174
try:
175+
# Load ping max_tokens configuration from environment variable
176+
config = DifyPluginEnv()
177+
ping_max_tokens = config.PING_MAX_TOKENS
178+
175179
headers = {"Content-Type": "application/json"}
176180

177181
api_key = credentials.get("api_key")
@@ -183,7 +187,7 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
183187
endpoint_url += "/"
184188

185189
# prepare the payload for a simple ping to the model
186-
data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": 5}
190+
data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": ping_max_tokens}
187191

188192
completion_type = LLMMode.value_of(credentials["mode"])
189193

@@ -202,7 +206,7 @@ def validate_credentials(self, model: str, credentials: dict) -> None:
202206
stream_mode_auth = credentials.get("stream_mode_auth", "not_use")
203207
if stream_mode_auth == "use":
204208
data["stream"] = True
205-
data["max_tokens"] = 10
209+
data["max_tokens"] = ping_max_tokens
206210
response = requests.post(endpoint_url, headers=headers, json=data, timeout=(10, 300), stream=True)
207211
if response.status_code != 200:
208212
raise CredentialsValidateFailedError(

0 commit comments

Comments
 (0)