File size: 4,864 Bytes
24371db
dd82d0a
24371db
fb65c41
dd82d0a
 
fb65c41
 
 
 
 
 
 
24371db
fb65c41
 
 
 
 
60f68c4
fb65c41
 
 
 
 
 
 
 
 
24371db
fb65c41
3d660e2
24371db
 
 
fb65c41
60f68c4
 
 
535f75c
 
 
 
60f68c4
 
 
3d660e2
60f68c4
3d660e2
 
 
 
 
 
 
 
dd82d0a
 
 
 
 
3d660e2
dd82d0a
 
 
 
 
 
 
 
 
 
19b2962
 
dd82d0a
 
 
 
 
 
 
 
 
 
60f68c4
 
 
 
 
3d660e2
60f68c4
 
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
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}",
                "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 

                with the following Columns: {columns}. 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. 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": ["data"],
                },
            }, 
        },
        {
        "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 with the following Columns: {columns}. 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. 

                This link should open in a new window. Do not edit the string returned by the function in any way when displaying to the user, as the user needs 

                all of the information returned by the function in it's exact state.""",
                "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"],
                },
            }, 
        }
    ]