File size: 10,197 Bytes
24371db
dd82d0a
24371db
fb65c41
dd82d0a
 
fb65c41
 
 
 
 
 
 
24371db
fb65c41
 
 
 
 
a66c2ab
 
 
fb65c41
 
 
 
 
 
 
 
 
24371db
fb65c41
ccbdd61
24371db
 
 
fb65c41
60f68c4
 
 
a66c2ab
 
 
535f75c
 
60f68c4
 
 
ccbdd61
60f68c4
a66c2ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccbdd61
 
 
 
 
 
 
dd82d0a
 
 
 
 
a66c2ab
dd82d0a
 
 
 
 
 
 
a66c2ab
 
dd82d0a
a66c2ab
dd82d0a
 
 
 
 
 
 
 
 
 
60f68c4
 
 
 
 
ccbdd61
60f68c4
 
a66c2ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"],
                },
            }, 
        }
    ]