From 4475adee0f13d9ec407aff6a47094c7ce808af0c Mon Sep 17 00:00:00 2001 From: Sophie Zhang Date: Wed, 22 Feb 2023 17:35:26 -0500 Subject: added GPT summarization functionality --- src/client/views/pdf/AnchorMenu.tsx | 43 +++++++++++++++++++++++++++++++++++++ src/client/views/pdf/GPTPopup.scss | 9 ++++++++ src/client/views/pdf/GPTPopup.tsx | 19 ++++++++++++++++ src/client/views/pdf/PDFViewer.tsx | 22 ++++++++++++++++++- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/client/views/pdf/GPTPopup.scss create mode 100644 src/client/views/pdf/GPTPopup.tsx (limited to 'src/client/views/pdf') diff --git a/src/client/views/pdf/AnchorMenu.tsx b/src/client/views/pdf/AnchorMenu.tsx index c53cc608c..63c8f9145 100644 --- a/src/client/views/pdf/AnchorMenu.tsx +++ b/src/client/views/pdf/AnchorMenu.tsx @@ -10,6 +10,8 @@ import { SelectionManager } from '../../util/SelectionManager'; import { AntimodeMenu, AntimodeMenuProps } from '../AntimodeMenu'; import { LinkPopup } from '../linking/LinkPopup'; import { ButtonDropdown } from '../nodes/formattedText/RichTextMenu'; +import { gptSummarize } from '../../apis/gpt/Summarization'; +import { GPTPopup } from './GPTPopup'; import './AnchorMenu.scss'; @observer @@ -43,10 +45,30 @@ export class AnchorMenu extends AntimodeMenu { @observable public Highlighting: boolean = false; @observable public Status: 'marquee' | 'annotation' | '' = ''; + // GPT additions (flow 2) + @observable private summarizedText: string = ''; + @observable private showGPTPopup: boolean = false; + @action + setGPTPopupVis = (vis: boolean) => { + this.showGPTPopup = vis; + }; + @action + setSummarizedText = (txt: string) => { + this.summarizedText = txt; + }; + + private selectedText: string = ''; + setSelectedText = (txt: string) => { + this.selectedText = txt; + }; + public onMakeAnchor: () => Opt = () => undefined; // Method to get anchor from text search public OnCrop: (e: PointerEvent) => void = unimplementedFunction; public OnClick: (e: PointerEvent) => void = unimplementedFunction; + public OnSummary: (e: PointerEvent) => Promise = () => { + return new Promise(() => {}); + }; public OnAudio: (e: PointerEvent) => void = unimplementedFunction; public StartDrag: (e: PointerEvent, ele: HTMLElement) => void = unimplementedFunction; public StartCropDrag: (e: PointerEvent, ele: HTMLElement) => void = unimplementedFunction; @@ -83,11 +105,26 @@ export class AnchorMenu extends AntimodeMenu { () => SelectionManager.Views(), selected => { this._showLinkPopup = false; + this.setGPTPopupVis(false); AnchorMenu.Instance.fadeOut(true); } ); } + getGPTSummary = (e: React.PointerEvent) => { + setupMoveUpEvents(this, e, returnFalse, returnFalse, e => this.OnSummary?.(e)); + }; + + invokeGPT = async (e: React.PointerEvent) => { + this.setGPTPopupVis(true); + const res = await gptSummarize(this.selectedText); + if (res) { + this.setSummarizedText(res); + } else { + this.setSummarizedText('Something went wrong.'); + } + }; + pointerDown = (e: React.PointerEvent) => { setupMoveUpEvents( this, @@ -192,6 +229,12 @@ export class AnchorMenu extends AntimodeMenu { + Summarize with GPT-3}> + + + {AnchorMenu.Instance.OnAudio === unimplementedFunction ? null : ( Click to Record Annotation}>