File size: 28,640 Bytes
24371db dd82d0a 24371db fb65c41 dd82d0a fb65c41 24371db 76271c7 fb65c41 76271c7 fb65c41 24371db fb65c41 ccbdd61 24371db fb65c41 60f68c4 76271c7 5bd7fd2 3b9f8b1 535f75c 60f68c4 ccbdd61 60f68c4 331a091 3b9f8b1 5bd7fd2 76271c7 5bd7fd2 76271c7 5bd7fd2 76271c7 331a091 5bd7fd2 ccbdd61 76271c7 3b9f8b1 76271c7 ccbdd61 331a091 3b9f8b1 dd82d0a 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 dd82d0a 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 3b9f8b1 76271c7 dd82d0a 17c6c25 5bd7fd2 34c2972 5bd7fd2 17c6c25 60f68c4 5bd7fd2 331a091 5bd7fd2 76271c7 5bd7fd2 fb65c41 |
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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
import sqlite3
from utils import TEMP_DIR
def tools_call(session_hash):
dir_path = TEMP_DIR / str(session_hash)
connection = sqlite3.connect(f'{dir_path}/data_source.db')
print("Querying Database in Tools.py");
cur=connection.execute('select * from data_source')
columns = [i[0] for i in cur.description]
print("COLUMNS 2")
print(columns)
cur.close()
connection.close()
column_string = (columns[:625] + '..') if len(columns) > 625 else columns
return [
{
"type": "function",
"function": {
"name": "sql_query_func",
"description": f"""This is a tool useful to query a SQLite table called 'data_source' with the following Columns: {column_string}.
There may also be more columns in the table if the number of columns is too large to process.
This function also saves the results of the query to csv file called query.csv.""",
"parameters": {
"type": "object",
"properties": {
"queries": {
"type": "array",
"description": "The query to use in the search. Infer this from the user's message. It should be a question or a statement",
"items": {
"type": "string",
}
}
},
"required": ["queries"],
},
},
},
{
"type": "function",
"function": {
"name": "scatter_chart_generation_func",
"description": f"""This is a scatter plot generation tool useful to generate scatter plots from queried data from our SQL table called 'data_source'.
The data values will come from the columns of our query.csv (the 'x' and 'y' values of each graph) file but the layout section of the plotly dictionary objects will be generated by you.
Returns an iframe string which will be displayed inline in our chat window. Do not edit the iframe string returned
from the scatter_chart_generation_func function in any way and always display the iframe fully to the user in the chat window. You can add your own text supplementary
to it for context if desired.""",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "array",
"description": """The array containing a dictionary that contains the 'data' portion of the plotly chart generation and will include the options requested by the user.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.
Do not include the 'x' or 'y' portions of the object as this will come from the query.csv file generated by our SQLite query.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"x_column": {
"type": "array",
"description": f"""An array of strings that correspond to the the columns in our query.csv file that contain the x values of the graph. There can be more than one column
that can each be plotted against the y_column, if needed.""",
"items": {
"type": "string",
}
},
"y_column": {
"type": "string",
"description": f"""The column in our query.csv file that contain the y values of the graph.""",
"items": {
"type": "string",
}
},
"category": {
"type": "string",
"description": f"""An optional column in our query.csv file that contain a parameter that will define the category for the data.""",
"items": {
"type": "string",
}
},
"trendline": {
"type": "string",
"description": f"""An optional field to specify the type of plotly trendline we wish to use in the scatter plot.
This trendline value can be one of ['ols','lowess','rolling','ewm','expanding'].
Do not send any values outside of this array as the function will fail.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"trendline_options": {
"type": "array",
"description": """An array containing a dictionary that contains the 'trendline_options' portion of the plotly chart generation.
The 'lowess', 'rolling', and 'ewm' options require trendline_options to be included.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.""",
"items": {
"type": "string",
}
},
"marginal_x": {
"type": "string",
"description": f"""The type of marginal distribution plot we'd like to specify for the plotly scatter plot for the x axis.
This marginal_x value can be one of ['histogram','rug','box','violin'].
Do not send any values outside of this array as the function will fail.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"marginal_y": {
"type": "string",
"description": f"""The type of marginal distribution plot we'd like to specify for the plotly scatter plot for the y axis.
This marginal_y value can be one of ['histogram','rug','box','violin'].
Do not send any values outside of this array as the function will fail.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"layout": {
"type": "array",
"description": """An array containing a dictionary that contains the 'layout' portion of the plotly chart generation.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.""",
"items": {
"type": "string",
}
},
"size": {
"type": "string",
"description": f"""An optional column in our query.csv file that contain a parameter that will define the size of each plot point.
This is useful for a bubble chart where another value in our query can be represented by the size of the plotted point.
Values must be greater than or equal to 0 and so in our query, all values less than 0 should be set equal to zero.""",
"items": {
"type": "string",
}
}
},
"required": ["x_column","y_column"],
},
},
},
{
"type": "function",
"function": {
"name": "line_chart_generation_func",
"description": f"""This is a line chart generation tool useful to generate line charts from queried data from our SQL table called 'data_source'.
The data values will come from the columns of our query.csv (the 'x' and 'y' values of each graph) file but the layout section of the plotly dictionary objects will be generated by you.
Returns an iframe string which will be displayed inline in our chat window. Do not edit the iframe string returned
from the line_chart_generation_func function in any way and always display the iframe fully to the user in the chat window. You can add your own text supplementary
to it for context if desired.""",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "array",
"description": """The array containing a dictionary that contains the 'data' portion of the plotly chart generation and will include the options requested by the user.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.
Do not include the 'x' or 'y' portions of the object as this will come from the query.csv file generated by our SQLite query.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"x_column": {
"type": "string",
"description": f"""The column in our query.csv file that contain the x values of the graph.""",
"items": {
"type": "string",
}
},
"y_column": {
"type": "string",
"description": f"""The column in our query.csv file that contain the y values of the graph.""",
"items": {
"type": "string",
}
},
"category": {
"type": "string",
"description": f"""An optional column in our query.csv file that contain a parameter that will define the category for the data.""",
"items": {
"type": "string",
}
},
"layout": {
"type": "array",
"description": """An array containing a dictionary that contains the 'layout' portion of the plotly chart generation.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.""",
"items": {
"type": "string",
}
}
},
"required": ["x_column","y_column","layout"],
},
},
},
{
"type": "function",
"function": {
"name": "bar_chart_generation_func",
"description": f"""This is a bar chart generation tool useful to generate line charts from queried data from our SQL table called 'data_source'.
The data values will come from the columns of our query.csv (the 'x' and 'y' values of each graph) file but the layout section of the plotly dictionary objects will be generated by you.
Returns an iframe string which will be displayed inline in our chat window. Do not edit the iframe string returned
from the bar_chart_generation_func function in any way and always display the iframe fully to the user in the chat window. You can add your own text supplementary
to it for context if desired.""",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "array",
"description": """The array containing a dictionary that contains the 'data' portion of the plotly chart generation and will include the options requested by the user.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.
Do not include the 'x' or 'y' portions of the object as this will come from the query.csv file generated by our SQLite query.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"x_column": {
"type": "string",
"description": f"""The column in our query.csv file that contains the x values of the graph.""",
"items": {
"type": "string",
}
},
"y_column": {
"type": "string",
"description": f"""The column in our query.csv file that contains the y values of the graph.""",
"items": {
"type": "string",
}
},
"category": {
"type": "string",
"description": f"""An optional column in our query.csv file that contains a parameter that will define the category for the data.""",
"items": {
"type": "string",
}
},
"facet_row": {
"type": "string",
"description": f"""An optional column in our query.csv file that contains a parameter that will define a faceted subplot, where different rows
correspond to different values of the query specified in this parameter.""",
"items": {
"type": "string",
}
},
"facet_col": {
"type": "string",
"description": f"""An optional column in our query.csv file that contain a parameter that will define the faceted column, corresponding to
different values of our query specified in this parameter.""",
"items": {
"type": "string",
}
},
"layout": {
"type": "array",
"description": """An array containing a dictionary that contains the 'layout' portion of the plotly chart generation.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.""",
"items": {
"type": "string",
}
}
},
"required": ["x_column","y_column","layout"],
},
},
},
{
"type": "function",
"function": {
"name": "pie_chart_generation_func",
"description": f"""This is a pie chart generation tool useful to generate pie charts from queried data from our SQL table called 'data_source'.
The data values will come from the columns of our query.csv (the 'values' and 'names' values of each graph) file but the layout section of the plotly dictionary objects will be generated by you.
Returns an iframe string which will be displayed inline in our chat window. Do not edit the iframe string returned
from the pie_chart_generation_func function in any way and always display the iframe fully to the user in the chat window. You can add your own text supplementary
to it for context if desired.""",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "array",
"description": """The array containing a dictionary that contains the 'data' portion of the plotly chart generation and will include the options requested by the user.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.
Do not include the 'x' or 'y' portions of the object as this will come from the query.csv file generated by our SQLite query.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"values": {
"type": "string",
"description": f"""The column in our query.csv file that contain the values of the pie chart.""",
"items": {
"type": "string",
}
},
"names": {
"type": "string",
"description": f"""The column in our query.csv file that contain the label or section of each piece of the pie graph and allow us to know what each piece of the pie chart represents.""",
"items": {
"type": "string",
}
},
"layout": {
"type": "array",
"description": """An array containing a dictionary that contains the 'layout' portion of the plotly chart generation.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.""",
"items": {
"type": "string",
}
}
},
"required": ["values","names","layout"],
},
},
},
{
"type": "function",
"function": {
"name": "histogram_generation_func",
"description": f"""This is a histogram generation tool useful to generate histograms from queried data from our SQL table called 'data_source'.
The data values will come from the columns of our query.csv (the 'values' and 'names' values of each graph) file but the layout section of the plotly dictionary objects will be generated by you.
Returns an iframe string which will be displayed inline in our chat window. Do not edit the iframe string returned
from the histogram_generation_func function in any way and always display the iframe fully to the user in the chat window. You can add your own text supplementary
to it for context if desired.""",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "array",
"description": """The array containing a dictionary that contains the 'data' portion of the plotly chart generation and will include the options requested by the user.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.
Do not include the 'x' or 'y' portions of the object as this will come from the query.csv file generated by our SQLite query.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"x_column": {
"type": "string",
"description": f"""The column in our query.csv file that contains the x values of the histogram.
This would correspond to the counts that would be distributed in the histogram.""",
"items": {
"type": "string",
}
},
"y_column": {
"type": "string",
"description": f"""An optional column in our query.csv file that contains the y values of the histogram.""",
"items": {
"type": "string",
}
},
"histnorm": {
"type": "string",
"description": f"""An optional argument to specify the type of normalization if the default isn't used.
This histnorm value can be one of ['percent','probability','density','probability density'].
Do not send any values outside of this array as the function will fail.""",
"items": {
"type": "string",
}
},
"category": {
"type": "string",
"description": f"""An optional column in our query.csv file that contains a parameter that will define the category for the data.""",
"items": {
"type": "string",
}
},
"histfunc": {
"type": "string",
"description": f"""An optional value that represents the function of data to compute the function which is used on the optional y column.
This histfunc value can be one of ['avg','sum','count'].
Do not send any values outside of this array as the function will fail.""",
"items": {
"type": "string",
}
},
"layout": {
"type": "array",
"description": """An array containing a dictionary that contains the 'layout' portion of the plotly chart generation.
The array must contain a json formatted dictionary with outer brackets included, any other format will not work.""",
"items": {
"type": "string",
}
}
},
"required": ["x_column"],
},
},
},
{
"type": "function",
"function": {
"name": "table_generation_func",
"description": f"""This an table generation tool useful to format data as a table from queried data from our SQL table called 'data_source'.
Takes no parameters as it uses data queried in our query.csv file to build the table.
Call this function after running our SQLite query and generating query.csv.
Returns an html string generated from the pandas library and pandas.to_html()
function which will be displayed inline in our chat window.
Do not edit the string returned by the function in any way when displaying to the user.""",
"parameters": {},
},
},
{
"type": "function",
"function": {
"name": "regression_func",
"description": f"""This a tool to calculate regressions on our SQLite table called 'data_source'.
We can run queries with our 'sql_query_func' function and they will be available to use in this function via the query.csv file that is generated.
Returns a dictionary of values that includes a regression_summary and a regression chart (which is an iframe displaying the
linear regression in chart form and should be shown to the user).""",
"parameters": {
"type": "object",
"properties": {
"independent_variables": {
"type": "array",
"description": f"""An array of strings that states the independent variables in our data set which should be column names in our query.csv file that is generated
in the 'sql_query_func' function. This will allow us to identify the data to use for our independent variables.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"dependent_variable": {
"type": "string",
"description": f"""A string that states the dependent variables in our data set which should be a column name in our query.csv file that is generated
in the 'sql_query_func' function. This will allow us to identify the data to use for our dependent variables.
Infer this from the user's message.""",
"items": {
"type": "string",
}
},
"category": {
"type": "string",
"description": f"""An optional column in our query.csv file that contain a parameter that will define the category for the data.
Do not send value if no category is needed or specified. This category must be present in our query.csv file to be valid.""",
"items": {
"type": "string",
}
}
},
"required": ["independent_variables","dependent_variable"],
},
},
}
] |