import { Configuration, OpenAIApi } from 'openai'; /** * Summarizes the inputted text with OpenAI. * * @param text Text to summarize * @returns Summary of text */ const gptSummarize = async (text: string) => { text += '.'; const model = 'text-curie-001'; // Most advanced: text-davinci-003 const maxTokens = 200; const temp = 0.8; try { const configuration = new Configuration({ apiKey: process.env.OPENAI_KEY, }); const openai = new OpenAIApi(configuration); const response = await openai.createCompletion({ model: model, max_tokens: maxTokens, temperature: temp, prompt: `Summarize this text: ${text}`, }); return response.data.choices[0].text; } catch (err) { console.log(err); return 'Error connecting with API.'; } }; export { gptSummarize };