Bugfixes from refactor
Browse files- functions/chart_functions.py +17 -22
- functions/sqlite_functions.py +1 -1
- tools.py +1 -1
functions/chart_functions.py
CHANGED
@@ -27,11 +27,9 @@ def chart_generation_func(data: List[str], x_column: str, y_column: str, graph_t
|
|
27 |
|
28 |
df = pd.read_csv(csv_query_path)
|
29 |
|
|
|
30 |
if graph_type == "bar":
|
31 |
-
|
32 |
-
initial_graph = px.bar(df, x=x_column, y=y_column, color=category, barmode="group")
|
33 |
-
else:
|
34 |
-
initial_graph = px.bar(df, x=x_column, y=y_column, barmode="group")
|
35 |
elif graph_type == "scatter":
|
36 |
if category in df.columns:
|
37 |
initial_graph = px.scatter(df, x=x_column, y=y_column, color=category)
|
@@ -41,46 +39,44 @@ def chart_generation_func(data: List[str], x_column: str, y_column: str, graph_t
|
|
41 |
if category in df.columns:
|
42 |
initial_graph = px.line(df, x=x_column, y=y_column, color=category)
|
43 |
else:
|
44 |
-
initial_graph = px.line(df, x=x_column, y=y_column)
|
45 |
elif graph_type == "pie":
|
46 |
-
|
47 |
-
initial_graph = px.pie(df, x=x_column, y=y_column, color=category)
|
48 |
-
else:
|
49 |
-
initial_graph = px.pie(df, x=x_column, y=y_column)
|
50 |
-
|
51 |
-
if isinstance(data, list):
|
52 |
-
data_list = data
|
53 |
-
else:
|
54 |
-
data_list.append(data)
|
55 |
|
|
|
56 |
|
57 |
#Processing data to account for variation from LLM
|
58 |
data_list = []
|
59 |
layout_dict = {}
|
60 |
|
|
|
|
|
|
|
|
|
|
|
61 |
data_dict = {}
|
62 |
for data_obj in data_list:
|
63 |
if isinstance(data_obj, str):
|
64 |
data_obj = data_obj.replace("\n", "")
|
65 |
-
if not data_obj.startswith('{')
|
66 |
data_obj = "{" + data_obj + "}"
|
67 |
data_dict = ast.literal_eval(data_obj)
|
68 |
else:
|
69 |
data_dict = data_obj
|
70 |
|
71 |
-
if isinstance(layout, list):
|
72 |
layout_obj = layout[0]
|
73 |
else:
|
74 |
layout_obj = layout
|
75 |
|
76 |
-
if isinstance(layout_obj, str):
|
77 |
layout_dict = ast.literal_eval(layout_obj)
|
78 |
else:
|
79 |
layout_dict = layout_obj
|
80 |
-
|
81 |
-
fig = initial_graph.to_dict()
|
82 |
|
83 |
-
|
|
|
|
|
84 |
|
85 |
for key, value in data_dict.items():
|
86 |
if key not in ["x","y"]:
|
@@ -126,8 +122,7 @@ def table_generation_func(data: List[dict], session_hash):
|
|
126 |
print(df)
|
127 |
df.to_csv(csv_path)
|
128 |
|
129 |
-
|
130 |
-
html_table = df.to_html() + f'<p>Download as a <a href="{download_path}">CSV file</a></p>'
|
131 |
print(html_table)
|
132 |
|
133 |
return {"reply": html_table}
|
|
|
27 |
|
28 |
df = pd.read_csv(csv_query_path)
|
29 |
|
30 |
+
#setting up the plotly express objects
|
31 |
if graph_type == "bar":
|
32 |
+
initial_graph = px.bar(df, x=x_column, y=y_column, barmode="group")
|
|
|
|
|
|
|
33 |
elif graph_type == "scatter":
|
34 |
if category in df.columns:
|
35 |
initial_graph = px.scatter(df, x=x_column, y=y_column, color=category)
|
|
|
39 |
if category in df.columns:
|
40 |
initial_graph = px.line(df, x=x_column, y=y_column, color=category)
|
41 |
else:
|
42 |
+
initial_graph = px.line(df, x=x_column, y=y_column)
|
43 |
elif graph_type == "pie":
|
44 |
+
initial_graph = px.pie(df, x=x_column, y=y_column)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
fig = initial_graph.to_dict()
|
47 |
|
48 |
#Processing data to account for variation from LLM
|
49 |
data_list = []
|
50 |
layout_dict = {}
|
51 |
|
52 |
+
if isinstance(data, list):
|
53 |
+
data_list = data
|
54 |
+
else:
|
55 |
+
data_list.append(data)
|
56 |
+
|
57 |
data_dict = {}
|
58 |
for data_obj in data_list:
|
59 |
if isinstance(data_obj, str):
|
60 |
data_obj = data_obj.replace("\n", "")
|
61 |
+
if not data_obj.startswith('{') or not data_obj.endswith('}'):
|
62 |
data_obj = "{" + data_obj + "}"
|
63 |
data_dict = ast.literal_eval(data_obj)
|
64 |
else:
|
65 |
data_dict = data_obj
|
66 |
|
67 |
+
if layout and isinstance(layout, list):
|
68 |
layout_obj = layout[0]
|
69 |
else:
|
70 |
layout_obj = layout
|
71 |
|
72 |
+
if layout and isinstance(layout_obj, str):
|
73 |
layout_dict = ast.literal_eval(layout_obj)
|
74 |
else:
|
75 |
layout_dict = layout_obj
|
|
|
|
|
76 |
|
77 |
+
#Applying stylings and settings generated from LLM
|
78 |
+
if layout:
|
79 |
+
fig["layout"] = layout_dict
|
80 |
|
81 |
for key, value in data_dict.items():
|
82 |
if key not in ["x","y"]:
|
|
|
122 |
print(df)
|
123 |
df.to_csv(csv_path)
|
124 |
|
125 |
+
html_table = df.to_html()
|
|
|
126 |
print(html_table)
|
127 |
|
128 |
return {"reply": html_table}
|
functions/sqlite_functions.py
CHANGED
@@ -33,7 +33,7 @@ def sqlite_query_func(queries: List[str], session_hash):
|
|
33 |
sql_query = SQLiteQuery(f'{dir_path}/data_source.db')
|
34 |
try:
|
35 |
result = sql_query.run(queries, session_hash)
|
36 |
-
if len(result["results"][0]) >
|
37 |
print("QUERY TOO LARGE")
|
38 |
return {"reply": "query result too large to be processed by llm, the query results are in our query.csv file"}
|
39 |
else:
|
|
|
33 |
sql_query = SQLiteQuery(f'{dir_path}/data_source.db')
|
34 |
try:
|
35 |
result = sql_query.run(queries, session_hash)
|
36 |
+
if len(result["results"][0]) > 500:
|
37 |
print("QUERY TOO LARGE")
|
38 |
return {"reply": "query result too large to be processed by llm, the query results are in our query.csv file"}
|
39 |
else:
|
tools.py
CHANGED
@@ -105,7 +105,7 @@ def tools_call(session_hash):
|
|
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",
|
|
|
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",
|