langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
46.02k stars 6.49k forks source link

[Chatflow] All classes with "Answer" block are triggered in "Knowledge Classifier" #8222

Closed AnotiaWang closed 1 week ago

AnotiaWang commented 1 week ago

Self Checks

Dify version

0.8.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a Chatflow chatbot
  2. Create the following chatflow: 截屏2024-09-10 19 40 40
  3. Preview the chatbot, and ask anything, e.g. "2".

✔️ Expected Behavior

The bot should answer "Response from 2".

❌ Actual Behavior

The bot answered "Response from 1Response from 2Response from 3".

截屏2024-09-10 19 43 41

I'm not sure whether all classes are triggered in the classifier, or just the ones that have Answers, since other classes are not shown in the log.

dosubot[bot] commented 1 week ago

All classes with the "Answer" block are being triggered in the "Knowledge Classifier" in your Chatflow chatbot, resulting in concatenated responses because the "Answer" block is defined to handle response content in a Chatflow process. This means that whenever the "Knowledge Classifier" node classifies a user input, it triggers the "Answer" block to generate a response, leading to multiple "Answer" blocks being activated and their responses concatenated.

To address this, you can configure the issue classifier to direct the flow to different paths based on the classification results. By setting up specific classification labels/descriptions and corresponding downstream nodes, you can ensure that only the relevant "Answer" block is triggered for each classified input. This can be done by:

  1. Selecting Input Variable: Define the content to be classified, usually the user's question.
  2. Choosing Inference Model: Select an appropriate model to enhance classification effectiveness.
  3. Writing Classification Labels/Descriptions: Add multiple classifications with keywords or descriptive statements for each category.
  4. Choosing Corresponding Downstream Nodes: Direct the flow to different paths based on the classification results.

By configuring these steps, you can prevent multiple "Answer" blocks from being triggered simultaneously, thereby avoiding concatenated responses.

Additionally, the QuestionClassifierNode in Dify's platform uses a structured approach to classify questions and direct the flow accordingly. It extracts variables, fetches model configurations, and processes the input through a series of prompt messages. The node then determines the appropriate category based on the classification results and directs the flow to the corresponding downstream node. This ensures that only the relevant "Answer" block is triggered, preventing concatenated responses.

The QUESTION_CLASSIFIER_SYSTEM_PROMPT in Dify's platform specifies that the classifier should assign only one category to the input text and extract keywords related to the classification. This constraint helps in ensuring that only the most relevant "Answer" block is triggered, thus avoiding the issue of concatenated responses [1][2][3][4][5].

To continue talking to Dosu, mention @dosu.

AnotiaWang commented 1 week ago

Maybe #8221 fixes this issue

crazywoola commented 1 week ago
image

Seems fixed in latest branch.