kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
36 wiersze
622 B
TypeScript
36 wiersze
622 B
TypeScript
import dotenv from 'dotenv-safe'
|
|
import { oraPromise } from 'ora'
|
|
|
|
import { ChatGPTAPI } from '../src'
|
|
|
|
dotenv.config()
|
|
|
|
/**
|
|
* Demo CLI for testing the GPT-4 model.
|
|
*
|
|
* ```
|
|
* npx tsx demos/demo-gpt-4.ts
|
|
* ```
|
|
*/
|
|
async function main() {
|
|
const api = new ChatGPTAPI({
|
|
apiKey: process.env.OPENAI_API_KEY,
|
|
debug: true,
|
|
completionParams: {
|
|
model: 'gpt-4'
|
|
}
|
|
})
|
|
|
|
const prompt = 'When should you use Python vs TypeScript?'
|
|
|
|
const res = await oraPromise(api.sendMessage(prompt), {
|
|
text: prompt
|
|
})
|
|
console.log(res.text)
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|