blob: 3706c7a5bea9b31db85d194fdc85a31e44c70b9d (
plain)
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
|
import { Configuration, OpenAIApi } from 'openai';
const gptSummarize = async (text: string) => {
try {
const configuration = new Configuration({
apiKey: process.env.OPENAI_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createCompletion({
model: 'text-davinci-003',
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 '';
}
};
// Summarizing with the MeaningCloud API
const fetchSummary = async (text: string, numSentences?: number) => {
const key = '0b41c071f838e573847f477e8f69e9d9';
const queryURL = '';
const sentences = numSentences ? numSentences : 3;
const URL = `https://api.meaningcloud.com/summarization-1.0?key=${key}&txt=${text}&sentences=${sentences}`;
const res = await fetch(URL);
const data = await res.json();
console.log(data.summary);
return data.summary;
};
export { fetchSummary, gptSummarize };
|