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.05k stars 6.49k forks source link

api/core/app/apps/base_app_generate_response_converter.py:71 _get_simple_metadata #8607

Open haike-1213 opened 2 hours ago

haike-1213 commented 2 hours ago

Self Checks

Dify version

0.8

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

image

✔️ Expected Behavior

image Issue Description: The code logic for handling the "retriever_resources" key in the metadata dictionary is incorrect. Specifically: The code checks if "retriever_resources" exists in metadata. If it exists, it clears the list. It then iterates over and rebuilds the list. Problem Reason: The list is cleared before iteration, causing the subsequent loop to have no effect because the list is empty. Suggested Fix: Remove the operation that clears the list to preserve the existing data structure. Iterate and rebuild the list as needed. Relevant Code Snippet: if "retriever_resources" in metadata:

This line clears the list

metadata["retriever_resources"] = []
for resource in metadata["retriever_resources"]:
    metadata["retriever_resources"].append(
        {
            "segment_id": resource["segment_id"],
            "position": resource["position"],
            "document_name": resource["document_name"],
            "score": resource["score"],
            "content": resource["content"],
        }
    )

Suggested Modified Code: if "retriever_resources" in metadata: updated_resources = [] for resource in metadata["retriever_resources"]: updated_resources.append( { "segment_id": resource["segment_id"], "position": resource["position"], "document_name": resource["document_name"], "score": resource["score"], "content": resource["content"], } ) metadata["retriever_resources"] = updated_resources

❌ Actual Behavior

image

dosubot[bot] commented 2 hours ago

Hey @haike-1213! It looks like you're sharing a detailed bug report and some code snippets. While I can help you solve bugs, answer technical questions, and gather engineering knowledge, this specific request seems to be more about sharing a report rather than seeking help with a technical issue.

If you think I should have answered this request, feel free to reach out to the Dosu Team.

To continue talking to Dosu, mention @dosu.