File size: 13,707 Bytes
7afc8ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70b0712
 
 
7afc8ec
 
 
 
 
 
70b0712
4ac9bc4
 
 
 
7afc8ec
 
 
 
 
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
 
 
 
 
4ac9bc4
 
 
7afc8ec
 
 
 
 
 
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
 
 
 
4ac9bc4
7afc8ec
4ac9bc4
70b0712
 
 
7afc8ec
 
 
 
 
70b0712
4ac9bc4
 
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
7afc8ec
 
4ac9bc4
7afc8ec
4ac9bc4
70b0712
 
 
7afc8ec
 
 
 
 
 
70b0712
4ac9bc4
 
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
7afc8ec
 
4ac9bc4
7afc8ec
4ac9bc4
70b0712
 
 
7afc8ec
 
 
 
 
70b0712
4ac9bc4
 
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
7afc8ec
 
4ac9bc4
7afc8ec
4ac9bc4
70b0712
 
 
7afc8ec
 
 
 
 
 
70b0712
4ac9bc4
 
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
 
 
7afc8ec
4ac9bc4
7afc8ec
 
4ac9bc4
7afc8ec
4ac9bc4
70b0712
c007902
 
7afc8ec
 
 
 
 
 
c007902
 
 
 
 
7afc8ec
c007902
 
 
7afc8ec
c007902
 
 
7afc8ec
c007902
7afc8ec
c007902
7afc8ec
c007902
 
 
 
7afc8ec
 
 
 
 
 
c007902
 
 
 
 
7afc8ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c007902
7afc8ec
c007902
 
70b0712
 
7afc8ec
 
 
 
 
 
70b0712
 
4ac9bc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# Shared parameter snippets reused across chart tool schemas.
# Update here to change the description everywhere at once.

_LAYOUT_PARAM = {
    "type": "array",
    "description": (
        "Optional. An array containing a single JSON-formatted Plotly layout dictionary. "
        "Use to set chart title, axis labels, colours, fonts, and other layout properties. "
        "Example: [{\"title\": \"Monthly Sales\", \"xaxis\": {\"title\": \"Month\"}}]"
    ),
    "items": {"type": "string"},
}

_TRACE_STYLE_PARAM = {
    "type": "array",
    "description": (
        "Optional. An array containing a single JSON-formatted Plotly trace styling dictionary. "
        "Use to control visual properties such as line colour, opacity, and marker style. "
        "Do NOT include 'x', 'y', or 'type' keys β€” those are set automatically from query.csv."
    ),
    "items": {"type": "string"},
}

