Stop sequences configured on non-workflow apps are never sent to the model
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with ModelConfigManager.convert and ModelConfigConverter.convert in core/app/app_config/easy_ui_based_app/model_config, then inspect the affected consumers at core/app/apps/base_app_runner.py:167, core/agent/cot_agent_runner.py:150, and core/agent/fc_agent_runner.py:182. Run or extend the regression test mentioned in the issue and confirm that configured stop sequences reach invoke_llm for non-workflow and agent apps.
Written by the indexing model from the issue text.
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.
- Dominant language
- TypeScript
- Stars
- 157k
- Forks
- 24.7k
- Avg merge
- 22h 32m
- Merged PRs (30d)
- 611
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from langgenius/dify
-
Annotation Reply: a stored score threshold of 0.0 is silently replaced with 1, disabling the feature Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
langgenius/dify#42639 · 1 comment · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
langgenius/dify#42468 · 1 comment · 1 reaction ·
-
🐞 bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
langgenius/dify#42446 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
langgenius/dify#42355 · 1 comment · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
langgenius/dify#42350 · 1 comment · 1 reaction ·
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100