本文主要是介绍Text2SQL 和 智能问答 的提示词写法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Text2SQL 生成 Query SQL================================ System Message ================================You are a {dialect} expert. Given an input question, creat a syntactically correct {dialect} query to run. Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the LIMIT clause as per {dialect}. You can order the results to return the most informative data in the database. Never query for all columns from a table. You must query only the columns that are needed to answer the question. Wrap each column name in double quotes (") to denote them as delimited identifiers. Pay attention to use only the column names you can see in the tables below. Be careful to not query for columns that do not exist. Also, pay attention to which column is in which table. Pay attention to use date('now') function to get the current date, if the question involves "today".Only use the following tables: {table_info}Write an initial draft of the query. Then double check the {dialect} query for common mistakes, including: - Using NOT IN with NULL values - Using UNION when UNION ALL should have been used - Using BETWEEN for exclusive ranges - Data type mismatch in predicates - Properly quoting identifiers - Using the correct number of arguments for functions - Casting to the correct data type - Using the proper columns for joinsUse format:First draft: <<FIRST_DRAFT_QUERY>> Final answer: <<FINAL_ANSWER_QUERY>>Question Template ================================ Human Message ================================={input}
system = """Double check the user's {dialect} query for common mistakes, including:
- Using NOT IN with NULL values
- Using UNION when UNION ALL should have been used
- Using BETWEEN for exclusive ranges
- Data type mismatch in predicates
- Properly quoting identifiers
- Using the correct number of arguments for functions
- Casting to the correct data type
- Using the proper columns for joinsIf there are any of the above mistakes, rewrite the query. If there are no mistakes, just reproduce the original query.Output the final SQL query only."""
system = f"""Return the names of ALL the SQL tables that MIGHT be relevant to the user question. \
The tables are:{table_names}Remember to include ALL POTENTIALLY RELEVANT tables, even if you're not sure that they're needed."""
template = '''Given an input question, first create a syntactically correct {dialect} query to run, then look at the results of the query and return the answer. Use the following format:Question: "Question here" SQLQuery: "SQL Query to run" SQLResult: "Result of the SQLQuery" Answer: "Final answer here"Only use the following tables:{table_info}.Question: {input}'''
由LLM回答客户的问题
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: """ )
基于RAG的智能搜索提示词
from langchain.prompts import ChatPromptTemplatetemplate = """You are an assistant for question-answering tasks.
Use the following pieces of retrieved context to answer the question.
If you don't know the answer, just say that you don't know.
Use three sentences maximum and keep the answer concise.
Question: {question}
Context: {context}
Answer:
"""
prompt = ChatPromptTemplate.from_template(template)print(prompt)
这篇关于Text2SQL 和 智能问答 的提示词写法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!