blob: 931e0e48fea6482179457b27ec5460674993c386 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { Configuration, OpenAIApi } from 'openai';
const gptSummarize = async (text: string) => {
text += '.';
try {
const configuration = new Configuration({
apiKey: process.env.OPENAI_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createCompletion({
model: 'text-curie-001',
max_tokens: 256,
temperature: 0.7,
prompt: `Summarize this text in one sentence: ${text}`,
});
return response.data.choices[0].text;
} catch (err) {
console.log(err);
return '';
}
};
export { gptSummarize };
|