api bug! '/chat messages' loses parameter' parent_message_id '!How to regenerate the message if 'parent_message_id' is not supported #6471

Closed
opened 2026-02-21 18:15:53 -05:00 by yindo · 8 comments
Owner

Originally created by @glacierck on GitHub (Oct 31, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.10.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

curl -X POST 'http://192.168.1.210/v1/chat-messages' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "query": "4",
    "response_mode": "streaming",
    "conversation_id": "64e25005-442f-41aa-97e3-f3e282e5a918",
    "parent_message_id":"165c27a7-561a-44a6-a311-e4ff33ea9638",
    "user": "abc-123"
}'

✔️ Expected Behavior

Delete the old answer for '4' and regenerate the answer for '4'

Actual Behavior

The old answer for '4' has not been deleted, and 'regenerate' has not been implemented!

Originally created by @glacierck on GitHub (Oct 31, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.10.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ``` curl -X POST 'http://192.168.1.210/v1/chat-messages' \ --header 'Authorization: Bearer {api_key}' \ --header 'Content-Type: application/json' \ --data-raw '{ "inputs": {}, "query": "4", "response_mode": "streaming", "conversation_id": "64e25005-442f-41aa-97e3-f3e282e5a918", "parent_message_id":"165c27a7-561a-44a6-a311-e4ff33ea9638", "user": "abc-123" }' ``` ### ✔️ Expected Behavior Delete the old answer for '4' and regenerate the answer for '4' ### ❌ Actual Behavior The old answer for '4' has not been deleted, and 'regenerate' has not been implemented!
yindo added the 🐞 bug label 2026-02-21 18:15:53 -05:00
yindo closed this issue 2026-02-21 18:15:53 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 31, 2024):

I found a similar open issue regarding the '/chat messages' API losing the 'parent_message_id' parameter. You can view the issue here. It seems there is no solution or comments on it yet [1].

To implement the 'regenerate' function when the 'parent_message_id' is not supported, you can modify the doRegenerate function to exclude the parent_message_id from the data being sent. Here's a suggested approach:

const doRegenerate = useCallback((chatItem: ChatItem) => {
  const index = chatList.findIndex(item => item.id === chatItem.id)
  if (index === -1)
    return

  const prevMessages = chatList.slice(0, index)
  const question = prevMessages.pop()

  if (!question)
    return

  handleUpdateChatList(prevMessages)
  // Remove the lastAnswer parameter since parent_message_id is not supported
  doSend(question.content, question.message_files, null)
}, [chatList, handleUpdateChatList, doSend])

In this modification, the lastAnswer is set to null when calling doSend, effectively omitting the parent_message_id from the request data. The doSend function in the provided context already handles the parent_message_id by setting it to null if last_answer is not provided, ensuring compatibility with the API's limitations [2][3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 31, 2024): <!-- Answer --> I found a similar open issue regarding the '/chat messages' API losing the 'parent_message_id' parameter. You can view the issue [here](https://github.com/langgenius/dify/issues/10115). It seems there is no solution or comments on it yet <sup>[[1]](https://github.com/langgenius/dify/issues/10115)</sup>. To implement the 'regenerate' function when the 'parent_message_id' is not supported, you can modify the `doRegenerate` function to exclude the `parent_message_id` from the data being sent. Here's a suggested approach: ```tsx const doRegenerate = useCallback((chatItem: ChatItem) => { const index = chatList.findIndex(item => item.id === chatItem.id) if (index === -1) return const prevMessages = chatList.slice(0, index) const question = prevMessages.pop() if (!question) return handleUpdateChatList(prevMessages) // Remove the lastAnswer parameter since parent_message_id is not supported doSend(question.content, question.message_files, null) }, [chatList, handleUpdateChatList, doSend]) ``` In this modification, the `lastAnswer` is set to `null` when calling `doSend`, effectively omitting the `parent_message_id` from the request data. The `doSend` function in the provided context already handles the `parent_message_id` by setting it to `null` if `last_answer` is not provided, ensuring compatibility with the API's limitations <sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/components/app/configuration/debug/debug-with-single-model/index.tsx)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@glacierck commented on GitHub (Oct 31, 2024):

@dosu What API does the 'handleupdateChatList' function call to modify the chat messages list?

@glacierck commented on GitHub (Oct 31, 2024): @dosu What API does the 'handleupdateChatList' function call to modify the chat messages list?
Author
Owner

@dosubot[bot] commented on GitHub (Oct 31, 2024):

The handleUpdateChatList function does not directly call any API to modify the chat messages list. Instead, it updates the state of the chat list within the application by setting a new list of chat items and updating a reference to the current chat list. This function is primarily used to manage the state of the chat list in the application's frontend [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 31, 2024): <!-- Answer --> The `handleUpdateChatList` function does not directly call any API to modify the chat messages list. Instead, it updates the state of the chat list within the application by setting a new list of chat items and updating a reference to the current chat list. This function is primarily used to manage the state of the chat list in the application's frontend <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/base/chat/chat/hooks.ts)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@glacierck commented on GitHub (Oct 31, 2024):

@dosu What I'm discussing here is how to use APIs to modify historical conversation messages

@glacierck commented on GitHub (Oct 31, 2024): @dosu What I'm discussing here is how to use APIs to modify historical conversation messages
Author
Owner

@crazywoola commented on GitHub (Oct 31, 2024):

If you delete an old conversation, then it won't be able to regenerate.

@crazywoola commented on GitHub (Oct 31, 2024): If you delete an old conversation, then it won't be able to regenerate.
Author
Owner

@glacierck commented on GitHub (Oct 31, 2024):

@crazywoola What I mean is to regenerate the message!not the conversation.
image
What other APIs can be used without using 'parent_message_id'?

@glacierck commented on GitHub (Oct 31, 2024): @crazywoola What I mean is to regenerate the message!not the conversation. ![image](https://github.com/user-attachments/assets/ff12b576-6f98-4e30-9ab6-1a5a8009fedb) What other APIs can be used without using 'parent_message_id'?
Author
Owner

@f1025211271 commented on GitHub (Dec 18, 2024):

I encountered the same problem. When using the service api v1/chat-messages, there is no "parent_message_id" field, so I cannot ask a question again based on a historical message. I sincerely hope that this function will be added as soon as possible. @crazywoola thanks

@f1025211271 commented on GitHub (Dec 18, 2024): I encountered the same problem. When using the service api v1/chat-messages, there is no "parent_message_id" field, so I cannot ask a question again based on a historical message. I sincerely hope that this function will be added as soon as possible. @crazywoola thanks
Author
Owner

@dosubot[bot] commented on GitHub (Dec 18, 2024):

There is no specific API endpoint in the Dify codebase designed for updating or modifying existing chat messages. The /chat-messages API endpoint is primarily used for initiating and continuing conversations, but it does not support direct modifications to historical messages [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Dec 18, 2024): <!-- Answer --> There is no specific API endpoint in the Dify codebase designed for updating or modifying existing chat messages. The `/chat-messages` API endpoint is primarily used for initiating and continuing conversations, but it does not support direct modifications to historical messages <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-publishing/developing-with-apis.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/01c41342-8331-43ef-bb2f-bfb15092dd95?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/01c41342-8331-43ef-bb2f-bfb15092dd95?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/01c41342-8331-43ef-bb2f-bfb15092dd95?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/01c41342-8331-43ef-bb2f-bfb15092dd95?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/01c41342-8331-43ef-bb2f-bfb15092dd95?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/01c41342-8331-43ef-bb2f-bfb15092dd95?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6471