aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/apis/gpt/GPT.ts2
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx85
2 files changed, 76 insertions, 11 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 365e7a804..f1e7b600b 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -55,7 +55,7 @@ const callTypeMap: { [type: string]: GPTCallOpts } = {
temp: 0,
prompt: 'List unique differences between the content of the UserAnswer and Rubric. Before each difference, label it and provide any additional information the UserAnswer missed and explain it in second person without separating it into UserAnswer and Rubric content and additional information. If there are no differences, say correct',
},
- template: { model: 'gpt-4-turbo', maxTokens: 512, temp: 0.5, prompt: 'You are a designer creating basic template options for a user given a set of fields. Your only job is adding blank rectangles to a canvas, one for each field. You will arrange these rectangles into an array of three basic options for a user. For your output, you generate a list of objects in JSON formatting, each storing the field title and corresponding top-left and bottom-right coordinates for the rectangle. The units for your coordinates are -1 to 1 on each axis. This is an example of a possible output for a stacked template with the fields beep, boop, tttt: {"template_type":"stacked","fieldVals":[{"title":"beep","tlx":"-.7","tly":"-.9","brx":".7","bry":"-.7"},{"title":"boop","tlx":"-.9","tly":"-.4","brx":".9","bry":"0"},{"title":"tttt","tlx":"-.9","tly":".1","brx":".9","bry":".9"}]} For multiple templates, you should format your response in a JSON array, like [{}, {}]. Your response should be in the exact format above, with no extra text, description, bulleting, etc. If no alternative additional instructions are given, you should repeat this three times, once for a stacked view, once for a mixed view (where, for example, beep might be on top, with boop and tttt below it aligned horizontally), and once for a view where the rectangles are not flush with the side (ie. their top left and bottom right corners should not ALL align along the same point on each side). If one or more fields are some variation of image (ie. IMG, image, photo, etc.), make that rectangle the central focus (bigger, centered, etc.) AND put its "title" field in $$__$$. Fields SHOULD BE IN DIFFERENT ORDERS from template to template (ie. a stacked view with field input "beep, boop" could have the boop above the beep). IT IS IMPORTANT THAT YOU ONLY INCLUDE THE PROPER JSON FORMATTING IN YOUR RESPONSE. IT IS ALSO IMPORTANT THAT NO RECTANGLES OVERLAP. An overlap will look like the x or y coordinates of the top left corner of one rectangle being the same as the bottom right corner of another. There should always be at least a .1 gap. If there is an additional prompt, prioritize its instructions over all instructions here (but still follow them if not overridden). No matter what, ALWAYS GIVE THREE OPTIONS'},
+ template: { model: 'gpt-4-turbo', maxTokens: 512, temp: 0.5, prompt: 'You will be given a list of field descriptions for multiple templates in the format {field #0: “description”}{field #1: “description”}{...}, and a list of column descriptions in the format {“title”: “description}{...}. Your job is to match columns with fields based on their descriptions. Your output should be in the following JSON format: {“Template title”:{“#”: “title”, “#”: “title”, “#”: “title” …}, “Template title”:{“#”: “title”, “#”: “title”, “#”: “title” …}} where “Template title” represents the template, # represents the field # and “title” the title of the column assigned to it. A filled out example might look like {“fivefield2”:{0:”Name”, 1:”Image”, 2:”Caption”, 3:”Position”, 4:”Stats”}, “fivefield3”:{0:”Image”, 1:”Name”, 2:”Caption”, 3:”Stats”, 4:”Position”}. Include one object for each template. IT IS VERY IMPORTANT THAT YOU ONLY INCLUDE TEXT IN THE FORMAT ABOVE, WITH NO ADDITIONS WHATSOEVER. Do not include extraneous ‘#’ characters, ‘column’ for columns, or ‘template’ for templates: ONLY THE TITLES AND NUMBERS. Do this for each template whose fields are described. The descriptions are as follows: ' },
vizsum: { model: 'gpt-4-turbo', maxTokens: 512, temp: 0.5, prompt: 'Your job is to provide brief descriptions for columns in a dataset based on example rows. Your descriptions should be geared towards how each column’s data might fit together into a visual template. Would they make good titles, main focuses, captions, descriptions, etc. Pay special attention to connections between columns, i.e. is there one column that specifically seems to describe/be related to another more than the rest? You should provide your analysis in JSON format like so: {“col1”:”description”, “col2”:”description”, …}. DO NOT INCLUDE ANY OTHER TEXT, ONLY THE JSON.'}
};
let lastCall = '';
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',