aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-03-14 16:34:21 -0400
committerbobzel <zzzman@gmail.com>2024-03-14 16:34:21 -0400
commit92879a2f211f5e5c3c5fe5b28bd25a6f22d274ee (patch)
tree93acd9b620c1bc569b385ac5d89b35cf9b6fb88f /src
parent0fcfcdf78a7736b4ecb414f6127020bbcceee267 (diff)
Added a GPT capability to comparison boxes ..
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/gpt/GPT.ts6
-rw-r--r--src/client/views/nodes/ComparisonBox.tsx27
2 files changed, 28 insertions, 5 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index cea862330..fb51278ae 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -14,9 +14,9 @@ type GPTCallOpts = {
};
const callTypeMap: { [type: string]: GPTCallOpts } = {
- summary: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: 'Summarize this text in simpler terms: ' },
- edit: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: 'Reword this: ' },
- completion: { model: 'text-davinci-003', maxTokens: 256, temp: 0.5, prompt: '' },
+ summary: { model: 'gpt-3.5-turbo-instruct', maxTokens: 256, temp: 0.5, prompt: 'Summarize this text in simpler terms: ' },
+ edit: { model: 'gpt-3.5-turbo-instruct', maxTokens: 256, temp: 0.5, prompt: 'Reword this: ' },
+ completion: { model: 'gpt-3.5-turbo-instruct', maxTokens: 256, temp: 0.5, prompt: '' },
};
/**
diff --git a/src/client/views/nodes/ComparisonBox.tsx b/src/client/views/nodes/ComparisonBox.tsx
index 2b57178f4..e759030f5 100644
--- a/src/client/views/nodes/ComparisonBox.tsx
+++ b/src/client/views/nodes/ComparisonBox.tsx
@@ -4,7 +4,7 @@ import { observer } from 'mobx-react';
import * as React from 'react';
import { emptyFunction, returnFalse, returnNone, returnZero, setupMoveUpEvents } from '../../../Utils';
import { Doc, Opt } from '../../../fields/Doc';
-import { DocCast, NumCast, StrCast } from '../../../fields/Types';
+import { DocCast, NumCast, RTFCast, StrCast } from '../../../fields/Types';
import { DocUtils, Docs } from '../../documents/Documents';
import { DragManager, dropActionType } from '../../util/DragManager';
import { undoBatch } from '../../util/UndoManager';
@@ -16,6 +16,8 @@ import { FieldView, FieldViewProps } from './FieldView';
import { PinProps, PresBox } from './trails';
import { FormattedTextBox } from './formattedText/FormattedTextBox';
import { RichTextField } from '../../../fields/RichTextField';
+import { GPTCallType, gptAPICall } from '../../apis/gpt/GPT';
+import { DocData } from '../../../fields/DocSymbols';
@observer
export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>() implements ViewBoxInterface {
@@ -174,8 +176,29 @@ export class ComparisonBox extends ViewBoxAnnotatableComponent<FieldViewProps>()
const displayDoc = (which: string) => {
const whichDoc = DocCast(this.dataDoc[which]);
const targetDoc = DocCast(whichDoc?.annotationOn, whichDoc);
+ const subjectText = RTFCast(this.Document[this.fieldKey])?.Text;
// if there is no Doc in the first comparison slot, but the comparison box's fieldKey slot has a RichTextField, then render a text box to show the contents of the document's field key slot
- const layoutTemplateString = !targetDoc && which.endsWith('1') && this.Document[this.fieldKey] instanceof RichTextField ? FormattedTextBox.LayoutString(this.fieldKey) : undefined;
+ // of if there is no Doc in the second comparison slot, but the second slot has a RichTextField, then render a text box to show the contents of the document's field key slot
+ const layoutTemplateString = !targetDoc
+ ? which.endsWith('1') && subjectText !== undefined
+ ? FormattedTextBox.LayoutString(this.fieldKey)
+ : which.endsWith('2') && (this.Document[which] instanceof RichTextField || typeof this.Document[which] === 'string')
+ ? FormattedTextBox.LayoutString(which)
+ : undefined
+ : undefined;
+
+ // A bit hacky to try out the concept of using GPT to fill in flashcards -- this whole process should probably be packaged into a script to be more generic.
+ // If the second slot doesn't have anything in it, but the fieldKey slot has text
+ // and the fieldKey + "_alternate" has a text that incldues "--TEXT--", then
+ // treat the fieldKey + "_altenrate" text as a GPT query parameterized by the fieldKey text
+ // Call GPT to fill in an "answer" value in the second slot.
+ if (which.endsWith('2') && !layoutTemplateString && !targetDoc) {
+ const queryText = RTFCast(this.Document[this.fieldKey + '_alternate'])?.Text;
+ if (queryText?.includes('--TEXT--') && subjectText) {
+ this.Document[DocData][this.fieldKey + '_2'] = '';
+ gptAPICall(queryText?.replace('--TEXT--', subjectText), GPTCallType.COMPLETION).then(value => (this.Document[DocData][this.fieldKey + '_2'] = value.trim()));
+ }
+ }
return targetDoc || layoutTemplateString ? (
<>
<DocumentView