Re:Everything ChatGPT – under the hood of the ChatGPT web app
by chatmasta on Wednesday March 22, 2023 @09:34PM
(#35269455)
This doesn't actually cover the most important part, which is where the response to a chat shows up. Has anyone figured this out? I only looked briefly, but it doesn't show up in the response data in Chrome DevTools. I figured it was maybe using WebSockets or Server Sent Events, which apparently don't show up in DevTools by default?
[ Parent
| on HN ]
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by marpstar on Wednesday March 22, 2023 @09:52PM
(#35269535)
Shows up in Safari as Content-Type: text/event-stream on the https://chat.openai.com/backend-api/conversation endpoint.
You can see the network call spin while the text loads.
edit: added name of endpoint.
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by codetrotter on Thursday March 23, 2023 @03:43AM
(#35271579)
The URL you linked says
{"detail":"Method Not Allowed"}
When I click on it
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by 1xdevloper on Thursday March 23, 2023 @04:15AM
(#35271755)
Clicking it won't do anything. It's a POST request endpoint so you also have to provide the auth token and input.
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by Semaphor on Thursday March 23, 2023 @04:13AM
(#35271744)
You aren’t supposed to click on it, that won’t work. It’s the endpoint that’s showing up in the network tab.
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by 1xdevloper on Thursday March 23, 2023 @04:22AM
(#35271792)
Probably because they're using a polyfill[0][1] to handle the event stream.
[0] https://stackoverflow.com/questions/55201372/event-stream-da... [1] https://github.com/EventSource/eventsource/issues/94
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by black3r on Thursday March 23, 2023 @04:44AM
(#35271910)
And that's because the native EventStream API only supports GET requests, so if you want to use a POST request (which make more sense in this context) you have to use a custom implementation...
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by qqqturing2 on Thursday March 23, 2023 @06:40AM
(#35272636)
they are using Server Side Events (SSE) to stream the text.
see API docs: https://platform.openai.com/docs/api-reference/chat/create
> If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. See the OpenAI Cookbook for example code.
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by czx4f4bd on Thursday March 23, 2023 @09:05AM
(#35274107)
Interesting. Apparently server-sent events show up in devtools under the network tab as multiple responses sent for the same request.
https://firefox-source-docs.mozilla.org/devtools-user/networ...
Re:Everything ChatGPT – under the hood of the ChatGPT web app
by tercmd on Thursday March 23, 2023 @11:17AM
(#35276176)
(Creator of the repo here) That is somewhat present in the `/backend-api/moderations` endpoint where the app sends your question + ChatGPT's response to (first time just your question, second time both)