chart_tool_schemas = [
    {
        "name": "scatter_chart_generation_func",
        "description": (
            "Generates a Plotly scatter plot from query.csv data. "
            "Use when the user wants to visualise the relationship between two numeric columns, "
            "create a bubble chart (via the size parameter), or overlay a trendline. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "x_column": {
                    "type": "array",
                    "description": (
                        "One or more column names from query.csv to plot on the x-axis. "
                        "Multiple columns produce multiple series, each plotted against y_column."
                    ),
                    "items": {"type": "string"},
                },
                "y_column": {
                    "type": "string",
                    "description": "Column name from query.csv to plot on the y-axis.",
                },
                "category": {
                    "type": "string",
                    "description": "Optional column name used to colour-code points by a categorical grouping.",
                },
                "trendline": {
                    "type": "string",
                    "description": (
                        "Optional trendline type. One of: 'ols' (linear regression), "
                        "'lowess' (local smoothing), 'rolling', 'ewm', 'expanding'. "
                        "Requires trendline_options when using 'lowess', 'rolling', or 'ewm'."
                    ),
                },
                "trendline_options": {
                    "type": "array",
                    "description": (
                        "Required when trendline is 'lowess', 'rolling', or 'ewm'. "
                        "An array containing a single JSON-formatted dict of trendline options "
                        "(e.g. [{\"window\": 7}] for a 7-point rolling average)."
                    ),
                    "items": {"type": "string"},
                },
                "marginal_x": {
                    "type": "string",
                    "description": "Optional marginal distribution plot along the x-axis. One of: 'histogram', 'rug', 'box', 'violin'.",
                },
                "marginal_y": {
                    "type": "string",
                    "description": "Optional marginal distribution plot along the y-axis. One of: 'histogram', 'rug', 'box', 'violin'.",
                },
                "size": {
                    "type": "string",
                    "description": "Optional column name whose values control the size of each point (bubble chart). Negative values are clamped to zero.",
                },
                "data": _TRACE_STYLE_PARAM,
                "layout": _LAYOUT_PARAM,
            },
            "required": ["x_column", "y_column"],
        },
    },
    {
        "name": "line_chart_generation_func",
        "description": (
            "Generates a Plotly line chart from query.csv data. "
            "Use for trends over time or any ordered sequence. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "x_column": {
                    "type": "string",
                    "description": "Column name from query.csv for the x-axis (typically a date or ordered index).",
                },
                "y_column": {
                    "type": "string",
                    "description": "Column name from query.csv for the y-axis (numeric values).",
                },
                "category": {
                    "type": "string",
                    "description": "Optional column name used to split the data into multiple colour-coded lines.",
                },
                "data": _TRACE_STYLE_PARAM,
                "layout": _LAYOUT_PARAM,
            },
            "required": ["x_column", "y_column"],
        },
    },
    {
        "name": "bar_chart_generation_func",
        "description": (
            "Generates a Plotly bar chart from query.csv data. "
            "Use for comparing values across categories. Supports grouped/stacked bars via category, "
            "and faceted subplots via facet_row or facet_col. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "x_column": {
                    "type": "string",
                    "description": "Column name from query.csv for the x-axis (category labels).",
                },
                "y_column": {
                    "type": "string",
                    "description": "Column name from query.csv for the y-axis (numeric values).",
                },
                "category": {
                    "type": "string",
                    "description": "Optional column name used to colour-code bars into grouped or stacked series.",
                },
                "facet_row": {
                    "type": "string",
                    "description": "Optional column name. Creates one subplot row per unique value β€” useful for comparing distributions across a second dimension.",
                },
                "facet_col": {
                    "type": "string",
                    "description": "Optional column name. Creates one subplot column per unique value.",
                },
                "data": _TRACE_STYLE_PARAM,
                "layout": _LAYOUT_PARAM,
            },
            "required": ["x_column", "y_column"],
        },
    },
    {
        "name": "pie_chart_generation_func",
        "description": (
            "Generates a Plotly pie chart from query.csv data. "
            "Use when the user wants to show part-to-whole proportions. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "values": {
                    "type": "string",
                    "description": "Column name from query.csv containing the numeric value for each slice.",
                },
                "names": {
                    "type": "string",
                    "description": "Column name from query.csv containing the label for each slice.",
                },
                "data": _TRACE_STYLE_PARAM,
                "layout": _LAYOUT_PARAM,
            },
            "required": ["values", "names"],
        },
    },
    {
        "name": "histogram_generation_func",
        "description": (
            "Generates a Plotly histogram from query.csv data. "
            "Use to show the frequency distribution of a numeric column. "
            "Supports normalisation (percent, probability, density) and aggregation functions per bin. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "x_column": {
                    "type": "string",
                    "description": "Column name from query.csv whose values are binned on the x-axis.",
                },
                "y_column": {
                    "type": "string",
                    "description": "Optional column name aggregated per bin via histfunc (e.g. sum of sales per price bucket).",
                },
                "histnorm": {
                    "type": "string",
                    "description": "Optional normalisation. One of: 'percent', 'probability', 'density', 'probability density'.",
                },
                "category": {
                    "type": "string",
                    "description": "Optional column name used to overlay multiple colour-coded histograms.",
                },
                "histfunc": {
                    "type": "string",
                    "description": "Optional aggregation function applied to y_column per bin. One of: 'avg', 'sum', 'count'.",
                },
                "data": _TRACE_STYLE_PARAM,
                "layout": _LAYOUT_PARAM,
            },
            "required": ["x_column"],
        },
    },
    {
        "name": "box_chart_generation_func",
        "description": (
            "Generates a Plotly box plot from query.csv data. "
            "Use to visualise the distribution of a numeric column and identify outliers. "
            "Especially useful for comparing distributions across categories. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "y_column": {
                    "type": "string",
                    "description": "Column name from query.csv containing the numeric values to distribute on the y-axis.",
                },
                "x_column": {
                    "type": "string",
                    "description": "Optional column name. Groups data into one box per unique value on the x-axis.",
                },
                "category": {
                    "type": "string",
                    "description": "Optional column name used to colour-code boxes by a secondary grouping.",
                },
                "layout": _LAYOUT_PARAM,
            },
            "required": ["y_column"],
        },
    },
    {
        "name": "correlation_heatmap_func",
        "description": (
            "Computes pairwise Pearson correlations between numeric columns in query.csv and renders "
            "the result as a colour-coded heatmap (blue = positive, red = negative). "
            "Use when the user asks which variables are related, correlated, or associated with each other. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "columns": {
                    "type": "array",
                    "description": "Optional list of numeric column names to include in the matrix. If omitted, all numeric columns from query.csv are used. Avoid ID or index columns.",
                    "items": {"type": "string"},
                },
            },
            "required": [],
        },
    },
    {
        "name": "rolling_stats_func",
        "description": (
            "Generates a rolling statistics / moving average chart from query.csv data. "
            "Overlays rolling aggregations (mean, std, min, max) on top of the original series. "
            "Use when the user asks for a moving average, rolling average, rolling statistics, or wants to smooth a time series. "
            "Returns an HTML iframe β€” display it verbatim in the chat."
        ),
        "parameters": {
            "type": "object",
            "properties": {
                "x_column": {
                    "type": "string",
                    "description": "Column name from query.csv for the x-axis β€” typically a date or sequential index.",
                },
                "y_column": {
                    "type": "string",
                    "description": "Column name from query.csv containing the numeric values to compute rolling stats on.",
                },
                "window": {
                    "type": "integer",
                    "description": "Rolling window size in number of rows. Default 7. Infer from the user's request.",
                },
                "stats": {
                    "type": "array",
                    "description": "Statistics to overlay. Valid values: 'mean', 'std', 'min', 'max'. Defaults to ['mean'] if omitted.",
                    "items": {"type": "string"},
                },
                "category": {
                    "type": "string",
                    "description": "Optional column name to group the data, producing separate rolling stat lines per group.",
                },
                "layout": _LAYOUT_PARAM,
            },
            "required": ["x_column", "y_column"],
        },
    },
    {
        "name": "table_generation_func",
        "description": (
            "Formats query.csv results as a styled HTML table. "
            "Use when the user wants to view raw query results in a readable format, "
            "or when result data is too large to describe in text. Displays up to 200 rows. "
            "Returns an HTML table β€” display it verbatim in the chat."
        ),
        "parameters": {"type": "object", "properties": {}},
    },
]