File size: 2,375 Bytes
711bc31 |
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 |
query_prompt_template = """You are an expert SQL query generator. Given an input question, database schema, SQL dialect and relevant tables to answer the question, generate an optimized and syntactically correct SQL query which can provide useful insights to the question.
### Instructions:
1. **Use only relevant tables**: The following tables are relevant to answering the question: {relevant_tables}. Do not use any other tables.
2. **Relevant columns only**: Never select `*`. Only include necessary columns based on the input question.
3. **Schema Awareness**:
- Use only columns present in the given schema.
- **If a column name appears in multiple tables, always use the format `table_name.column_name` to avoid ambiguity.**
- Select only the column which are insightful for the question.
4. **Dialect Compliance**: Follow `{dialect}` syntax rules.
5. **Ordering**: Order the results by a relevant column if applicable (e.g., timestamp for recent records).
6. **Valid query**: Make sure the query is syntactically and functionally correct.
7. **Conditions** : For the common columns, the same condition should be applied to all the tables (e.g. latitude, longitude, model, year...)
9. **Join tables** : If you need to join table, you should join them with year feature.
10. **Model** : For each table, you need to add a condition on the model to be equal to {model}
### Provided Database Schema:
{table_info}
### Relevant Tables:
{relevant_tables}
**Question:** {input}
**SQL Query:**"""
plot_prompt_template = """You are a data visualization expert. Given an input question and an SQL Query, generate an insightful plot according to the question.
### Instructions
1. **Use only the column names provided**. The data will be provided as a Pandas DataFrame `df` with the columns present in the SELECT.
2. Generate the Python Plotly code to chart the results using `df` and the column names.
3. Make as complete a graph as possible to answer the question, and make it as easy to understand as possible.
4. **Response with only Python code**. Do not answer with any explanations -- just the code.
5. **Specific cases** :
- For a question about the evolution of something, it is also relevant to plot the data with also the sliding average for a period of 20 years for example.
### SQL Query:
{sql_query}
**Question:** {input}
**Python code:**
"""
|