Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: ensure proper conversation role alternation for vLLM (#18837)

Contraila145c2a8fee9
diff --git a/api/core/workflow/nodes/question_classifier/question_classifier_node.py b/api/core/workflow/nodes/question_classifier/question_classifier_node.py
index e846b76280a..28d8b3b8672 100644
--- a/api/core/workflow/nodes/question_classifier/question_classifier_node.py
+++ b/api/core/workflow/nodes/question_classifier/question_classifier_node.py
@@ -79,9 +79,13 @@ class QuestionClassifierNode(LLMNode):
memory=memory,
max_token_limit=rest_token,
)
+ # Some models (e.g. Gemma, Mistral) force roles alternation (user/assistant/user/assistant...).
+ # If both self._get_prompt_template and self._fetch_prompt_messages append a user prompt,
+ # two consecutive user prompts will be generated, causing model's error.
+ # To avoid this, set sys_query to an empty string so that only one user prompt is appended at the end.
prompt_messages, stop = self._fetch_prompt_messages(
prompt_template=prompt_template,
- sys_query=query,
+ sys_query="",
memory=memory,
model_config=model_config,
sys_files=files,