Repository navigation
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report.
- [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- Please do not modify this template :) and fill in all the required fields.
Dify version
1.17.0
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
- Create a Chatbot app (this also affects Agent, Completion and Agent Chat apps).
- Switch the prompt to expert mode.
- Open the model parameter panel and add a stop sequence, for example
###. - Publish, then send a message that makes the model produce
###mid answer. - The model keeps generating past
###.
The saved app model config is correct, the loss happens during runtime conversion. ModelConfigManager.convert moves stop out of completion_params and onto ModelConfigEntity.stop, but ModelConfigConverter.convert still looks for stop inside model_config.parameters, where it no longer exists, and never reads model_config.stop. ModelConfigWithCredentialsEntity.stop is therefore always empty, and ModelConfigEntity.stop has no readers anywhere in the codebase.
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
from core.app.app_config.easy_ui_based_app.model_config.converter import ModelConfigConverter
from core.app.app_config.easy_ui_based_app.model_config.manager import ModelConfigManager
M = "core.app.app_config.easy_ui_based_app.model_config.converter"
saved = {"model": {"provider": "openai", "name": "gpt-4", "mode": "chat",
"completion_params": {"temperature": 0.5, "stop": ["###"]}}}
entity = ModelConfigManager.convert(saved)
print("ModelConfigEntity.stop ->", entity.stop)
with (patch(f"{M}.create_plugin_provider_manager"),
patch(f"{M}.ModelConfigWithCredentialsEntity", side_effect=lambda **kw: SimpleNamespace(**kw))):
runtime = ModelConfigConverter.convert(MagicMock(tenant_id="t", model=entity))
print("stop actually sent to model ->", runtime.stop)ModelConfigEntity.stop -> ['###']
stop actually sent to model -> []
Affected consumers are core/app/apps/base_app_runner.py:167 for the advanced prompt path and core/agent/cot_agent_runner.py:150 and core/agent/fc_agent_runner.py:182 for agent apps.
I have a fix ready with a regression test and would be happy to be assigned to this issue.
✔️ Expected Behavior
The stop sequences saved in the model configuration reach invoke_llm, so generation stops at the configured sequence.
❌ Actual Behavior
ModelConfigWithCredentialsEntity.stop is always an empty list, so the model is invoked with no stop sequences and generation runs past them.
Activity