diff options
Diffstat (limited to 'src/client/views/nodes')
| -rw-r--r-- | src/client/views/nodes/ComparisonBox.tsx | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx index 00ca0078e..9b75feba8 100644 --- a/src/client/views/nodes/ComparisonBox.tsx +++ b/src/client/views/nodes/ComparisonBox.tsx @@ -451,36 +451,33 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() const senArr = text?.split('Question: ') ?? []; const collectionArr: Doc[] = []; for (let i = 1; i < senArr.length; i++) { - const newDoc = Docs.Create.ComparisonDocument(senArr![i], { _layout_isFlashcard: true, _width: 300, _height: 300 }); + const newDoc = Docs.Create.ComparisonDocument(senArr[i], { _layout_isFlashcard: true, _width: 300, _height: 300 }); - if (StrCast(senArr![i]).includes('Keyword: ')) { + if (senArr[i].includes('Keyword: ')) { const question = StrCast(senArr![i]).split('Keyword: '); - const img = await this.fetchImages(question[1]); - const textSide1 = question[0].includes('Answer: ') ? question[0].split('Answer: ')[0] : question[0]; - const textDoc1 = Docs.Create.TextDocument(question[0]); - const rtfiel = new RichTextField( - JSON.stringify({ - doc: { - type: 'doc', - content: [ - { - type: 'paragraph', - attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, - content: [ - { type: 'text', text: question[0].includes('Answer: ') ? question[0].split('Answer: ')[0] : question[0] }, - { type: 'dashDoc', attrs: { width: '200px', height: '200px', title: 'dashDoc', float: 'unset', hidden: false, docId: img![Id] } }, - ], - }, - ], - }, - selection: { type: 'text', anchor: 2, head: 2 }, - }), - textSide1 - ); - - textDoc1[DocData].text = rtfiel; - DocCast(newDoc)[DocData][this.fieldKey + '_1'] = textDoc1; - DocCast(newDoc)[DocData][this.fieldKey + '_0'] = Docs.Create.TextDocument(question[0].includes('Answer: ') ? question[0].split('Answer: ')[1] : question[1]); + const questionTxt = question[0].includes('Answer: ') ? question[0].split('Answer: ')[0] : question[0]; + const answerTxt = question[0].includes('Answer: ') ? question[0].split('Answer: ')[1] : question[1]; + this.fetchImages(question[1]).then(img => { + const rtfiel = new RichTextField( + JSON.stringify({ + // this is a RichText json that has the question text placed above a related image + doc: { + type: 'doc', + content: [ + { + type: 'paragraph', + attrs: { align: null, color: null, id: null, indent: null, inset: null, lineSpacing: null, paddingBottom: null, paddingTop: null }, + content: [{ type: 'text', text: questionTxt }, img ? { type: 'dashDoc', attrs: { width: '200px', height: '200px', title: 'dashDoc', float: 'unset', hidden: false, docId: img[Id] } } : {}], + }, + ], + }, + selection: { type: 'text', anchor: 2, head: 2 }, + }), + questionTxt + ); + newDoc[DocData][this.fieldKey + '_1'] = Docs.Create.TextDocument(questionTxt, { text: rtfiel }); + newDoc[DocData][this.fieldKey + '_0'] = Docs.Create.TextDocument(answerTxt); + }); } collectionArr.push(newDoc); @@ -493,8 +490,8 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() */ askGPT = async (callType: GPTCallType): Promise<string | undefined> => { const questionText = 'Question: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_1']).text)?.Text); - const rubricText = ' Rubric: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); - const queryText = questionText + ' UserAnswer: ' + this._inputValue + '. ' + rubricText; + // const rubricText = ' Rubric: ' + StrCast(RTFCast(DocCast(this.dataDoc[this.fieldKey + '_0']).text)?.Text); + // const queryText = questionText + ' UserAnswer: ' + this._inputValue + '. ' + rubricText; this._loading = true; if (callType == GPTCallType.CHATCARD) { @@ -504,7 +501,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() } } try { - console.log(queryText); const res = await gptAPICall(questionText, GPTCallType.FLASHCARD); if (!res) { console.error('GPT call failed'); @@ -513,7 +509,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() if (callType == GPTCallType.CHATCARD) { DocCast(this.dataDoc[this.props.fieldKey + '_0'])[DocData].text = res; } else if (callType == GPTCallType.QUIZ) { - console.log(this._inputValue); this._frontSide = true; this._outputValue = res.replace(/UserAnswer/g, "user's answer").replace(/Rubric/g, 'rubric'); } else if (callType === GPTCallType.FLASHCARD) { @@ -531,13 +526,12 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() layoutHeight = () => NumCast(this.layoutDoc.height, 200); findImageTags = async () => { - const c = this.DocumentView?.().ContentDiv!.getElementsByTagName('img'); - if (c?.length === 0) await this.askGPT(GPTCallType.CHATCARD); + const c = this.DocumentView?.().ContentDiv?.getElementsByTagName('img'); + if (c?.length === 0) this.askGPT(GPTCallType.CHATCARD); if (c) { this._loading = true; for (const i of c) { - console.log(i); - if (i.className !== 'ProseMirror-separator') await this.getImageDesc(i.src); + if (i.className !== 'ProseMirror-separator') this.getImageDesc(i.src); } this._loading = false; } @@ -611,7 +605,6 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() fetchImages = async (selection: string) => { try { const { data } = await axios.get(`${API_URL}?query=${selection}&page=1&per_page=${1}&client_id=Q4zruu6k6lum2kExiGhLNBJIgXDxD6NNj0SRHH_XXU0`); - console.log(data.results); const imageSnapshot = Docs.Create.ImageDocument(data.results[0].urls.small, { _nativeWidth: Doc.NativeWidth(this.layoutDoc), _nativeHeight: Doc.NativeHeight(this.layoutDoc), |
