Update table function to use query.csv (#16)
Browse files- Update table function to use query.csv (58e8e451a0556a962a115be4e2b32efff8ab2af8)
- functions/chart_functions.py +3 -16
- functions/chat_functions.py +1 -1
- tools.py +4 -18
functions/chart_functions.py
CHANGED
@@ -100,27 +100,14 @@ def chart_generation_func(data: List[str], x_column: str, y_column: str, graph_t
|
|
100 |
"""
|
101 |
return {"reply": reply}
|
102 |
|
103 |
-
def table_generation_func(
|
104 |
print("TABLE GENERATION")
|
105 |
-
print(data)
|
106 |
try:
|
107 |
dir_path = TEMP_DIR / str(session_hash)
|
108 |
-
|
109 |
-
|
110 |
-
#Processing data to account for variation from LLM
|
111 |
-
if isinstance(data, list):
|
112 |
-
data_obj = data[0]
|
113 |
-
else:
|
114 |
-
data_obj = data
|
115 |
-
|
116 |
-
if isinstance(data_obj, str):
|
117 |
-
data_dict = ast.literal_eval(data_obj)
|
118 |
-
else:
|
119 |
-
data_dict = data_obj
|
120 |
|
121 |
-
df = pd.
|
122 |
print(df)
|
123 |
-
df.to_csv(csv_path)
|
124 |
|
125 |
html_table = df.to_html()
|
126 |
print(html_table)
|
|
|
100 |
"""
|
101 |
return {"reply": reply}
|
102 |
|
103 |
+
def table_generation_func(session_hash):
|
104 |
print("TABLE GENERATION")
|
|
|
105 |
try:
|
106 |
dir_path = TEMP_DIR / str(session_hash)
|
107 |
+
csv_query_path = f'{dir_path}/query.csv'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
+
df = pd.read_csv(csv_query_path)
|
110 |
print(df)
|
|
|
111 |
|
112 |
html_table = df.to_html()
|
113 |
print(html_table)
|
functions/chat_functions.py
CHANGED
@@ -48,7 +48,7 @@ def chatbot_with_fc(message, history, session_hash):
|
|
48 |
ChatMessage.from_system(
|
49 |
"""You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'.
|
50 |
You also have access to a chart function that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate charts and graphs and returns an iframe that we can display in our chat window.
|
51 |
-
You also have access to a function, called table_generation_func, that builds table formatted html
|
52 |
You also have access to a linear regression function, called regression_func, that can take a query.csv file generated from our sql query and a list of column names for our independent and dependent variables and return a regression data string and a regression chart which is returned as an iframe."""
|
53 |
)
|
54 |
]
|
|
|
48 |
ChatMessage.from_system(
|
49 |
"""You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'.
|
50 |
You also have access to a chart function that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate charts and graphs and returns an iframe that we can display in our chat window.
|
51 |
+
You also have access to a function, called table_generation_func, that builds table formatted html.
|
52 |
You also have access to a linear regression function, called regression_func, that can take a query.csv file generated from our sql query and a list of column names for our independent and dependent variables and return a regression data string and a regression chart which is returned as an iframe."""
|
53 |
)
|
54 |
]
|
tools.py
CHANGED
@@ -103,27 +103,13 @@ def tools_call(session_hash):
|
|
103 |
"type": "function",
|
104 |
"function": {
|
105 |
"name": "table_generation_func",
|
106 |
-
"description": f"""This an table generation tool useful to format data as a table from queried data from our SQL table called 'data_source.
|
|
|
|
|
107 |
Returns an html string generated from the pandas library and pandas.to_html()
|
108 |
function which will be displayed inline in our chat window.
|
109 |
Do not edit the string returned by the function in any way when displaying to the user.""",
|
110 |
-
"parameters": {
|
111 |
-
"type": "object",
|
112 |
-
"properties": {
|
113 |
-
"data": {
|
114 |
-
"type": "array",
|
115 |
-
"description": """The data points to use in the table generation. Infer this from the user's message.
|
116 |
-
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.
|
117 |
-
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.
|
118 |
-
Make sure this is a dictionary object and not a string or an array.
|
119 |
-
Send nothing else.""",
|
120 |
-
"items": {
|
121 |
-
"type": "string",
|
122 |
-
}
|
123 |
-
}
|
124 |
-
},
|
125 |
-
"required": ["data"],
|
126 |
-
},
|
127 |
},
|
128 |
},
|
129 |
{
|
|
|
103 |
"type": "function",
|
104 |
"function": {
|
105 |
"name": "table_generation_func",
|
106 |
+
"description": f"""This an table generation tool useful to format data as a table from queried data from our SQL table called 'data_source'.
|
107 |
+
Takes no parameters as it uses data queried in our query.csv file to build the table.
|
108 |
+
Call this function after running our SQLite query and generating query.csv.
|
109 |
Returns an html string generated from the pandas library and pandas.to_html()
|
110 |
function which will be displayed inline in our chat window.
|
111 |
Do not edit the string returned by the function in any way when displaying to the user.""",
|
112 |
+
"parameters": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
},
|
114 |
},
|
115 |
{
|