terminalcommandnewsletter / everything-chatgpt

🔍 Explore what happens under the hood with the ChatGPT web app, its backend API calls and more. And some speculation, of course.
Creative Commons Attribution Share Alike 4.0 International
576 stars 29 forks source link

Misc: Where parent_message_id come from? #12

Closed rendomnet closed 1 year ago

rendomnet commented 1 year ago

Is there an existing issue for this?

Issue

In your example where parent_message_id and id values come from?

action: next
messages (Array):
|__ (Object):
|____ author (Object):
|______ role: user
|____ content (Object):
|______ content_type: text
|______ parts (Array):
|________ What is ChatGPT?
|__ id: 0c[redacted]91
|__ role: user
model: text-davinci-002-render-sha
parent_message_id: a0[redacted]7f

CONTRIBUTING.md

terminalcommandnewsletter commented 1 year ago

It comes from the previous message in the conversation.

rendomnet commented 1 year ago

@terminalcommandnewsletter Sorry I cant find the step where we create the conversation.

terminalcommandnewsletter commented 1 year ago

See the "The process of asking ChatGPT a question" section.

rendomnet commented 1 year ago

See the "The process of asking ChatGPT a question" section.

Yes and there is no call for creating the conversation. In this section we already using the parent_message_id

terminalcommandnewsletter commented 1 year ago

First, we make a POST request to /backend-api/conversation with a request body like this:

action: next
messages (Array):
|__ (Object):
|____ author (Object):
|______ role: user
|____ content (Object):
|______ content_type: text
|______ parts (Array):
|________ What is ChatGPT?
|__ id: 0c[redacted]91
|__ role: user
model: text-davinci-002-render-sha
parent_message_id: a0[redacted]7f

This responds with an EventStream which ends with a [DONE] signal. You can view a sample response in sample/conversation-event-stream.txt.

rendomnet commented 1 year ago

First, we make a POST request to /backend-api/conversation with a request body like this:

action: next
messages (Array):
|__ (Object):
|____ author (Object):
|______ role: user
|____ content (Object):
|______ content_type: text
|______ parts (Array):
|________ What is ChatGPT?
|__ id: 0c[redacted]91
|__ role: user
model: text-davinci-002-render-sha
parent_message_id: a0[redacted]7f

This responds with an EventStream which ends with a [DONE] signal. You can view a sample response in sample/conversation-event-stream.txt.

Yes and where parent_message_id value come from?

rendomnet commented 1 year ago

First, we make a POST request to /backend-api/conversation with a request body like this:

action: next
messages (Array):
|__ (Object):
|____ author (Object):
|______ role: user
|____ content (Object):
|______ content_type: text
|______ parts (Array):
|________ What is ChatGPT?
|__ id: 0c[redacted]91
|__ role: user
model: text-davinci-002-render-sha
parent_message_id: a0[redacted]7f

This responds with an EventStream which ends with a [DONE] signal. You can view a sample response in sample/conversation-event-stream.txt.

To make this request we first need to have parent_message_id and id values right?

terminalcommandnewsletter commented 1 year ago

I'm currently not able to check. I'll check it once I can and get back to you.

rendomnet commented 1 year ago

@terminalcommandnewsletter without this values post request returns error.

rendomnet commented 1 year ago

@terminalcommandnewsletter Any updates on this?

terminalcommandnewsletter commented 1 year ago

Hi! Sorry for the late response. The request (even on first message) already starts with a message ID and parent message ID.

I'm assuming this is generated on the client-side, though you can use any values as the message ID (changing the parent message ID to anything else returns an error "Hmm...something seems to have gone wrong." since that is used to link conversations) such as "13371337-1337-1337-1337-133713371337" and the server will correct it to use a different message ID (such as "f0[redacted]a0").

Hope this answers your question.

terminalcommandnewsletter commented 1 year ago

This is quite interesting. When I refreshed the page and clicked on each conversation, I found 3 conversations all containing a message with an id of 13371337-1337-1337-1337-133713371337 which is just crazy :laughing: (more so the multiple conversations with messages with the same ID).

Edit: Using a past message ID with this new message ID creates multiple conversations!

rendomnet commented 1 year ago

@terminalcommandnewsletter It is peculiar that we generate these IDs on the client side as they may intersect. Additionally, it seems odd to generate the parent_message_id during the initial call. We should make sure to document this process.

terminalcommandnewsletter commented 1 year ago

Agreed.

rendomnet commented 1 year ago

Hi. Any updates on this? Why did you closed it.

terminalcommandnewsletter commented 1 year ago

There's not much more information and the initial question you had was answered. If there's any related question you want to ask, feel free to comment that and I'll reopen the issue and solve.

rendomnet commented 1 year ago

There's not much more information and the initial question you had was answered. If there's any related question you want to ask, feel free to comment that and I'll reopen the issue and solve.

After conducting my own research, I have come to the conclusion that when initiating a conversation, it is necessary to generate a message ID and a parent ID. However, I'm unsure of the exact purpose of the parent ID in the initial call. Subsequently, to obtain the conversation ID, we must make a call to the conversations endpoint and search for our specific conversation after our initial call.

terminalcommandnewsletter commented 1 year ago

Yes. This is what the web app does. After the first message, it fetches the list of conversations and updates the sidebar. Then, it calls a generate title API and fetches the list again to update it.