From 2b4288efa2f21db46addd19c8884f80dba835f2d Mon Sep 17 00:00:00 2001 From: aidahosa1 Date: Tue, 17 Sep 2024 09:20:54 -0400 Subject: pulling from amster wish me luck --- src/client/views/pdf/GPTPopup/GPTPopup.tsx | 95 +++++++----------------------- 1 file changed, 22 insertions(+), 73 deletions(-) (limited to 'src/client/views/pdf/GPTPopup') diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx index 2d8547dcd..13196f06d 100644 --- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx +++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx @@ -52,6 +52,8 @@ interface GPTPopupProps {} export class GPTPopup extends ObservableReactComponent { // eslint-disable-next-line no-use-before-define static Instance: GPTPopup; + private messagesEndRef: React.RefObject; + @observable private chatMode: boolean = false; private correlatedColumns: string[] = []; @@ -173,29 +175,25 @@ export class GPTPopup extends ObservableReactComponent { this.sortRespText = resp } - //mode where gpt says to select a specific card - // - - @observable chatSortPrompt: string = "" sortPromptChanged = action((e: React.ChangeEvent) => { this.chatSortPrompt = e.target.value; }); - @observable quizAnswer: string = "" quizAnswerChanged = action((e: React.ChangeEvent) => { this.quizAnswer = e.target.value; }); - - @observable correctAnswer: string = '' - @observable setCorrectAnswer = (s: string) => { - this.correctAnswer = s - } + @observable conversationArray: string[] = ["Hi! In this pop up, you can ask ChatGPT questions about your documents and filter / sort them. "] + + /** + * When the cards are in quiz mode in the card view, allows gpt to determine whether the user's answer was correct + * @returns + */ generateQuiz = async () => { this.setLoading(true); this.setSortDone(false); @@ -238,6 +236,12 @@ export class GPTPopup extends ObservableReactComponent { } + /** + * Generates a rubric by which to compare the user's answer to + * @param inputText user's answer + * @param doc the doc the user is providing info about + * @returns gpt's response + */ generateRubric = async (inputText: string, doc:Doc) => { try { const res = await gptAPICall(inputText, GPTCallType.RUBRIC); @@ -253,6 +257,10 @@ export class GPTPopup extends ObservableReactComponent { @observable private regenerateCallback: (() => Promise) | null = null; + /** + * Callback function that causes the card view to update the childpair string list + * @param callback + */ @action public setRegenerateCallback(callback: () => Promise) { this.regenerateCallback = callback; } @@ -271,6 +279,9 @@ export class GPTPopup extends ObservableReactComponent { } + /** + * Generates a response to the user's questoin depending on the type of their question + */ generateCard = async () => { console.log(this.chatSortPrompt + "USER PROMPT") this.setLoading(true); @@ -469,7 +480,6 @@ export class GPTPopup extends ObservableReactComponent { } - private messagesEndRef: React.RefObject; scrollToBottom = () => { @@ -538,7 +548,6 @@ export class GPTPopup extends ObservableReactComponent { ) - @observable conversationArray: string[] = ["Hi! In this pop up, you can ask ChatGPT questions about your documents and filter / sort them. If you're not sure if something is possible-- just ask!"] handleKeyPress = async (e: React.KeyboardEvent, isSort: boolean) => { @@ -563,12 +572,9 @@ export class GPTPopup extends ObservableReactComponent { cardActual = (opt: GPTPopupMode) => { const isSort = opt === GPTPopupMode.SORT - // if (opt === GPTPopupMode.SORT) { return ( - // !this.sortDone ? ( - // <> +
- {/* Chat bubble container with scroll */}
{this.conversationArray.map((message, index) => ( @@ -579,8 +585,6 @@ export class GPTPopup extends ObservableReactComponent { {message}
))} - - {/* Conditional Loading message */} {(!this.cardsDoneLoading || this.loading) && (
... @@ -610,62 +614,7 @@ export class GPTPopup extends ObservableReactComponent { />
- - - // - // ) : ( - //
- //
- //

{this.text === 'Something went wrong :(' ? 'Something went wrong :(' : `${isSort ? this.sortRespText : this.quizRespText}`}

- // this.setSortDone(false)} - // icon={} - // color={StrCast(Doc.UserDoc().userVariantColor)} - // /> - //
- //
- // ) ); - // } else if (opt === GPTPopupMode.QUIZ) { - // return ( - // <> - //
- // { - // if (e.key === 'Enter') { - // this.generateQuiz(); - // } - // e.stopPropagation(); - // }} - // type="text" - // placeholder="What is the selected card?" - // id="search-input" - // style={{ width: '100%' }} - // /> - // {/*
- //
*/} - //
- // - // ); - // } }; sortBox = () => ( -- cgit v1.2.3-70-g09d2