-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchat-gpt.js
executable file
·36 lines (31 loc) · 927 Bytes
/
chat-gpt.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
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
let prompt = "";
for(let i = 2; i < process.argv.length; i++){
prompt += process.argv[i] + ' '
}
if(process.argv.length <= 2 || prompt.trim().length == 0){
console.error('No prompt provided to ChatGPT')
process.exit(1)
}
const { Configuration, OpenAIApi } = require('openai');
const configuration = new Configuration({
apiKey: require('./env'),
});
const openai = new OpenAIApi(configuration);
async function generateText() {
const response = await openai.createCompletion({
model: 'text-davinci-003',
prompt: prompt,
temperature: 0,
max_tokens: 1500,
});
if(response.data.choices[0].text){
console.log('===================== Chat-GPT =====================')
console.log(response.data.choices[0].text.toString())
console.log('\n')
}
else{
console.error('No response generated')
}
}
generateText();