From e3355dd9f47238b8c6dc9d3cf6d3adcb7782c63b Mon Sep 17 00:00:00 2001 From: Bruno Cal Date: Mon, 5 Dec 2022 02:14:23 -0300 Subject: [PATCH] Add resetThread() function --- src/chatgpt-api.ts | 8 ++++++++ src/example.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/chatgpt-api.ts b/src/chatgpt-api.ts index bf1933e..770ca18 100644 --- a/src/chatgpt-api.ts +++ b/src/chatgpt-api.ts @@ -187,6 +187,14 @@ export class ChatGPTAPI { } while (true) } + async resetThread() { + const resetButton = await this._page.$('nav > a:nth-child(1)') + + if (!resetButton) throw new Error('not signed in') + + await resetButton.click() + } + async close() { await this._browser.close() this._page = null diff --git a/src/example.ts b/src/example.ts index 4981874..93ccb4f 100644 --- a/src/example.ts +++ b/src/example.ts @@ -47,9 +47,16 @@ async function main() { // Wait forever; useful for debugging chromium sessions // await new Promise(() => {}) + await api.resetThread() + + const newResponse = await api.sendMessage( + // 'Write a TypeScript function for conway sort.' + 'Write a javascript version of bubble sort. Do not include example usage.' + ) + await api.close() - return response + return newResponse } main().then((res) => {