Mustehson commited on
Commit
230c281
Β·
1 Parent(s): afa1988

Added Prompt

Browse files
prompt.py β†’ __pycache__/prompt.cpython-311.pyc RENAMED
Binary files a/prompt.py and b/__pycache__/prompt.cpython-311.pyc differ
 
app.py CHANGED
@@ -64,15 +64,80 @@ def get_visualization(question, tool, schema, table_name):
64
  additional_authorized_imports=['matplotlib.pyplot',
65
  'pandas', 'plotly.express',
66
  'seaborn'], max_iterations=10)
67
- fig = agent.run(
68
 
69
- task=PROMPT,
70
- query_description= f'{question}',
71
- schema= f'{schema}',
72
- table_name= f'{table_name}',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  )
74
 
75
- return fig
76
 
77
 
78
  class SQLExecutorTool(Tool):
 
64
  additional_authorized_imports=['matplotlib.pyplot',
65
  'pandas', 'plotly.express',
66
  'seaborn'], max_iterations=10)
67
+ results = agent.run(
68
 
69
+ task= f'''
70
+
71
+ Here are the steps you should follow while writing code for Visualization:
72
+ 1. You have access to the database with the `sql_engine` tool, which allows you to run DuckDB SQL queries and return results as a df.
73
+ 2. Query the database using `sql_engine`, print the first 5 rows to inspect the data.
74
+ 3. Select the most appropriate chart type for the data:
75
+ - Use bar charts for categorical comparisons, line charts for trends over time, scatter plots for relationships between variables, pie charts for proportions, histograms for distribution, and box plots for data spread and outliers.
76
+ 4. Analyze the data and choose the best visualization type to answer the query.
77
+ 5. Always include a plot in your answer.
78
+ 6. Use Seaborn for the plots.
79
+ 7. In the end, return a dictionary containing the final figure (`fig` key), the generated SQL (`sql` key), and the data as a dataframe (`data` key) using the `final_answer` tool, e.g. `final_answer(answer={{"fig": 'fig.png', "sql": sql, "data": data}})`.
80
+
81
+ Example:
82
+
83
+ ```python
84
+ # Input query
85
+ query_description = 'Average tip amount based on the ride time length in minutes.'
86
+
87
+ # SQL Query to get ride time length and average tip amount
88
+ query = """
89
+ SELECT
90
+ EXTRACT(EPOCH FROM (tpep_dropoff_datetime - tpep_pickup_datetime)) / 60 AS ride_time_length,
91
+ AVG(tip_amount) AS avg_tip_amount
92
+ FROM
93
+ sample_data.nyc.taxi
94
+ GROUP BY
95
+ EXTRACT(EPOCH FROM (tpep_dropoff_datetime - tpep_pickup_datetime)) / 60
96
+ """
97
+
98
+ # Execute the query using the sql_engine tool
99
+ df = sql_engine(query=query)
100
+
101
+ # Print the result to observe the data
102
+ print(df)
103
+
104
+ # Create a line plot using seaborn
105
+ import seaborn as sns
106
+ import matplotlib.pyplot as plt
107
+
108
+ plt.figure(figsize=(10,6))
109
+ sns.lineplot(x="ride_time_length", y="avg_tip_amount", data=df)
110
+
111
+ # Set the title and labels
112
+ plt.title("Average Tip Amount vs Ride Time Length")
113
+ plt.xlabel("Ride Time Length (minutes)")
114
+ plt.ylabel("Average Tip Amount")
115
+
116
+ # Print the plot to observe the results
117
+ print("Plot created")
118
+
119
+ # Since we are required to return a fig, sql, and data, let's store the plot in a variable
120
+ fig = plt.gcf()
121
+
122
+ # Store the query in a variable
123
+ sql = query
124
+
125
+ # Store the dataframe in a variable
126
+ data = df
127
+
128
+ # Return the final answer
129
+ final_answer(answer={{"fig": fig, "sql": sql, "data": data}})
130
+ ```
131
+
132
+
133
+ Here is the query you should generate a plot for: '{question}'.
134
+ Here is the schema: '{schema}' and here is the table name: '{table_name}
135
+
136
+
137
+ '''
138
  )
139
 
140
+ return results
141
 
142
 
143
  class SQLExecutorTool(Tool):