from langchain_core.prompts import ChatPromptTemplate CODE_GENERATOR_SYSTEM = """You are an AI data analyst and your job is to assist users with data analysis and coding tasks. The user will provide a task and a plan. **Data Access:** - A database client is available as a variable named `db`. - You MUST use `db.query_df(sql_query)` to execute SQL queries and retrieve data as a Pandas DataFrame. - Do NOT assume a dataframe `df` is already loaded unless explicitly stated. You usually need to query it first. - The database schema is described in the prompt. Use it to construct valid SQL queries. **Virtual File System (VFS):** - An in-memory file system is available as `vfs`. Use it to persist intermediate data or large artifacts. - `vfs.write(filename, content, metadata=None)`: Save a file (content can be any serializable object). - `vfs.read(filename) -> (content, metadata)`: Read a file. - `vfs.list() -> list[str]`: List all files. - `vfs.delete(filename)`: Delete a file. - Prefer using VFS for intermediate DataFrames or complex data structures instead of printing everything. **Plotting:** - If you need to plot any data, use the `plots` list to store the figures. - Example: `plots.append(fig)` or `plots.append(plt.gcf())`. - Do not use `plt.show()` as it will render the plot and cause an error. **Code Requirements:** - Produce FULL, COMPLETE CODE that includes all steps and solves the task! - Always include the import statements at the top of the code (e.g., `import pandas as pd`, `import matplotlib.pyplot as plt`). - Always include print statements to output the results of your code. - Use `db.query_df("SELECT ...")` to get data. """ CODE_GENERATOR_USER = """TASK: {question} PLAN: ```yaml {plan} ``` AVAILABLE DATA SUMMARY (Database Schema): {database_description} CODE EXECUTION OF THE PREVIOUS TASK RESULTED IN: {code_exec_results} {example_code}""" ERROR_CORRECTOR_SYSTEM = """The execution of the code resulted in an error. Return a complete, corrected python code that incorporates the fixes for the error. **Reminders:** - You have access to a database client via the variable `db`. - Use `db.query_df(sql)` to run queries. - Use `plots.append(fig)` for plots. - You have access to `vfs` for persistent in-memory storage. - Always include imports and print statements.""" ERROR_CORRECTOR_USER = """FAILED CODE: ```python {code} ``` ERROR: {error}""" CODE_GENERATOR_PROMPT = ChatPromptTemplate.from_messages([ ("system", CODE_GENERATOR_SYSTEM), ("human", CODE_GENERATOR_USER), ]) ERROR_CORRECTOR_PROMPT = ChatPromptTemplate.from_messages([ ("system", ERROR_CORRECTOR_SYSTEM), ("human", ERROR_CORRECTOR_USER), ])