From 5508baf1eb991240030ce0dde57678619c64063a Mon Sep 17 00:00:00 2001 From: karynzv Date: Wed, 23 Aug 2023 18:33:37 +0100 Subject: [PATCH] Add CrateDB prompt (#9657) Adds a prompt template for the CrateDB SQL dialect. --- .../langchain/chains/sql_database/prompt.py | 21 +++++++++++++++++++ libs/langchain/pyproject.toml | 2 +- pyproject.toml | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/chains/sql_database/prompt.py b/libs/langchain/langchain/chains/sql_database/prompt.py index 3b2040931f7..b212ecd3067 100644 --- a/libs/langchain/langchain/chains/sql_database/prompt.py +++ b/libs/langchain/langchain/chains/sql_database/prompt.py @@ -42,6 +42,26 @@ DECIDER_PROMPT = PromptTemplate( output_parser=CommaSeparatedListOutputParser(), ) +_cratedb_prompt = """You are a CrateDB expert. Given an input question, first create a syntactically correct CrateDB query to run, then look at the results of the query and return the answer to the input question. +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 CrateDB. 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 CURRENT_DATE function to get the current date, if the question involves "today". + +Use the following format: + +Question: Question here +SQLQuery: SQL Query to run +SQLResult: Result of the SQLQuery +Answer: Final answer here + +""" + +CRATEDB_PROMPT = PromptTemplate( + input_variables=["input", "table_info", "top_k"], + template=_cratedb_prompt + PROMPT_SUFFIX, +) + _duckdb_prompt = """You are a DuckDB expert. Given an input question, first create a syntactically correct DuckDB query to run, then look at the results of the query and return the answer to the input question. 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 DuckDB. 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. @@ -250,6 +270,7 @@ PRESTODB_PROMPT = PromptTemplate( SQL_PROMPTS = { + "crate": CRATEDB_PROMPT, "duckdb": DUCKDB_PROMPT, "googlesql": GOOGLESQL_PROMPT, "mssql": MSSQL_PROMPT, diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.toml index 61f05175ddb..296cbae35ba 100644 --- a/libs/langchain/pyproject.toml +++ b/libs/langchain/pyproject.toml @@ -391,4 +391,4 @@ ignore-regex = '.*(Stati Uniti|Tense=Pres).*' # whats is a typo but used frequently in queries so kept as is # aapply - async apply # unsecure - typo but part of API, decided to not bother for now -ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon' +ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate' diff --git a/pyproject.toml b/pyproject.toml index f886dda4996..dcf5c938a81 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,4 +40,4 @@ ignore-regex = '.*(Stati Uniti|Tense=Pres).*' # whats is a typo but used frequently in queries so kept as is # aapply - async apply # unsecure - typo but part of API, decided to not bother for now -ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon' \ No newline at end of file +ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate' \ No newline at end of file