From 274dc4bc53d3b3642325aca8b0c2dd8489d565f0 Mon Sep 17 00:00:00 2001 From: zvrr Date: Wed, 10 May 2023 22:22:42 +0800 Subject: [PATCH] add clickhouse prompt (#4456) # Add clickhouse prompt Add clickhouse database sql prompt --- langchain/chains/sql_database/prompt.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/langchain/chains/sql_database/prompt.py b/langchain/chains/sql_database/prompt.py index 8fd3b46a..c0dfe5f2 100644 --- a/langchain/chains/sql_database/prompt.py +++ b/langchain/chains/sql_database/prompt.py @@ -220,6 +220,28 @@ SQLITE_PROMPT = PromptTemplate( template=_sqlite_prompt, ) +_clickhouse_prompt = """You are a ClickHouse expert. Given an input question, first create a syntactically correct Clic 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 ClickHouse. 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. + +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}""" + +CLICKHOUSE_PROMPT = PromptTemplate( + input_variables=["input", "table_info", "top_k"], + template=_clickhouse_prompt, +) + SQL_PROMPTS = { "duckdb": DUCKDB_PROMPT, @@ -230,4 +252,5 @@ SQL_PROMPTS = { "oracle": ORACLE_PROMPT, "postgresql": POSTGRES_PROMPT, "sqlite": SQLITE_PROMPT, + "clickhouse": CLICKHOUSE_PROMPT, }