-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpt.js
38 lines (30 loc) · 942 Bytes
/
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
37
38
// Trial file
const { spawn } = require("child_process");
const pythonProcess = spawn("python", ["dummy.py"]);
pythonProcess.stdout.on("data", (data) => {
const outputText = data.toString().trim();
if (outputText !== 0) {
getAiResponse(outputText);
}
});
// function myMethod(text) {
// console.log(`Received output text: ${text}`);
// }
const { Configuration, OpenAIApi } = require("openai");
require('dotenv').config();
const apiKey = process.env.OPENAI_API_KEY;
const configuration = new Configuration({
apiKey: apiKey,
});
async function getAiResponse(topic) {
const openai = new OpenAIApi(configuration);
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: "You are a therapist. Answer like a therapist who cares about their patients." + topic,
max_tokens: 1024,
n: 1,
stop: null,
temperature: 0.7
});
console.log(completion.data.choices[0].text);
}