aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraidahosa1 <aisosa_idahosa@brown.edu>2024-09-17 08:44:47 -0400
committeraidahosa1 <aisosa_idahosa@brown.edu>2024-09-17 08:44:47 -0400
commit4ba23252ca23a6017974c31364d00c0a1859e45e (patch)
tree672a1b8cd697292871e6fcc261d17ab886f7f7e0 /src
parent4e34335e600b5d9d29e8a4af99fda6b2a6d3ba69 (diff)
cleaning up
Diffstat (limited to 'src')
-rw-r--r--src/client/views/pdf/GPTPopup/GPTPopup.tsx109
1 files changed, 25 insertions, 84 deletions
diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
index 1b44508d7..2d8547dcd 100644
--- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx
+++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
@@ -205,62 +205,42 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
const selected = DocumentView.SelectedDocs().lastElement();
- const questionText = 'Question: ' + StrCast(selected['gptInputText']);
-
- if (StrCast(selected['gptRubric']) === '') {
- const rubricText = 'Rubric: ' + await this.generateRubric(StrCast(selected['gptInputText']), selected)
- }
-
- const rubricText = 'Rubric: ' + (StrCast(selected['gptRubric']))
- // const rubricText = 'Rubric: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text);
- const queryText = questionText + ' UserAnswer: ' + this.quizAnswer + '. ' + 'Rubric' + rubricText;
-
- try {
- const res = await gptAPICall(queryText, GPTCallType.QUIZ);
- if (!res) {
- console.error('GPT call failed');
- return;
- }
- console.log(res)
- this.setQuizResp(res)
- this.conversationArray.push(res)
-
- this.setLoading(false);
- this.setSortDone(true);
-
- // this._outputValue = res;
- } catch (err) {
- console.error('GPT call failed');
- }
-
-
- if (this.onQuizRandom){
- this.onQuizRandom()
- }
+ const questionText = 'Question: ' + StrCast(selected['gptInputText']);
+ if (StrCast(selected['gptRubric']) === '') {
+ const rubricText = 'Rubric: ' + await this.generateRubric(StrCast(selected['gptInputText']), selected)
+ }
-
+ const rubricText = 'Rubric: ' + (StrCast(selected['gptRubric']))
+ const queryText = questionText + ' UserAnswer: ' + this.quizAnswer + '. ' + 'Rubric' + rubricText;
+ try {
+ const res = await gptAPICall(queryText, GPTCallType.QUIZ);
+ if (!res) {
+ console.error('GPT call failed');
+ return;
+ }
+ console.log(res)
+ this.setQuizResp(res)
+ this.conversationArray.push(res)
- // switch(quizType){
- // default:
-
- // }
+ this.setLoading(false);
+ this.setSortDone(true);
+ } catch (err) {
+ console.error('GPT call failed');
+ }
-
+ if (this.onQuizRandom){
+ this.onQuizRandom()
+ }
}
generateRubric = async (inputText: string, doc:Doc) => {
try {
- const res = await gptAPICall(inputText, GPTCallType.RUBRIC);
- console.log(res + "rubbbb")
- // if (!res) {
- // console.error('GPT call failed');
- // return;
- // }
+ const res = await gptAPICall(inputText, GPTCallType.RUBRIC);
doc['gptRubric']= res;
return res
} catch (err) {
@@ -326,8 +306,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
break
}
-
- // const res = await gptAPICall(this.sortDesc, GPTCallType.SUBSET, this.chatSortPrompt);
// Trigger the callback with the result
if (this.onSortComplete) {
this.onSortComplete(res || 'Something went wrong :(', questionNumber, questionType.split(' ').slice(1).join(' '));
@@ -356,44 +334,6 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
this.setSortDone(true);
};
-
- // /**
- // * Sorts cards in the CollectionCardDeckView
- // */
- // generateSort = async () => {
- // console.log(this.chatSortPrompt + "USER PROMPT")
- // this.setLoading(true);
- // this.setSortDone(false);
-
- // if (this.regenerateCallback) {
- // await this.regenerateCallback();
- // }
-
- // try {
- // const res = await gptAPICall(this.sortDesc, GPTCallType.SORT, this.chatSortPrompt);
-
- // // Trigger the callback with the result
- // if (this.onSortComplete) {
- // this.onSortComplete(res || 'Something went wrong :(');
-
- // // Extract explanation surrounded by ------ at the top or both at the top and bottom
- // const explanationMatch = res.match(/------\s*([\s\S]*?)\s*(?:------|$)/) || [];
- // const explanation = explanationMatch[1] ? explanationMatch[1].trim() : 'No explanation found';
-
- // // Set the extracted explanation to sortRespText
- // this.setSortRespText(explanation);
-
- // console.log(res);
- // }
- // } catch (err) {
- // console.error(err);
- // }
-
- // this.setLoading(false);
- // this.setSortDone(true);
- // };
-
-
/**
* Generates a Dalle image and uploads it to the server.
*/
@@ -656,6 +596,7 @@ export class GPTPopup extends ObservableReactComponent<GPTPopupProps> {
<input
className="searchBox-input"
defaultValue=""
+ value={isSort ? this.chatSortPrompt : this.quizAnswer} // Controlled input
autoComplete="off"
onChange={isSort ? this.sortPromptChanged : this.quizAnswerChanged}
onKeyDown={(e) => {