diff options
-rw-r--r-- | src/client/apis/gpt/GPT.ts | 3 | ||||
-rw-r--r-- | src/client/views/collections/CollectionCarousel3DView.tsx | 11 | ||||
-rw-r--r-- | src/client/views/collections/FlashcardPracticeUI.scss | 2 | ||||
-rw-r--r-- | src/client/views/nodes/ComparisonBox.tsx | 67 |
4 files changed, 41 insertions, 42 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts index 88352110b..e8c6cc02f 100644 --- a/src/client/apis/gpt/GPT.ts +++ b/src/client/apis/gpt/GPT.ts @@ -72,7 +72,6 @@ const callTypeMap: { [type: string]: GPTCallOpts } = { model: 'gpt-4-turbo', maxTokens: 1024, temp: 0.1, //0.3 - prompt: '', prompt: "BRIEFLY (<50 words) describe any differences between the rubric and the user's answer answer in second person. If there are no differences, say correct", }, @@ -125,7 +124,7 @@ let lastResp = ''; * @param inputText Text to process * @returns AI Output */ -const gptAPICall = async (inputTextIn: string, callType: GPTCallType, prompt?: any, dontCache?: boolean) => { +const gptAPICall = async (inputTextIn: string, callType: GPTCallType, prompt?: string, dontCache?: boolean) => { const inputText = [GPTCallType.SUMMARY, GPTCallType.FLASHCARD, GPTCallType.QUIZ, GPTCallType.STACK].includes(callType) ? inputTextIn + '.' : inputTextIn; const opts: GPTCallOpts = callTypeMap[callType]; if (lastCall === inputText && dontCache !== true) return lastResp; diff --git a/src/client/views/collections/CollectionCarousel3DView.tsx b/src/client/views/collections/CollectionCarousel3DView.tsx index 9ccac0e0f..f2ba90c78 100644 --- a/src/client/views/collections/CollectionCarousel3DView.tsx +++ b/src/client/views/collections/CollectionCarousel3DView.tsx @@ -6,7 +6,7 @@ import { returnZero } from '../../../ClientUtils'; import { Utils } from '../../../Utils'; import { Doc, DocListCast, Opt } from '../../../fields/Doc'; import { Id } from '../../../fields/FieldSymbols'; -import { DocCast, NumCast, ScriptCast, StrCast } from '../../../fields/Types'; +import { BoolCast, DocCast, NumCast, ScriptCast, StrCast } from '../../../fields/Types'; import { DocumentType } from '../../documents/DocumentTypes'; import { DragManager } from '../../util/DragManager'; import { Transform } from '../../util/Transform'; @@ -52,7 +52,14 @@ export class CollectionCarousel3DView extends CollectionSubView() { panelHeight = () => this._props.PanelHeight() * this.sideScale; onChildDoubleClick = () => ScriptCast(this.layoutDoc.onChildDoubleClick); isContentActive = () => this._props.isSelected() || this._props.isContentActive() || this._props.isAnyChildContentActive(); - isChildContentActive = () => !!this.isContentActive(); + isChildContentActive = () => + this._props.isContentActive?.() === false + ? false + : this._props.isDocumentActive?.() && (this._props.childDocumentsActive?.() || BoolCast(this.Document.childDocumentsActive)) + ? true + : this._props.childDocumentsActive?.() === false || this.Document.childDocumentsActive === false + ? false + : undefined; contentScreenToLocalXf = () => this._props.ScreenToLocalTransform().scale(this._props.NativeDimScaling?.() || 1); childScreenLeftToLocal = () => this.contentScreenToLocalXf() diff --git a/src/client/views/collections/FlashcardPracticeUI.scss b/src/client/views/collections/FlashcardPracticeUI.scss index c5252bbfa..2f99500f8 100644 --- a/src/client/views/collections/FlashcardPracticeUI.scss +++ b/src/client/views/collections/FlashcardPracticeUI.scss @@ -50,7 +50,7 @@ height: 20px; align-items: center; margin: auto; - // padding: 3px; + padding: 3px; &:hover { color: white; } 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), |