forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add onProgress to ChatGPTAPIBrowser.sendMessage
- Loading branch information
1 parent
525524b
commit e0fd5f4
Showing
5 changed files
with
142 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import dotenv from 'dotenv-safe' | ||
import { oraPromise } from 'ora' | ||
|
||
import { ChatGPTAPIBrowser } from '../src' | ||
|
||
dotenv.config() | ||
|
||
/** | ||
* Demo CLI for testing the `onProgress` handler. | ||
* | ||
* ``` | ||
* npx tsx demos/demo-on-progress.ts | ||
* ``` | ||
*/ | ||
async function main() { | ||
const email = process.env.OPENAI_EMAIL | ||
const password = process.env.OPENAI_PASSWORD | ||
|
||
const api = new ChatGPTAPIBrowser({ | ||
email, | ||
password, | ||
debug: false, | ||
minimize: true | ||
}) | ||
await api.initSession() | ||
|
||
const prompt = | ||
'Write a python version of bubble sort. Do not include example usage.' | ||
|
||
console.log(prompt) | ||
|
||
const res = await api.sendMessage(prompt, { | ||
onProgress: (partialResponse) => { | ||
console.log('p') | ||
console.log('progress', partialResponse?.response) | ||
} | ||
}) | ||
console.log(res.response) | ||
|
||
// close the browser at the end | ||
await api.closeSession() | ||
} | ||
|
||
main().catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters