diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-08-31 02:37:15 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-08-31 02:37:15 -0400 |
commit | dbfb364da14c2d080f0c465a5519a25821a477c6 (patch) | |
tree | 46f7864f04251a2fbca1523a2d079e4ee8a47c6c /src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx | |
parent | b839dbde9fa3dfc2488b15a1d96464d54987f38f (diff) |
GPT response working!
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx | 85 |
1 files changed, 75 insertions, 10 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx index af15e6113..245a8124c 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx @@ -29,6 +29,7 @@ import { FieldViewProps } from '../FieldView'; import { CollectionViewType } from '../../../documents/DocumentTypes'; import { dropActionType } from '../../../util/DropActionTypes'; import { ImageBox } from '../ImageBox'; +import { a } from '@react-spring/web'; export enum LayoutType { Stacked = 'stacked', @@ -417,14 +418,16 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const temp = TemplateLayouts.FourField001; - const img: Col = {type: TemplateFieldType.VISUAL, title: 'Image', desc: '', size: FieldSize.LARGE}; - const capt1: Col = {type: TemplateFieldType.TEXT, title: 'Type', desc: '', size: FieldSize.TINY}; + const img: Col = {type: TemplateFieldType.VISUAL, title: 'Image', desc: 'description whpoo', size: FieldSize.LARGE}; + const capt1: Col = {type: TemplateFieldType.TEXT, title: 'Type', desc: 'description hey', size: FieldSize.TINY}; const capt2: Col = {type: TemplateFieldType.TEXT, title: 'Locality', desc: '', size: FieldSize.TINY}; const desc: Col = {type: TemplateFieldType.TEXT, title: 'Description', desc: '', size: FieldSize.LARGE}; - const assignments = {'0': img, '1': capt1, '2': capt2, '3': desc} + // const assignments = {'0': img, '1': capt1, '2': capt2, '3': desc} - this.createEmptyTemplate(temp, assignments); + // this.createEmptyTemplate(temp, assignments); + + console.log(this.assignColsToFields([TemplateLayouts.FourField001, TemplateLayouts.FourField002], this.fieldsInfos)); }; @action addField = () => { @@ -553,7 +556,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { // return new Doc; // } - createEmptyTemplate = (template: TemplateDocInfos, assignments: {[field: number]: Col}) => { + createEmptyTemplate = (template: TemplateDocInfos, assignments: {[field: string]: Col}) => { const fields: Doc[] = []; Object.entries(assignments).forEach(([f, col]) => { @@ -621,13 +624,58 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { return descriptions; }; - assignColsToFields = (templates: TemplateDocInfos[], cols: Col[]) => { + getColByTitle = (title: string) => { return this.fieldsInfos.filter(col => col.title === title)[0]; }; + + @action + assignColsToFields = async(templates: TemplateDocInfos[], cols: Col[]): Promise<[TemplateDocInfos, {[field: number]: Col}][]> => { const fieldDescriptions: string = this.compileFieldDescriptions(templates); const colDescriptions: string = this.compileColDescriptions(cols); + const inputText = fieldDescriptions.concat(colDescriptions); + console.log(inputText) + + ++this._callCount; + const origCount = this._callCount; + + let prompt: string = `(${origCount}) ${inputText}`; + + this._GPTLoading = true; + + try { + const res = await gptAPICall(prompt, GPTCallType.TEMPLATE); + + if (res && this._callCount === origCount) { + console.log('first stage') + this._GPTLoading = false; + const assignments: {[templateTitle: string]: {[field: string]: string}} = JSON.parse(res); + console.log(assignments); + const brokenDownAssignments: [TemplateDocInfos, {[field: number]: Col}][] = []; + Object.entries(assignments).forEach(([tempTitle, assignment]) => { + const template = TemplateLayouts.fieldByTitle(tempTitle); + console.log('template', template) + if (!template) {console.log('returned'); return}; + const toObj = Object.entries(assignment).reduce((a, [fieldNum, colTitle]) => { + console.log('hey', a, fieldNum, colTitle) + a[Number(fieldNum)] = this.getColByTitle(colTitle); + return a; + }, {} as { [field: number]: Col }); + console.log('obj', toObj) + brokenDownAssignments.push([template, toObj]) + }) + return brokenDownAssignments; + } + } catch (err) { + console.error(err); + } + + return []; }; + generatePresetTemplates = async(templates: TemplateDocInfos[], cols: Col[]) => { + + } + get templatesPreviewContents(){ const renderedTemplates: Doc[] = []; @@ -1292,6 +1340,23 @@ export class FieldFuncs { export class TemplateLayouts { + public static fieldByTitle = (title: string): TemplateDocInfos | undefined => { + switch (title){ + case 'fourfield1': + return TemplateLayouts.FourField001; + case 'fourfield2': + return TemplateLayouts.FourField002; + case 'fourfield3': + return TemplateLayouts.FourField003; + case 'threefield1': + return TemplateLayouts.ThreeField001; + default: + break; + } + + return undefined; + } + public static FourField001: TemplateDocInfos = { title: 'fourfield1', width: 416, @@ -1307,7 +1372,7 @@ export class TemplateLayouts { br: [.85, -.85], types: [TemplateFieldType.TEXT], sizes: [FieldSize.TINY], - description: '', + description: 'A title field for very short text that contextualizes the content.', opts: { backgroundColor: 'transparent', } @@ -1316,7 +1381,7 @@ export class TemplateLayouts { br: [.87, .2], types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL], sizes: [FieldSize.MEDIUM, FieldSize.LARGE, FieldSize.HUGE], - description: '', + description: 'The main focus of the template; could be an image, long text, etc.', opts: { cornerRounding: 20, borderColor: '#642B00', @@ -1328,7 +1393,7 @@ export class TemplateLayouts { br: [.8, .35], types: [TemplateFieldType.TEXT], sizes: [FieldSize.TINY, FieldSize.SMALL], - description: '', + description: 'A caption for field #2, very short to short text that contextualizes the content of field #2', opts: { backgroundColor: 'transparent' } @@ -1337,7 +1402,7 @@ export class TemplateLayouts { br: [.87, .96], types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL], sizes: [FieldSize.MEDIUM, FieldSize.LARGE, FieldSize.HUGE], - description: '', + description: 'A medium-sized field for medium/long text or a secondary image that complements the main focus.', opts: { cornerRounding: 15, borderColor: '#642B00', |