diff --git a/legacy/demos/demo-gpt-4.ts b/legacy/demos/demo-gpt-4.ts new file mode 100644 index 00000000..5f312518 --- /dev/null +++ b/legacy/demos/demo-gpt-4.ts @@ -0,0 +1,35 @@ +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) +})