From 72f18fd08ba5f02b66ed64905e467af4f4e3bbfe Mon Sep 17 00:00:00 2001 From: vinoyang Date: Sat, 13 May 2023 01:04:28 +0800 Subject: [PATCH] Provide get current date function dialect for other DBs (#4576) # Provide get current date function dialect for other DBs Fixes # (issue) ## Before submitting ## Who can review? Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested: @eyurtsev --- langchain/chains/sql_database/prompt.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/langchain/chains/sql_database/prompt.py b/langchain/chains/sql_database/prompt.py index 943e22e6..83acefc4 100644 --- a/langchain/chains/sql_database/prompt.py +++ b/langchain/chains/sql_database/prompt.py @@ -44,6 +44,7 @@ _duckdb_prompt = """You are a DuckDB expert. Given an input question, first crea 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. 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 today() function to get the current date, if the question involves "today". Use the following format: @@ -66,6 +67,7 @@ _googlesql_prompt = """You are a GoogleSQL expert. Given an input question, firs 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 GoogleSQL. 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 backticks (`) 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: @@ -89,6 +91,7 @@ _mssql_prompt = """You are an MS SQL expert. Given an input question, first crea Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the TOP clause as per MS SQL. 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 square brackets ([]) 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 CAST(GETDATE() as date) function to get the current date, if the question involves "today". Use the following format: @@ -111,6 +114,7 @@ _mysql_prompt = """You are a MySQL expert. Given an input question, first create 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 MySQL. 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 backticks (`) 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 CURDATE() function to get the current date, if the question involves "today". Use the following format: @@ -134,6 +138,7 @@ _mariadb_prompt = """You are a MariaDB expert. Given an input question, first cr 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 MariaDB. 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 backticks (`) 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 CURDATE() function to get the current date, if the question involves "today". Use the following format: @@ -157,6 +162,7 @@ _oracle_prompt = """You are an Oracle SQL expert. Given an input question, first Unless the user specifies in the question a specific number of examples to obtain, query for at most {top_k} results using the FETCH FIRST n ROWS ONLY clause as per Oracle SQL. 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 TRUNC(SYSDATE) function to get the current date, if the question involves "today". Use the following format: @@ -180,6 +186,7 @@ _postgres_prompt = """You are a PostgreSQL expert. Given an input question, firs 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 PostgreSQL. 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: @@ -202,6 +209,7 @@ _sqlite_prompt = """You are a SQLite expert. Given an input question, first crea 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 SQLite. 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". Use the following format: @@ -247,6 +255,7 @@ _prestodb_prompt = """You are a PrestoDB expert. Given an input question, first 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 PrestoDB. 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: