diff options
author | Sophie Zhang <sophie_zhang@brown.edu> | 2023-02-27 16:56:02 -0500 |
---|---|---|
committer | Sophie Zhang <sophie_zhang@brown.edu> | 2023-02-27 16:56:02 -0500 |
commit | ed94cc8fb516455dbeea223d0fab25e4fb1c1d78 (patch) | |
tree | 662cee07a6a64fe1b688fc336c46f10574881b44 /src/client/apis/gpt | |
parent | d2be7d2bfec6978238811cc50ad3effd2a19d15d (diff) |
feat: added summarization functionality to WebBox and cleaned up code
Diffstat (limited to 'src/client/apis/gpt')
-rw-r--r-- | src/client/apis/gpt/Summarization.ts | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/client/apis/gpt/Summarization.ts b/src/client/apis/gpt/Summarization.ts index 931e0e48f..c0dcc0267 100644 --- a/src/client/apis/gpt/Summarization.ts +++ b/src/client/apis/gpt/Summarization.ts @@ -1,22 +1,32 @@ 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: 'text-curie-001', - max_tokens: 256, - temperature: 0.7, - prompt: `Summarize this text in one sentence: ${text}`, + model: model, + max_tokens: maxTokens, + temperature: temp, + prompt: `Summarize this text: ${text}`, }); return response.data.choices[0].text; } catch (err) { console.log(err); - return ''; + return 'Error connecting with API.'; } }; |