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
39.76k stars 5.45k forks source link

api /v1/chat-messages match annotation or moderation on blocking in service api of chat flow, but answer is empty #6201

Closed guogeer closed 1 week ago

guogeer commented 2 weeks ago

Self Checks

Dify version

0.6.13

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

api /v1/chat-messages match annotation or moderation on blocking in service api of chat flow, but answer is empty

image 20240711-193706

✔️ Expected Behavior

output annotation or moderation result

❌ Actual Behavior

empty

dosubot[bot] commented 2 weeks ago

The response might be empty because the inputs field in your request is empty. Ensure that the inputs field contains relevant data. Here is an example of a correctly formatted request for the /v1/chat-messages endpoint:

import requests
import json

url = 'https://api.dify.ai/v1/chat-messages'
headers = {
    'Authorization': 'Bearer ENTER-YOUR-SECRET-KEY',
    'Content-Type': 'application/json',
}
data = {
    "inputs": {"text": "Hello, how are you?"},  # Ensure this field is populated
    "query": "eh",
    "response_mode": "streaming",
    "conversation_id": "1c7e55fb-1ba2-4e10-81b5-30addcea2276",
    "user": "abc-123"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

print(response.json())

Make sure the inputs field is not empty and contains the necessary data for the API to process.

Additionally, ensure that the moderation and annotation processes are correctly configured. The AgentChatAppRunner class in Dify's codebase handles these processes. If there are issues with moderation or annotation, the response might be empty. Check the following:

  1. Moderation: Ensure that the moderation process does not raise any exceptions. If a ModerationException is raised, it will directly output the exception message and return. You can extend custom content moderation rules at the code level in a private deployment of Dify. For example, you can create a custom moderation class like CloudServiceModeration to handle specific business logic for moderation.

  2. Annotation: Verify that the annotation reply is correctly processed. If an annotation reply is found, it will be published and returned.

Review the AgentChatAppRunner class to ensure that all necessary configurations and processes are correctly set up. For more detailed guidance on extending and debugging custom moderation rules, refer to the Dify documentation on Sensitive Content Moderation [1][2][3][4].

To continue talking to Dosu, mention @dosu.