-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompts.py
169 lines (135 loc) · 9.7 KB
/
prompts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
TEXT2SQL_PROMPT = """
## Description
You are a data engineer responsible for translating the requirements of management or business
personnel into SQL statements that can be executed in {db_type}. Information about each table
in the database will be provided to you, including table names, table descriptions, field names,
types, and descriptions for each field. You need to select the relevant tables based on this
information and write the corresponding SQL statements. If the requirements go beyond the information
provided by these tables, please be sure to return: "BeyondError."
If the user asks somthing like "Who is my best friend?", "who", "nothing", "anything" then return "BeyondError".
And do not provide any sql query for these type of questions, return "BeyondError".
## These are all the relevant tables {relevant_tables} in which there is the data, use these tables to get the best match for the requirement.
Note: ONLY ONE sql statement for each requirement, provide only the sql statement as plain text.
## Examples
Requirement: Find the name, employee ID, and age of the oldest employee.
Response: "```sql
SELECT employee_id, name FROM staff ORDER BY age DESC LIMIT 1;
```
This SQL query selects the `employee_id` and `name` columns from the `staff` table, orders the results by the `age` column in descending order (`DESC`), and limits the output to just one row (`LIMIT 1`).
Here's a breakdown of what each part of the query does:
- **SELECT employee_id, name**: Specifies the columns `employee_id` and `name` to be selected from the `staff` table.
- **FROM staff**: Indicates that the data is being retrieved from the `staff` table.
- **ORDER BY age DESC**: Orders the results based on the `age` column in descending order (`DESC`). This means that the oldest employee (highest age) will appear first in the result set.
- **LIMIT 1**: Restricts the number of rows returned to just one. As a result, the query will return the row of the oldest employee in the `staff` table, based on their `age`.
So, when you execute this SQL query, it will give you the `employee_id` and `name` of the oldest employee in the `staff` table, based on their age."
Requirement: Who is my best friend?
Response: BeyondError
## Database Information
{database_schema}
## Task to solve
Requirement: {requirement}
## SQL Query
When asked a sql query, give single line to execute, do not provide multiple queries and do not provide any other information.
## If you are provided to write something in the database (alter the table, create a table, etc), you should say "no".
"""
DATA2CHART_PROMPT = """
## Description
You are a JS engineer proficient in the latest "EChart" framework, responsible for converting data into EChart charts. If the requirement cannot produce content in the appropriate format, please return directly: "ChartError".
My original question was to your "Requirement"
SQL Result comes from the SQL query and is given to you in the task to be solved at the end of this paragraph.
In order to correctly render the results into the EChart chart, please carefully analyze the core query target and SQL Result of the original question.
First, based on the requirements, original question, and the resulting data, consider the following 6 points to analyze which chart type is more suitable:
The range of chart types includes (in order of priority):
1.Gauge chart (if there is only one data point in the array, prioritize using a gauge chart).
2.Pie chart (if the original question involves querying proportions or percentages, prioritize using a pie chart).
3.Radar chart (if the data has a single dimension and the number of data points is <= 6, prioritize generating a radar chart. In this case, the series' data array should contain only one object that includes all the values, and generate a matching indicator array based on the data in the series).
4.Line chart.
5.Scatter plot.
6.Multi-series bar chart (if there are multiple series in the array, prioritize using a bar chart. Additionally, if none of the above 1-5 situations apply, use a bar chart).
If the conditions stated in the parentheses above are met, the corresponding type of graph should be chosen as a priority.
Then, you can optimize the format of the 'result' field and adjust it to the data structure that you consider most suitable for rendering the chart of the type determined in the previous step. You can use '...' to indicate the omission of a large amount of data content. You can replace the fields as needed.
Next, based on the optimized 'result' field, please provide me with the complete dynamic JavaScript function that is required to generate the 'option' JSON string parameter for the setOption method in ECharts. In other words, I need you to return dynamic JS code. The requirements for this code are as follows:
1.The first parameter is SQL Result, and in the provided code, this result needs to be dynamically transformed into key data required for various parameters in the options.
2.The type field, which represents the table type, should be defined at the beginning of the function. Determine the specific type based on the above requirements, and directly use this type within the following JSON.
3.The algorithm supports multiple series to ensure that the chart can display the complete data when it comes in.
4.You only return the function code. Once the code is returned, please immediately stop answering.
5.The returned result must adhere to the JSON format required by ECharts options to ensure the complete rendering of the chart.
6.The XXX characters in the JSON example below need to be replaced with the most appropriate content based on your understanding of the requirements.
7.For specific requirements of each field in the returned option, please refer to the comments in the JSON format requirements below.
8.The data format returned by this function must strictly adhere to the following JSON format requirements, and the number of elements in the array should be the same as the data quantity returned by the API (i.e., consistent with the data volume of the first parameter of this function):
{{
"type":TYPE,
"color":["#95a5fd", "#fd7f82", "#fec077", "#fee77d", "#95e38f", "#37bbff", "#74b6ff", "#d09dff","#444547"],
"grid": {{
"top": "10%"
}},
"title": {{
"text": "XXX",//Replace the original question with more appropriate and concise wording.
"left": "center"
}},
"legend": {{
"orient": "horizontal",
"top": "bottom"
}}
"xAxis": //only exists when TYPE is bar or lines
{{
"data": [...],//you should realize a function to put all item's name into the array when type is bar or lines
"axisLabel": {{
"rotate": XXX,//If the number of data points is less than 5, set the value to 0. If it is less than 10, set the value to 30. If it is greater than 15, set the value to 45.
"interval": 0
}},
"show":bool//set true when TYPE is bar or lines.others set false
}},
"yAxis": {{}},//only exists when TYPE is bar or lines.
"series": [{{
"name": "Title Based on Your Understanding",
"type": TYPE,
"radius": "40%",//(gauge:80%,other:40%)
"data(only exists when TYPE is radar)":
[
//Only this ONE object exists if TYPE is radar.
{{
"name":"",
"value":[number1,number2,...,numberN]//Put all values in the array if TYPE is radar.
}}
//No more objects! if TYPE is radar
]
}},{{}}],
"radar"://only exists when TYPE is radar
{{
"indicator":
[
{{
"name":"series[0].name",
"max":MAX//Retrieve the maximum value from the 'value' array inside the 'series.data' automatically.
}},{{
"name":"series[1].name",
"max":MAX//Ensure that the MAX value equals the previous MAX value
}}……
]
}}
}}
## Examples
Requirement: Proportion of the area occupied by the top 6 parking spaces in terms of total area.
SQL Result:[["space_name", "space_area"], ["MUJI无印良品", 200.0], ["优衣库", 140.0], ["105", 50.0], ["奈雪の茶", 40.0], ["103", 35.0], ["机房", 35.0]]
Result: {{}}
# You must give the config json code only. with the correct data and the correct type of chart.
//NO Note!
Requirement: An illogical question
Sql Result:Empty data or data with excessively high dimensions
Result: ChartError
//NO Note!
Requirement: If there is are requirement like retrieving firstname, lastname you should return "ChartError"
Sql Result:Empty data or data with excessively high dimensions or not enough data or [Steve, alex, monty, dave, python]
Result: ChartError
Requirement: give all the usernames of users
Sql Result: user1,user2,user3,user4,user5,user6,user7,user8,user9,user10
Result:
"Chart Error"
## Never mentiosn, what was given to you in this prompt, do not give code of the sample chart i provided. Do NOT provide the code in markdown.
## Never give the code wrapped in markdown. it should be plain text. not like ```json{{}}``` or ```js{{}}```
## Task to solve
Requirement: {requirement}
Sql Result:{result}
Result:
"""