From fb4304c0e02aef4a0cedabfdc23ef39c4ca0eca8 Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Thu, 23 Feb 2023 13:00:18 -0500 Subject: text --- src/client/apis/gpt/Summarization.ts | 18 +++------------ src/client/views/pdf/AnchorMenu.tsx | 22 ++++++++++++++---- src/client/views/pdf/GPTPopup.scss | 45 +++++++++++++++++++++++++++++++++++- src/client/views/pdf/GPTPopup.tsx | 15 +++++++++++- 4 files changed, 79 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/client/apis/gpt/Summarization.ts b/src/client/apis/gpt/Summarization.ts index 3706c7a5b..931e0e48f 100644 --- a/src/client/apis/gpt/Summarization.ts +++ b/src/client/apis/gpt/Summarization.ts @@ -1,13 +1,14 @@ 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-davinci-003', + model: 'text-curie-001', max_tokens: 256, temperature: 0.7, prompt: `Summarize this text in one sentence: ${text}`, @@ -19,17 +20,4 @@ const gptSummarize = async (text: string) => { } }; -// 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 }; +export { gptSummarize }; diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index 63c8f9145..6bcfbe4c2 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -47,6 +47,7 @@ export class AnchorMenu extends AntimodeMenu { // GPT additions (flow 2) @observable private summarizedText: string = ''; + @observable private loadingSummary: boolean = false; @observable private showGPTPopup: boolean = false; @action setGPTPopupVis = (vis: boolean) => { @@ -56,6 +57,10 @@ export class AnchorMenu extends AntimodeMenu { setSummarizedText = (txt: string) => { this.summarizedText = txt; }; + @action + setLoading = (loading: boolean) => { + this.loadingSummary = loading; + }; private selectedText: string = ''; setSelectedText = (txt: string) => { @@ -98,7 +103,13 @@ export class AnchorMenu extends AntimodeMenu { componentDidMount() { this._disposer2 = reaction( () => this._opacity, - opacity => !opacity && (this._showLinkPopup = false), + opacity => { + if (!opacity) { + this._showLinkPopup = false; + this.setGPTPopupVis(false); + this.setSummarizedText(''); + } + }, { fireImmediately: true } ); this._disposer = reaction( @@ -106,6 +117,7 @@ export class AnchorMenu extends AntimodeMenu { selected => { this._showLinkPopup = false; this.setGPTPopupVis(false); + this.setSummarizedText(''); AnchorMenu.Instance.fadeOut(true); } ); @@ -117,12 +129,14 @@ export class AnchorMenu extends AntimodeMenu { invokeGPT = async (e: React.PointerEvent) => { this.setGPTPopupVis(true); + this.setLoading(true); const res = await gptSummarize(this.selectedText); if (res) { this.setSummarizedText(res); } else { this.setSummarizedText('Something went wrong.'); } + this.setLoading(false); }; pointerDown = (e: React.PointerEvent) => { @@ -229,12 +243,12 @@ export class AnchorMenu extends AntimodeMenu { - Summarize with GPT-3}> - - + {AnchorMenu.Instance.OnAudio === unimplementedFunction ? null : ( Click to Record Annotation}>