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.76k stars 6.61k forks source link

Issues with conversation_id in Dify API – Error "Conversation does not exist" #8858

Open evertonresende opened 1 day ago

evertonresende commented 1 day ago

Self Checks

Dify version

0.8.3

Cloud or Self Hosted

Cloud

Steps to reproduce

Steps to Reproduce

  1. I set up an automation in n8n to send requests to the /chat-messages endpoint of the Dify API.
  2. The first request is sent without a conversation_id, and I successfully receive a response with a valid conversation_id.
  3. I capture this conversation_id and use it in a second request to continue the conversation.
  4. The second request fails with a 404 - Conversation does not exist error, even though the conversation_id is visible in the Dify dashboard.

First Request (works as expected):

curl -X POST 'https://api.dify.ai/v1/chat-messages' \
--header 'Authorization: Bearer {API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "user": "user-id-example"
}' 

Response from First Request:

{
  "message_id": "1234",
  "conversation_id": "30082f1d-0a67-4bc7-9e5a-7907d1835cd2",
  "answer": "The iPhone 13 Pro Max has a 6.7-inch display, etc..."
}

Second Request (returns error):

curl -X POST 'https://api.dify.ai/v1/chat-messages' \
--header 'Authorization: Bearer {API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": "Tell me more about the iPhone's camera?",
    "conversation_id": "30082f1d-0a67-4bc7-9e5a-7907d1835cd2",
    "response_mode": "streaming",
    "user": "user-id-example"
}'

Response from Second Request:

{
  "error": {
    "message": "Conversation does not exist",
    "code": "conversation_not_found"
  }
}

Captura de tela 2024-09-27 222030 Captura de tela 2024-09-27 220549

✔️ Expected Behavior

The conversation_id should allow the conversation to continue, with the response based on the previous context.

❌ Actual Behavior

The API returns a 404 - Conversation does not exist error, even though the conversation_id is valid and visible in the Dify dashboard.

dosubot[bot] commented 1 day ago

Hey @evertonresende! I'm here to assist you with any bugs, questions, or contributions. Let's work together to resolve the issue.

The "Conversation does not exist" error for a valid conversation_id in the second request could occur if the conversation_id is not being correctly maintained or passed in subsequent API calls. According to the documentation:

Ensure that the conversation_id is correctly captured from the initial response and consistently used in all subsequent requests. Here is an example of how to correctly use the conversation_id in a Python request:

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": {},
    "query": "Tell me more about the iPhone's camera?",
    "response_mode": "streaming",
    "conversation_id": "30082f1d-0a67-4bc7-9e5a-7907d1835cd2",  # Ensure this is the correct conversation_id
    "user": "user-id-example"
}

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

print(response.json())

Ensure that the conversation_id is correctly captured from the initial response and consistently used in all subsequent requests [1][2].

To continue talking to Dosu, mention @dosu.

crazywoola commented 1 day ago
image

Still can not reproduce it. I am using both postman and curl command.

evertonresende commented 17 hours ago

image Still can not reproduce it. I am using both postman and curl command.

postmantest

I tested the call in postman and unfortunately it doesn't work.