nolanzandi commited on
Commit
c9c27b8
·
verified ·
1 Parent(s): 61f7b79

Updates to convince LLM to display visualizations more often (#30)

Browse files

- Updates to convince LLM to display visualizations more often (1862a575a4166c1c9daecc20258c3c9e98c93e6b)

functions/chart_functions.py CHANGED
@@ -131,7 +131,7 @@ def scatter_chart_generation_func(x_column: List[str], y_column: str, session_ha
131
 
132
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
133
 
134
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
135
 
136
  return {"reply": iframe}
137
 
@@ -182,7 +182,7 @@ def line_chart_generation_func(x_column: str, y_column: str, session_hash, sessi
182
 
183
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
184
 
185
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
186
 
187
  return {"reply": iframe}
188
 
@@ -237,7 +237,7 @@ def bar_chart_generation_func(x_column: str, y_column: str, session_hash, sessio
237
 
238
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
239
 
240
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
241
 
242
  return {"reply": iframe}
243
 
@@ -284,7 +284,7 @@ def pie_chart_generation_func(values: str, names: str, session_hash, session_fol
284
 
285
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
286
 
287
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
288
 
289
  return {"reply": iframe}
290
 
@@ -343,7 +343,7 @@ def histogram_generation_func(x_column: str, session_hash, session_folder, y_col
343
 
344
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
345
 
346
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
347
 
348
  return {"reply": iframe}
349
 
@@ -373,7 +373,7 @@ def table_generation_func(session_hash, session_folder, **kwargs):
373
 
374
  table_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/table.html'
375
 
376
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + table_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
377
  print(iframe)
378
  return {"reply": iframe}
379
 
 
131
 
132
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
133
 
134
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
135
 
136
  return {"reply": iframe}
137
 
 
182
 
183
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
184
 
185
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
186
 
187
  return {"reply": iframe}
188
 
 
237
 
238
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
239
 
240
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
241
 
242
  return {"reply": iframe}
243
 
 
284
 
285
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
286
 
287
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
288
 
289
  return {"reply": iframe}
290
 
 
343
 
344
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
345
 
346
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
347
 
348
  return {"reply": iframe}
349
 
 
373
 
374
  table_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/table.html'
375
 
376
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + table_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
377
  print(iframe)
378
  return {"reply": iframe}
379
 
functions/chat_functions.py CHANGED
@@ -14,7 +14,7 @@ def example_question_generator(session_hash):
14
  "You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'."
15
  )
16
  ]
17
-
18
  session_path = 'file_upload'
19
 
20
  dir_path = TEMP_DIR / str(session_hash) / str(session_path)
@@ -74,14 +74,14 @@ def chatbot_with_fc(message, history, session_hash):
74
  messages = [
75
  ChatMessage.from_system(
76
  """You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'.
77
- You also have access to a function, called table_generation_func, that can take a query.csv file generated from our sql query and returns an iframe that we can display in our chat window.
78
- You also have access to a scatter plot function, called scatter_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a scatter plot and returns an iframe that we can display in our chat window.
79
- You also have access to a line chart function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a line chart and returns an iframe that we can display in our chat window.
80
- You also have access to a bar graph function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a bar graph and returns an iframe that we can display in our chat window.
81
- You also have access to a pie chart function, called pie_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a pie chart and returns an iframe that we can display in our chat window.
82
- You also have access to a histogram function, called histogram_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a histogram and returns an iframe that we can display in our chat window.
83
  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.
84
- Charts, tables, and visualizations are a very important part of your output. If you generate a chart, table, or visualization as part of your answer, please display it always."""
85
  )
86
  ]
87
  messages.append(ChatMessage.from_user(message))
@@ -131,14 +131,14 @@ def sql_chatbot_with_fc(message, history, session_hash, db_url, db_port, db_user
131
  messages = [
132
  ChatMessage.from_system(
133
  f"""You are a helpful and knowledgeable agent who has access to an PostgreSQL database which has a series of tables called {db_tables}.
134
- You also have access to a function, called table_generation_func, that can take a query.csv file generated from our sql query and returns an iframe that we can display in our chat window.
135
- You also have access to a scatter plot function, called scatter_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a scatter plot and returns an iframe that we can display in our chat window.
136
- You also have access to a line chart function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a line chart and returns an iframe that we can display in our chat window.
137
- You also have access to a bar graph function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a bar graph and returns an iframe that we can display in our chat window.
138
- You also have access to a pie chart function, called pie_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a pie chart and returns an iframe that we can display in our chat window.
139
- You also have access to a histogram function, called histogram_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a histogram and returns an iframe that we can display in our chat window.
140
  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.
141
- Charts, tables, and visualizations are a very important part of your output. If you generate a chart, table, or visualization as part of your answer, please display it always."""
142
  )
143
  ]
144
  messages.append(ChatMessage.from_user(message))
 
14
  "You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'."
15
  )
16
  ]
17
+
18
  session_path = 'file_upload'
19
 
20
  dir_path = TEMP_DIR / str(session_hash) / str(session_path)
 
74
  messages = [
75
  ChatMessage.from_system(
76
  """You are a helpful and knowledgeable agent who has access to an SQLite database which has a table called 'data_source'.
77
+ You also have access to a function, called table_generation_func, that can take a query.csv file generated from our sql query and returns an iframe that we should display in our chat window.
78
+ You also have access to a scatter plot function, called scatter_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a scatter plot and returns an iframe that we should display in our chat window.
79
+ You also have access to a line chart function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a line chart and returns an iframe that we should display in our chat window.
80
+ You also have access to a bar graph function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a bar graph and returns an iframe that we should display in our chat window.
81
+ You also have access to a pie chart function, called pie_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a pie chart and returns an iframe that we should display in our chat window.
82
+ You also have access to a histogram function, called histogram_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a histogram and returns an iframe that we should display in our chat window.
83
  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.
84
+ Could you please always display the generated charts, tables, and visualizations as part of your output?"""
85
  )
86
  ]
87
  messages.append(ChatMessage.from_user(message))
 
131
  messages = [
132
  ChatMessage.from_system(
133
  f"""You are a helpful and knowledgeable agent who has access to an PostgreSQL database which has a series of tables called {db_tables}.
134
+ You also have access to a function, called table_generation_func, that can take a query.csv file generated from our sql query and returns an iframe that we should display in our chat window.
135
+ You also have access to a scatter plot function, called scatter_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a scatter plot and returns an iframe that we should display in our chat window.
136
+ You also have access to a line chart function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a line chart and returns an iframe that we should display in our chat window.
137
+ You also have access to a bar graph function, called line_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a bar graph and returns an iframe that we should display in our chat window.
138
+ You also have access to a pie chart function, called pie_chart_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a pie chart and returns an iframe that we should display in our chat window.
139
+ You also have access to a histogram function, called histogram_generation_func, that can take a query.csv file generated from our sql query and uses plotly dictionaries to generate a histogram and returns an iframe that we should display in our chat window.
140
  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.
141
+ Could you please always display the generated charts, tables, and visualizations as part of your output?"""
142
  )
143
  ]
144
  messages.append(ChatMessage.from_user(message))
functions/stat_functions.py CHANGED
@@ -34,7 +34,7 @@ def regression_func(independent_variables: List[str], dependent_variable: str, s
34
 
35
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
36
 
37
- iframe = '<div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
38
 
39
  results_frame = px.get_trendline_results(fig)
40
 
 
34
 
35
  chart_url = f'{root_url}/gradio_api/file/temp/{session_hash}/{session_folder}/chart.html'
36
 
37
+ iframe = 'Please display this iframe: <div style=overflow:auto;><iframe\n scrolling="yes"\n width="1000px"\n height="500px"\n src="' + chart_url + '"\n frameborder="0"\n allowfullscreen\n></iframe>\n</div>'
38
 
39
  results_frame = px.get_trendline_results(fig)
40