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/nodes/WebBox.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/client/views/nodes') diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx index d0d638e98..996028ec8 100644 --- a/src/client/views/nodes/WebBox.tsx +++ b/src/client/views/nodes/WebBox.tsx @@ -36,6 +36,7 @@ import { VideoBox } from './VideoBox'; import './WebBox.scss'; import React = require('react'); import { DragManager } from '../../util/DragManager'; +import { gptSummarize } from '../../apis/gpt/Summarization'; const { CreateImage } = require('./WebBoxRenderer'); const _global = (window /* browser */ || global) /* node */ as any; const htmlToText = require('html-to-text'); @@ -58,6 +59,21 @@ export class WebBox extends ViewBoxAnnotatableComponent(); private _searchString = ''; + // GPT Additions + private _summaryText: string = ''; + private _selectionText: string = ''; + setSummaryText = async () => { + try { + const summary = await gptSummarize(this.selectionText()); + this._summaryText = `Summary: ${summary}`; + } catch (err) { + console.log(err); + this._summaryText = 'Failed to fetch summary.'; + } + }; + summaryText = () => this._summaryText; + selectionText = () => this._selectionText; + private get _getAnchor() { return AnchorMenu.Instance?.GetAnchor; } @@ -341,6 +357,7 @@ export class WebBox extends ViewBoxAnnotatableComponent this.createTextAnnotation(sel, !sel.isCollapsed ? sel.getRangeAt(0) : undefined); AnchorMenu.Instance.jumpTo(e.clientX * scale + mainContBounds.translateX, e.clientY * scale + mainContBounds.translateY - NumCast(this.layoutDoc._scrollTop) * scale); } @@ -1017,6 +1034,8 @@ export class WebBox extends ViewBoxAnnotatableComponent -- cgit v1.2.3-70-g09d2