-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
davinci.js
executable file
·27 lines (24 loc) · 874 Bytes
/
davinci.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env node
const { createInterface } = require('readline')
const { Configuration, OpenAIApi } = require('openai')
const configuration = new Configuration({ apiKey: process.env.npm_config_openai_secret || process.env.OPENAI_API_KEY })
setImmediate(function next (ai, cli, { argv } = process) {
cli.question('> ', async (prompt) => {
try {
const { data: { choices: [{ text: answer }] } } = await ai.createCompletion({
model: 'text-davinci-003',
prompt,
temperature: 0.25,
max_tokens: 1536,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0
})
cli.write(`${answer.trimStart()}\n`)
} catch (err) {
console.error(err)
} finally {
next(ai, cli, { argv })
}
})
}, new OpenAIApi(configuration), createInterface({ input: process.stdin, output: process.stdout }))