Skip to content

Commit db59681

Browse files
authored
feat(browser-client): deleteConversation function (#344)
* Add deleteConversation function * Fix for ESlint * Fix Event Stream
1 parent 94e85a1 commit db59681

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

demos/use-browser-client.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ const response3 = await chatGptClient.sendMessage('Now write it in French.', {
3030
});
3131
console.log();
3232
console.log(response3.response); // Les chats sont les meilleurs animaux de compagnie du monde.
33+
34+
// (Optional) Lets you delete the conversation when you're done with it.
35+
await chatGptClient.deleteConversation(response3.conversationId);

src/ChatGPTBrowserClient.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ export default class ChatGPTBrowserClient {
178178
return response;
179179
}
180180

181+
async deleteConversation(conversationId) {
182+
const url = this.options.reverseProxyUrl || 'https://chat.openai.com/backend-api/conversation';
183+
184+
// eslint-disable-next-line no-async-promise-executor
185+
return new Promise(async (resolve, reject) => {
186+
try {
187+
await fetch(`${url}/${conversationId}`, {
188+
headers: {
189+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
190+
'Content-Type': 'application/json',
191+
Authorization: `Bearer ${this.accessToken}`,
192+
Cookie: this.cookies || undefined,
193+
},
194+
body: '{"is_visible":false}',
195+
method: 'PATCH',
196+
});
197+
} catch (err) {
198+
reject(err);
199+
}
200+
});
201+
}
202+
181203
async sendMessage(
182204
message,
183205
opts = {},

0 commit comments

Comments
 (0)