aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/apis/gpt/GPT.ts2
-rw-r--r--src/client/views/nodes/DataVizBox/DataVizBox.tsx34
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx3
3 files changed, 38 insertions, 1 deletions
diff --git a/src/client/apis/gpt/GPT.ts b/src/client/apis/gpt/GPT.ts
index 05007960d..184173784 100644
--- a/src/client/apis/gpt/GPT.ts
+++ b/src/client/apis/gpt/GPT.ts
@@ -12,6 +12,7 @@ enum GPTCallType {
DESCRIBE = 'describe',
MERMAID = 'mermaid',
DATA = 'data',
+ TEMPLATE = "template"
}
type GPTCallOpts = {
@@ -53,6 +54,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 name, type, and desc: {"template_type":"stacked","fieldVals":[{"title":"name","tlx":"-.7","tly":"-.9","brx":".7","bry":"-.7"},{"title":"type","tlx":"-.9","tly":"-.4","brx":".9","bry":"0"},{"title":"desc","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. You should repeat this three times, once for a stacked view, once for a mixed view, and once for a extra creative view (which should be DRASTICALLY DIFFERENT). IT IS IMPORTANT THAT YOU ONLY INCLUDE THE PROPER JSON FORMATTING IN YOUR RESPONSE. IT IS ALSO IMPORTANT THAT NO RECTANGLES OVERLAP'}
};
let lastCall = '';
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index 1994f1b01..9b7fb4320 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -42,6 +42,7 @@ import { data } from 'jquery';
import { listSpec } from '../../../../fields/Schema';
import { ObjectField } from '../../../../fields/ObjectField';
import { Id } from '../../../../fields/FieldSymbols';
+import { GPTCallType, gptAPICall } from '../../../apis/gpt/GPT';
export enum DataVizView {
TABLE = 'table',
@@ -567,6 +568,39 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
this.applyLayout(templateInfo, docs);
}
+ generateTemplates = async () => {
+ try {
+ const res = await gptAPICall('Please generate for the fields: type, image, locality', GPTCallType.TEMPLATE);
+
+ if (res) {
+ const templates: {template_type: string, fieldVals: {title: string, tlx: string, tly: string, brx: string, bry: string}[]}[] = JSON.parse(res);
+ console.log(templates);
+ this.createGeneratedTemplates(templates, 500, 500);
+ //console.log(res);
+ }
+ } catch (err) {
+ console.error(err);
+ }
+
+ }
+
+ createGeneratedTemplates = (layouts: {template_type: string, fieldVals: {title: string, tlx: string, tly: string, brx: string, bry: string}[]}[], tempWidth: number, tempHeight: number) => {
+ const mainCollection = this.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
+
+ layouts.forEach(layout => {
+ const fields: Doc[] = layout.fieldVals.map(field => {
+ const left: number = Number(field.tlx) * tempWidth / 2; const top: number = Number(field.tly) * tempHeight / 2; //prettier-ignore
+ const right: number = Number(field.brx) * tempWidth / 2; const bottom: number = Number(field.bry) * tempHeight / 2; //prettier-ignore
+ const height = bottom - top; const width = right - left; //prettier-ignore
+ const doc = Docs.Create.TextDocument('', { _height: height, _width: width, title: field.title, x: left, y: top });
+ return doc;
+ });
+
+ const template = Docs.Create.FreeformDocument(fields, { _height: tempHeight, _width: tempWidth, title: layout.template_type, x: 400, y: 400 });
+ mainCollection.addDocument(template);
+ });
+ }
+
createBasicTemplates = (colsToLayout: {width: number, height: number, x: number, y: number, title: string}[]) => {
const mainCollection = this.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
index 7993cab28..411257ff7 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
@@ -551,7 +551,8 @@ export class DocCreatorMenu extends ObservableReactComponent<{}> {
{width: 300, height: 300, x: -150, y: -100, title: 'image'},
{width: 200, height: 50, x: -100, y: -200, title: 'description'},
]
- this._dataViz?.createBasicTemplates(temps);
+ this._dataViz?.generateTemplates();
+ //this._dataViz?.createBasicTemplates(temps);
}
get renderSelectedViewType(){