Spaces:
Build error
Build error
from examples import get_example_selector | |
from langchain_core.prompts import ( | |
ChatPromptTemplate, | |
MessagesPlaceholder, | |
FewShotChatMessagePromptTemplate, | |
PromptTemplate | |
) | |
example_prompt = ChatPromptTemplate.from_messages([ | |
("human", "{input}\nSQLQuery:"), | |
("ai", "{query}"), | |
]) | |
def create_prompts(api_key): | |
example_selector = get_example_selector(api_key) | |
few_shot_prompt = FewShotChatMessagePromptTemplate( | |
example_prompt=example_prompt, | |
example_selector=example_selector, | |
input_variables=["input", "top_k"], | |
) | |
final_prompt = ChatPromptTemplate.from_messages([ | |
("system", "You are a Postgres SQL expert. Given an input question, create a syntactically correct Postgres SQL query to run. Unless otherwise specified.\n\nHere is the relevant table info: {table_info}\n\nBelow are a number of examples of questions and their corresponding SQL queries."), | |
few_shot_prompt, | |
MessagesPlaceholder(variable_name="messages"), | |
("human", "{input}"), | |
]) | |
answer_prompt = PromptTemplate.from_template( | |
"""Given the following user question, corresponding SQL query, and SQL result, answer the user question. | |
Question: {question} | |
SQL Query: {query} | |
SQL Result: {result} | |
Answer: """ | |
) | |
return final_prompt, answer_prompt |