kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
46 wiersze
902 B
TypeScript
46 wiersze
902 B
TypeScript
![]() |
import dotenv from 'dotenv-safe'
|
||
|
|
||
|
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)
|
||
|
})
|