Prompt Template for SQL #11847
Replies: 1 comment
-
Hey @PradiptaAtByteIQMind-Graph2023! Great to see you back. What's cooking with those tables? To add a prompt template to your
Here's a simplified example of how you might implement steps 2 through 4: # Step 2: Modify the __init__ method to accept custom prompt templates
def __init__(self, ..., custom_prompt_templates: Dict[str, BasePromptTemplate] = None):
...
self._custom_prompt_templates = custom_prompt_templates or {}
# Step 3: Assuming you have a mapping of table names to prompt templates
table_prompt_templates = {
"table1": PromptTemplate("Your custom prompt for table 1"),
"table2": PromptTemplate("Your custom prompt for table 2"),
# Add templates for all 10 tables
}
# Initialize your NLSQLTableQueryEngine or similar class with this mapping
nlsql_engine = NLSQLTableQueryEngine(..., custom_prompt_templates=table_prompt_templates)
# Step 4: Utilize the prompt templates in query processing
def _query_sql_other(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:
...
# Determine the table being queried (this is a placeholder, you'll need to implement this based on your query structure)
table_name = determine_table_from_query(query_bundle.query_str)
# Fetch the appropriate prompt template based on the table
prompt_template = self._custom_prompt_templates.get(table_name, self._sql_join_synthesis_prompt)
# Use the fetched prompt template in the prediction
response_str = self._llm.predict(
prompt_template,
query_str=query_bundle.query_str,
sql_query_str=sql_query,
sql_response_str=str(sql_response),
query_engine_query_str=new_query.query_str,
query_engine_response_str=str(other_response),
)
... This example assumes you have a way to determine which table is being queried ( Please note that the The purpose of You can refer to the source code here for more details. Sources
|
Beta Was this translation helpful? Give feedback.
-
Hi
I have 10 tables in my database. want to add the prompt template to my NLSQLTableQueryEngine. Let me know how can I add it.
Thanks and Regards
Pradipta
Beta Was this translation helpful? Give feedback.
All reactions