-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.js
34 lines (29 loc) · 1.32 KB
/
extract.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
// extract.js
const axios = require('axios');
const openaiApiKey = process.env.OPENAI_API_KEY;
async function extractText(jsonObject) {
try {
// Assuming jsonObject contains a field 'text' for the command
const cmd = jsonObject['text'];
const prompt = "Summarize the position of the moderators on the topic of discussion in Korean with appropriate evidence. Present the summary in a consistent JSON format with each moderator's name and comment as separate objects within an array named 'moderators'. Each object should have 'name' and 'comment' as properties.";
const payload = {
model: "gpt-4-1106-preview",
response_format: {"type": "json_object"},
messages: [
{"role": "system", "content": cmd},
{"role": "user", "content": prompt}
]
};
const response = await axios.post('https://api.openai.com/v1/chat/completions', payload, {
headers: {
'Authorization': `Bearer ${openaiApiKey}`,
'Content-Type': 'application/json'
}
});
return response.data;
} catch (err) {
console.error("Error in extractText:", err);
throw err; // Rethrowing the error so it can be handled by the caller
}
}
module.exports = { extractText };