Skip to content

Commit 903124a

Browse files
committed
tab to get started
1 parent 3e78482 commit 903124a

File tree

7 files changed

+59
-16
lines changed

7 files changed

+59
-16
lines changed

py-src/data_formulator/agents/agent_data_load.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313

1414
SYSTEM_PROMPT = '''You are a data scientist to help user infer data types based off the table provided by the user.
15-
Given a dataset provided by the user, identify their type and semantic type, and provide a very short summary of the dataset.
15+
Given a dataset provided by the user,
16+
1. identify their type and semantic type
17+
2. provide a very short summary of the dataset.
18+
3. provide a list of (5-10) explorative questions that can help users get started with data visualizations.
1619
1720
Types to consider include: string, number, date
1821
Semantic types to consider include: Location, Year, Month, Day, Date, Time, DateTime, Range, Duration, Name, Percentage, String, Number
@@ -34,7 +37,8 @@
3437
"field2": {"type": ..., "semantic_type": ..., "sort_order": null},
3538
...
3639
},
37-
"data summary": ... // a short summary of the data
40+
"data summary": ... // a short summary of the data,
41+
"explorative_questions": [...], // a list of explorative questions that can help users get started with data visualizations
3842
}
3943
```
4044
'''
@@ -76,7 +80,13 @@
7680
"total": {"type": "number", "semantic_type": "Number", "sort_order": null},
7781
"group": {"type": "string", "semantic_type": "Range", "sort_order": ["<10000", "10000 to 14999", "15000 to 24999", "25000 to 34999", "35000 to 49999", "50000 to 74999", "75000 to 99999", "100000 to 149999", "150000 to 199999", "200000+"]}
7882
},
79-
"data summary": "The dataset contains information about income distribution across different states in the USA. It includes fields for state names, regions, state IDs, percentage of total income, total income, and income groups."
83+
"data summary": "The dataset contains information about income distribution across different states in the USA. It includes fields for state names, regions, state IDs, percentage of total income, total income, and income groups.",
84+
"explorative_questions": [
85+
"What is the average income across different states?",
86+
"What is the distribution of income across different regions?",
87+
"What is the relationship between income and state ID?",
88+
"What is the relationship between income and region?"
89+
]
8090
}
8191
```
8292
@@ -121,7 +131,13 @@
121131
"sort_order": null
122132
}
123133
},
124-
"data_summary": "This dataset contains weather information for the cities of Seattle and Atlanta. The fields include the date, city name, and temperature readings. The 'Date' field represents dates in a string format, the 'City' field represents city names, and the 'Temperature' field represents temperature values in integer format."
134+
"data_summary": "This dataset contains weather information for the cities of Seattle and Atlanta. The fields include the date, city name, and temperature readings. The 'Date' field represents dates in a string format, the 'City' field represents city names, and the 'Temperature' field represents temperature values in integer format.",
135+
"explorative_questions": [
136+
"What is the average temperature across different cities?",
137+
"What is the distribution of temperature across different dates?",
138+
"What is the relationship between temperature and city?",
139+
"What is the relationship between temperature and date?"
140+
]
125141
}```'''
126142

127143
class DataLoadAgent(object):

src/app/dfSlice.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,11 @@ export const dataFormulatorSlice = createSlice({
745745
return field;
746746
}
747747
})
748+
749+
if (data["result"][0]["explorative_questions"] && data["result"][0]["explorative_questions"].length > 0) {
750+
let table = state.tables.find(t => t.id == tableId) as DictTable;
751+
table.explorativeQuestions = data["result"][0]["explorative_questions"] as string[];
752+
}
748753
}
749754
})
750755
.addCase(fetchAvailableModels.fulfilled, (state, action) => {

src/components/ComponentType.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ export interface DictTable {
7676
rowCount: number; // total number of rows in the full table
7777
};
7878
anchored: boolean; // whether this table is anchored as a persistent table used to derive other tables
79+
explorativeQuestions: string[]; // a list of (3-5) explorative questions that can help users get started with data visualizations
7980
}
8081

8182
export function createDictTable(
8283
id: string, rows: any[],
8384
derive: {code: string, codeExpl: string, source: string[], dialog: any[],
8485
trigger: Trigger} | undefined = undefined,
8586
virtual: {tableId: string, rowCount: number} | undefined = undefined,
86-
anchored: boolean = false) : DictTable {
87+
anchored: boolean = false,
88+
explorativeQuestions: string[] = []) : DictTable {
8789

8890
let names = Object.keys(rows[0])
8991

@@ -95,7 +97,8 @@ export function createDictTable(
9597
types: names.map(name => inferTypeFromValueArray(rows.map(r => r[name]))),
9698
derive,
9799
virtual,
98-
anchored
100+
anchored,
101+
explorativeQuestions
99102
}
100103
}
101104

src/views/ChartRecBox.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,13 @@ export const ChartRecBox: FC<ChartRecBoxProps> = function ({ tableId, placeHolde
169169

170170
const [prompt, setPrompt] = useState<string>("");
171171
const [isFormulating, setIsFormulating] = useState<boolean>(false);
172+
// Remove the randomQuestion state since we'll generate it on demand
172173

173174
// Use the provided tableId and find additional available tables for multi-table operations
174175
const currentTable = tables.find(t => t.id === tableId);
176+
177+
// Remove the useEffect that sets randomQuestion
178+
175179
const availableTables = tables.filter(t => t.derive === undefined || t.anchored);
176180
const [additionalTableIds, setAdditionalTableIds] = useState<string[]>([]);
177181

@@ -184,6 +188,25 @@ export const ChartRecBox: FC<ChartRecBoxProps> = function ({ tableId, placeHolde
184188
setAdditionalTableIds(additionalIds);
185189
};
186190

191+
// Function to get a random question from the list
192+
const getQuestion = (random: boolean = false): string => {
193+
if (currentTable?.explorativeQuestions && currentTable.explorativeQuestions.length > 0) {
194+
const index = random ? Math.floor(Math.random() * currentTable.explorativeQuestions.length) : 0;
195+
return currentTable.explorativeQuestions[index];
196+
}
197+
return "Show something interesting about the data";
198+
};
199+
200+
// Handle tab key press for auto-completion
201+
const handleKeyDown = (event: React.KeyboardEvent) => {
202+
if (event.key === 'Tab' && !event.shiftKey) {
203+
event.preventDefault();
204+
if (prompt.trim() === "") {
205+
setPrompt(getQuestion(false));
206+
}
207+
}
208+
};
209+
187210
const deriveDataFromNL = (instruction: string) => {
188211

189212
if (selectedTableIds.length === 0 || instruction.trim() === "") {
@@ -452,6 +475,7 @@ export const ChartRecBox: FC<ChartRecBoxProps> = function ({ tableId, placeHolde
452475
"& .MuiInput-input": { fontSize: '14px' }
453476
}}
454477
onChange={(event) => setPrompt(event.target.value)}
478+
onKeyDown={handleKeyDown}
455479
slotProps={{
456480
inputLabel: { shrink: true },
457481
input: {
@@ -471,7 +495,7 @@ export const ChartRecBox: FC<ChartRecBoxProps> = function ({ tableId, placeHolde
471495
}}
472496
value={prompt}
473497
label="Describe what you want to visualize"
474-
placeholder="e.g., Show sales trends by region over time"
498+
placeholder={`e.g., ${getQuestion(false)}`}
475499
fullWidth
476500
multiline
477501
variant="standard"
@@ -488,7 +512,7 @@ export const ChartRecBox: FC<ChartRecBoxProps> = function ({ tableId, placeHolde
488512
size="medium"
489513
disabled={isFormulating || !currentTable}
490514
color="primary"
491-
onClick={() => deriveDataFromNL('show me a creative visualization about the data')}
515+
onClick={() => deriveDataFromNL(getQuestion(true))}
492516
>
493517
<InsightsIcon sx={{fontSize: 24}} />
494518
</IconButton>

src/views/DBTableManager.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ export const DBTableSelectionDialog: React.FC<{ buttonElement: any }> = function
542542
rowCount: dbTable.row_count,
543543
},
544544
anchored: true, // by default, db tables are anchored
545+
explorativeQuestions: []
545546
}
546547
dispatch(dfActions.loadTable(table));
547548
dispatch(fetchFieldSemanticType(table));

src/views/DataThread.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ let SingleThreadView: FC<{
293293
highlightedTableIds = focusedTableId && tableIdList.includes(focusedTableId) ? tableIdList : [];
294294
}
295295

296-
console.log('triggerToFirstNewTable - ', triggerToFirstNewTable)
297-
298296
let tableElementList = tableIdList.map((tableId, i) => {
299297

300298
if (tableId == leafTable.id && leafTable.anchored && tableIdList.length > 1) {

src/views/VisualizationView.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,6 @@ export const ChartEditorFC: FC<{}> = function ChartEditorFC({}) {
363363

364364
let table = getDataTable(focusedChart, tables, charts, conceptShelfItems);
365365

366-
console.log('charts')
367-
console.log(charts)
368-
369366
let visFieldIds = Object.keys(focusedChart.encodingMap).filter(key => focusedChart.encodingMap[key as keyof EncodingMap].fieldID != undefined).map(key => focusedChart.encodingMap[key as keyof EncodingMap].fieldID);
370367
let visFields = conceptShelfItems.filter(f => visFieldIds.includes(f.id));
371368
let dataFieldsAllAvailable = visFields.every(f => table.names.includes(f.name));
@@ -881,8 +878,8 @@ export const VisualizationViewFC: FC<VisPanelProps> = function VisualizationView
881878
{focusedTableId ? <ChartRecBox sx={{margin: 'auto'}} tableId={focusedTableId as string} placeHolderChartId={focusedChartId as string} /> : ""}
882879
<Divider sx={{my: 3}} textAlign='left'>
883880
<Typography sx={{fontSize: 12, color: "darkgray"}}>
884-
or, select a chart
885-
</Typography>
881+
or, select a chart type
882+
</Typography>
886883
</Divider>
887884
{chartSelectionBox}
888885
</Box>
@@ -891,7 +888,6 @@ export const VisualizationViewFC: FC<VisPanelProps> = function VisualizationView
891888

892889
let chartEditor = <ChartEditorFC key={focusedChartId} />
893890

894-
895891
let finalView = <Box></Box>;
896892

897893
if (visViewMode == "gallery") {

0 commit comments

Comments
 (0)