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() return [ { "type": "function", "function": { "name": "sql_query_func", "description": f"""This a tool useful to query a SQLite table called 'data_source' with the following Columns: {columns}. This function also saves the results of the query to csv file called query.csv. This is useful when query results are too large to process or need to be used in an another function.""", "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": "chart_generation_func", "description": f"""This a chart generation tool useful to generate charts and graphs 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 string returned from the chart_generation_func function in any way and display it 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 list containing a dictionary that contains the 'data' portion of the plotly chart generation and will include the options requested by the user. 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", } }, "graph_type": { "type": "string", "description": f"""The type of plotly graph we wish to generate. This graph_type value can be one of ['bar','scatter','line','pie']. Do not send any values outside of this list as the function will fail. Infer this from the user's message.""", "items": { "type": "string", } }, "layout": { "type": "array", "description": """The dictionary that contains the 'layout' portion of the plotly chart generation""", "items": { "type": "string", } } }, "required": ["graph_type","x_column","y_column","layout"], }, }, }, { "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. Returns an html string generated from the pandas library and pandas.to_html() function which will be displayed inline in our chat window. There will also be a link to download the CSV included in the HTML string. Do not edit the string returned by the function in any way when displaying to the user.""", "parameters": { "type": "object", "properties": { "data": { "type": "array", "description": """The data points to use in the table generation. Infer this from the user's message. Send a python dictionary object with query data that correspond to data that will be converted into a pandas DataFrame and that correspond to the users request. The keys of this python dictionary object will be the names of the columns and values will be a list of values for each object. Make sure this is a dictionary object and not a string or an array. Send nothing else.""", "items": { "type": "string", } } }, "required": ["data"], }, }, }, { "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"""A list 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", } }, "regression_type": { "type": "string", "description": f"""A parameter that specifies the type of regression being used from the trendline options that plotly offers. Defaults to 'ols'.""", "items": { "type": "string", } }, }, "required": ["independent_variables","dependent_variable"], }, }, } ]