aboutsummaryrefslogtreecommitdiff
path: root/src/client/views
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views')
-rw-r--r--src/client/views/nodes/DataVizBox/DataVizBox.tsx63
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu.scss6
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx8
3 files changed, 71 insertions, 6 deletions
diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index c0b05b082..808bc182a 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -63,6 +63,8 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
@observable _marqueeing: number[] | undefined = undefined;
@observable _savedAnnotations = new ObservableMap<number, HTMLDivElement[]>();
@observable _specialHighlightedRow: number | undefined = undefined;
+ @observable _GPTSummary: ObservableMap<string, string> | undefined = undefined;
+ @observable _GPTLoading: boolean = false;
constructor(props: FieldViewProps) {
super(props);
@@ -352,13 +354,12 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
},
{ fireImmediately: true }
);
+ this._disposers.contentSummary = reaction(
+ () => this.records,
+ () => this.updateGPTSummary()
+ );
}
- // recs = () => {
- // let csvStr: string = '';
- // this.records[rowId][col]
- // }
-
fetchData = () => {
if (!this.Document.dataViz_asSchema) {
DataVizBox.dataset.set(CsvCast(this.dataDoc[this.fieldKey]).url.href, []); // assign temporary dataset as a lock to prevent duplicate server requests
@@ -476,6 +477,58 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
GPTPopup.Instance.generateDataAnalysis();
});
+ getColSummary = (): string => {
+ let possibleIds: number[] = this.records.map((_, index) => index);
+
+ for (let i = possibleIds.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1));
+ [possibleIds[i], possibleIds[j]] = [possibleIds[j], possibleIds[i]];
+ }
+
+ const rowsToCheck = possibleIds.slice(0, Math.min(10, this.records.length));
+
+ let prompt: string = 'Col titles: ';
+
+ const cols = Array.from(Object.keys(this.records[0])).filter(header => header !== '' && header !== undefined);
+
+ cols.forEach((col, i) => {
+ prompt += `Col #${i}: ${col} ------`
+ })
+
+ prompt += '----------- Rows: '
+
+ rowsToCheck.forEach(row => {
+ prompt += `Row #${row}: `
+ cols.forEach(col => {
+ prompt += `${col}: ${this.records[row][col]} -----`
+ })
+ })
+
+ return prompt;
+ }
+
+ updateGPTSummary = async () => {
+ this._GPTLoading = true;
+
+ const prompt = this.getColSummary();
+
+ try {
+ const res = await gptAPICall(prompt, GPTCallType.VIZSUM);
+
+ if (res) {
+ this._GPTSummary = new ObservableMap();
+ const descs: {[col: string]: string} = JSON.parse(res);
+ for (const [key, val] of Object.entries(descs)) {
+ this._GPTSummary.set(key, val);
+ }
+
+ console.log(res, descs);
+ }
+ } catch (err) {
+ console.error(err);
+ }
+ }
+
getPossibleTemplates = (): Doc[] => {
const linkedDocs: Doc[] = LinkManager.Instance.getAllRelatedLinks(this.Document).map(d => DocCast(LinkManager.getOppositeAnchor(d, this.Document)));
const linkedCollections: Doc[] = linkedDocs.filter(doc => doc.type === 'config').map(doc => DocCast(doc.annotationOn));
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss b/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss
index baed9009b..9b3a02e0f 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.scss
@@ -757,6 +757,7 @@
margin: 5px;
margin-top: 0px;
border-radius: 3px;
+ flex: 0 0 auto;
.properties-wrapper {
display: flex;
@@ -826,6 +827,11 @@
border-radius: 3px;
width: 100%;
height: 100%;
+ resize: none;
+
+ ::-webkit-scrollbar-track {
+ background: none;
+ }
}
.top-right {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
index d3117da22..3218b9765 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
@@ -413,6 +413,8 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps & Co
// const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
// mainCollection.addDocument(doc);
+ //this._dataViz?.getRandomSample();
+ console.log(this._dataViz?._GPTSummary?.get('IMG'))
}
get templatesPreviewContents(){
@@ -809,10 +811,14 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps & Co
</div>
</div>
</div>
- <textarea className='field-description-container' placeholder={'Enter description to enhance template generation'} />
+ <textarea className='field-description-container' placeholder={'Add a description to help with template generation.'} />
+ this._dataViz?._GPTSummary?.get(field.title) ??
<button className='docCreatorMenu-menu-button section-reveal-options top-right' onPointerDown={e => this.setUpButtonClick(e, () => this.removeField(field))}>
<FontAwesomeIcon icon='trash'/>
</button>
+ <button className='docCreatorMenu-menu-button section-reveal-options top-right' onPointerDown={e => this.setUpButtonClick(e, () => this.removeField(field))}>
+ <FontAwesomeIcon icon='lightbulb'/>
+ </button>
</div>
)}
</div>