-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.js
More file actions
32 lines (27 loc) · 1.12 KB
/
utils.js
File metadata and controls
32 lines (27 loc) · 1.12 KB
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
const jwt = require("jsonwebtoken");
const { Configuration, OpenAIApi } = require("openai"); /* openai 모듈을 불러옵니다.*/
require('dotenv').config();
function parseJWTPayload(token) {
return jwt.verify(token, process.env.JWT_SECRET_KEY, function (err, decoded) {
if (err) throw err;
return decoded;
});
}
const callGpt35 = async (prompt) => {
const configiration = new Configuration({
apiKey: process.env.OPENAI_SECRET_KEY,
organization: process.env.OPENAI_ORGANIZATION,
});
try {
const openai = new OpenAIApi(configiration); /* openai에서 발급 받은 비밀키, 조직ID로 객체를 생성합니다 */
const response = await openai.createChatCompletion({ /* 생성된 객체로 openAI의 여러가지 모델 중 하나인 gpt-3.5-turbo에 요청을 보냅니다. */
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: prompt }],
});
return response.data.choices[0].message;
} catch (error) {
console.error('callGpt35() error >>> ', error);
return null;
}
};
module.exports = {parseJWTPayload, callGpt35};