-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (27 loc) · 1.03 KB
/
index.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
const dotenv = require("dotenv");
const OpenAI = require("openai");
const axios = require("axios");
dotenv.config();
const { Configuration, OpenAIApi } = OpenAI;
const configuration = new Configuration({
organization: process.env.ORGANIZATION,
apiKey: process.env.API_KEY,
});
const openai = new OpenAIApi(configuration);
exports.handler = async (event, context, callback) => {
const { keyword } = event;
const message = `Tell me in one word what kind of food '${keyword}' is and what the food name of '${keyword}' is. You should tell me in only Korean, Don't ever speak English and follow this rule, {word**word}`;
let answer = "";
let answers = [];
const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: message }],
temperature: 0,
});
if (response.data) {
if (response.data.choices) answer = response.data.choices[0].message.content;
else answer = null;
}
if (answer != null) answers = answer.split("**");
callback(null, { words: answers });
};