Nolan Zandi commited on
Commit
defe6ea
·
1 Parent(s): 50a58d3

updates to chart generation

Browse files
functions/chart_functions.py CHANGED
@@ -18,24 +18,10 @@ def chart_generation_func(queries: List[str], session_hash):
18
  qc.height = 500
19
 
20
  # Config can be set as a string or as a nested dict
21
- chart_type = query_dict["chart_type"]
22
- chart_labels = query_dict["chart_labels"]
23
- chart_data = query_dict["chart_data"][0]["data"]
24
- chart_data_label = query_dict["chart_data"][0]["label"]
25
-
26
- qc.config = {
27
- "type": chart_type,
28
- "data": {
29
- "labels": chart_labels,
30
- "datasets": [{
31
- "label": chart_data_label,
32
- "data": chart_data
33
- }]
34
- }
35
- }
36
 
37
  # You can get the chart URL...
38
-
39
- iframe = '<iframe\n scrolling="no"\n width="1000px"\n height="500px"\n src="' + qc.get_url() + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n'
40
 
41
  return {"reply": iframe}
 
18
  qc.height = 500
19
 
20
  # Config can be set as a string or as a nested dict
21
+ qc.config = query_dict
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # You can get the chart URL...
24
+
25
+ iframe = '<iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + qc.get_url() + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n'
26
 
27
  return {"reply": iframe}
functions/chat_functions.py CHANGED
@@ -43,13 +43,10 @@ def chatbot_with_fc(message, history, session_hash):
43
  function_name = function_call.tool_name
44
  function_args = function_call.arguments
45
 
46
- ## Find the correspoding function and call it with the given arguments
47
  function_to_call = available_functions[function_name]
48
  function_response = function_to_call(**function_args, session_hash=session_hash)
49
  ## Append function response to the messages list using `ChatMessage.from_tool`
50
- print("REPLY")
51
- print(response)
52
- print(function_response['reply'])
53
  messages.append(ChatMessage.from_tool(tool_result=function_response['reply'], origin=function_call))
54
  response = chat_generator.run(messages=messages, generation_kwargs={"tools": tools.tools_call(session_hash)})
55
 
@@ -78,7 +75,12 @@ css= ".file_marker .large{min-height:50px !important;} .example_btn{max-width:30
78
 
79
  with gr.Blocks(css=css) as demo:
80
  title = gr.HTML("<h1 style='text-align:center;'>Virtual Data Analyst</h1>")
81
- description = gr.HTML("<p style='text-align:center;'>Upload a data file and chat with our virtual data analyst to get insights on your data set. Currently accepts CSV, TSV, TXT, XLS, XLSX, XML, and JSON files. Try a sample file to get started!</p>")
 
 
 
 
 
82
  example_file_1 = gr.File(visible=False, value="samples/bank_marketing_campaign.csv")
83
  example_file_2 = gr.File(visible=False, value="samples/online_retail_data.csv")
84
  with gr.Row():
 
43
  function_name = function_call.tool_name
44
  function_args = function_call.arguments
45
 
46
+ ## Find the corresponding function and call it with the given arguments
47
  function_to_call = available_functions[function_name]
48
  function_response = function_to_call(**function_args, session_hash=session_hash)
49
  ## Append function response to the messages list using `ChatMessage.from_tool`
 
 
 
50
  messages.append(ChatMessage.from_tool(tool_result=function_response['reply'], origin=function_call))
51
  response = chat_generator.run(messages=messages, generation_kwargs={"tools": tools.tools_call(session_hash)})
52
 
 
75
 
76
  with gr.Blocks(css=css) as demo:
77
  title = gr.HTML("<h1 style='text-align:center;'>Virtual Data Analyst</h1>")
78
+ description = gr.HTML("""<p style='text-align:center;'>Upload a data file and chat with our virtual data analyst
79
+ to get insights on your data set. Currently accepts CSV, TSV, TXT, XLS, XLSX, XML, and JSON files.
80
+ Can now generate charts and graphs!
81
+ Try a sample file to get started!</p>
82
+ <p style='text-align:center;'>This tool is under active development. If you experience bugs with use,
83
+ open a discussion in the community tab and I will respond.</p>""")
84
  example_file_1 = gr.File(visible=False, value="samples/bank_marketing_campaign.csv")
85
  example_file_2 = gr.File(visible=False, value="samples/online_retail_data.csv")
86
  with gr.Row():
tools.py CHANGED
@@ -15,7 +15,7 @@ def tools_call(session_hash):
15
  "type": "function",
16
  "function": {
17
  "name": "sql_query_func",
18
- "description": f"This a tool useful to query a SQL table called 'data_source' with the following Columns: {columns}",
19
  "parameters": {
20
  "type": "object",
21
  "properties": {
@@ -35,7 +35,7 @@ def tools_call(session_hash):
35
  "type": "function",
36
  "function": {
37
  "name": "rag_pipeline_func",
38
- "description": f"This a tool useful to query a SQL table called 'data_source' with the following Columns: {columns}",
39
  "parameters": {
40
  "type": "object",
41
  "properties": {
@@ -61,7 +61,9 @@ def tools_call(session_hash):
61
  "properties": {
62
  "queries": {
63
  "type": "array",
64
- "description": "The data points to use in the chart generation. Infer this from the user's message. Send a dictionary with fields chart_type, chart_labels, and chart_data which includes a field called 'label' which labels the data and a field called 'data' which is a list of data points. Return nothing else.",
 
 
65
  "items": {
66
  "type": "string",
67
  }
 
15
  "type": "function",
16
  "function": {
17
  "name": "sql_query_func",
18
+ "description": f"This a tool useful to query a SQLite table called 'data_source' with the following Columns: {columns}",
19
  "parameters": {
20
  "type": "object",
21
  "properties": {
 
35
  "type": "function",
36
  "function": {
37
  "name": "rag_pipeline_func",
38
+ "description": f"This a tool useful to query a SQLite table called 'data_source' with the following Columns: {columns}",
39
  "parameters": {
40
  "type": "object",
41
  "properties": {
 
61
  "properties": {
62
  "queries": {
63
  "type": "array",
64
+ "description": """The data points to use in the chart generation. Infer this from the user's message.
65
+ Send a chart.js dictionary with options that correspond to the users request. But also format this dictionary as a string as this will allow javascript to be interpreted by the API we are using.
66
+ Return nothing else.""",
67
  "items": {
68
  "type": "string",
69
  }