mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
1b050b98f5
Corrected some spelling mistakes and grammatical errors CC: @baskaryan, @eyurtsev, @hwchase17. --------- Co-authored-by: Ishita Chauhan <136303787+IshitaChauhanShortHillsAI@users.noreply.github.com> Co-authored-by: Aashish Saini <141953346+AashishSainiShorthillsAI@users.noreply.github.com> Co-authored-by: ManpreetShorthillsAI <142380984+ManpreetShorthillsAI@users.noreply.github.com> Co-authored-by: AryamanJaiswalShorthillsAI <142397527+AryamanJaiswalShorthillsAI@users.noreply.github.com> Co-authored-by: Adarsh Shrivastav <142413097+AdarshKumarShorthillsAI@users.noreply.github.com> Co-authored-by: Vishal <141389263+VishalYadavShorthillsAI@users.noreply.github.com> Co-authored-by: ChetnaGuptaShorthillsAI <142381084+ChetnaGuptaShorthillsAI@users.noreply.github.com> Co-authored-by: PankajKumarShorthillsAI <142473460+PankajKumarShorthillsAI@users.noreply.github.com> Co-authored-by: AbhishekYadavShorthillsAI <142393903+AbhishekYadavShorthillsAI@users.noreply.github.com> Co-authored-by: AmitSinghShorthillsAI <142410046+AmitSinghShorthillsAI@users.noreply.github.com> Co-authored-by: Md Nazish Arman <142379599+MdNazishArmanShorthillsAI@users.noreply.github.com> Co-authored-by: KamalSharmaShorthillsAI <142474019+KamalSharmaShorthillsAI@users.noreply.github.com> Co-authored-by: Lakshya <lakshyagupta87@yahoo.com> Co-authored-by: Aayush <142384656+AayushShorthillsAI@users.noreply.github.com> Co-authored-by: AnujMauryaShorthillsAI <142393269+AnujMauryaShorthillsAI@users.noreply.github.com> Co-authored-by: ishita <chauhanishita5356@gmail.com>
86 lines
4.5 KiB
Python
86 lines
4.5 KiB
Python
# flake8: noqa
|
|
from langchain.prompts.prompt import PromptTemplate
|
|
|
|
|
|
PROMPT_SUFFIX = """Only use the following tables:
|
|
{table_info}
|
|
|
|
Question: {input}"""
|
|
|
|
_VECTOR_SQL_DEFAULT_TEMPLATE = """You are a {dialect} expert. 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 to the input question.
|
|
{dialect} queries has a vector distance function called `DISTANCE(column, array)` to compute relevance to the user's question and sort the feature array column by the relevance.
|
|
When the query is asking for {top_k} closest row, you have to use this distance function to calculate distance to entity's array on vector column and order by the distance to retrieve relevant rows.
|
|
|
|
*NOTICE*: `DISTANCE(column, array)` only accept an array column as its first argument and a `NeuralArray(entity)` as its second argument. You also need a user defined function called `NeuralArray(entity)` to retrieve the entity's array.
|
|
|
|
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 should only order according to the distance function.
|
|
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". `ORDER BY` clause should always be after `WHERE` clause. DO NOT add semicolon to the end of SQL. Pay attention to the comment in table schema.
|
|
|
|
Use the following format:
|
|
|
|
Question: "Question here"
|
|
SQLQuery: "SQL Query to run"
|
|
SQLResult: "Result of the SQLQuery"
|
|
Answer: "Final answer here"
|
|
"""
|
|
|
|
VECTOR_SQL_PROMPT = PromptTemplate(
|
|
input_variables=["input", "table_info", "dialect", "top_k"],
|
|
template=_VECTOR_SQL_DEFAULT_TEMPLATE + PROMPT_SUFFIX,
|
|
)
|
|
|
|
|
|
_myscale_prompt = """You are a MyScale expert. Given an input question, first create a syntactically correct MyScale query to run, then look at the results of the query and return the answer to the input question.
|
|
MyScale queries has a vector distance function called `DISTANCE(column, array)` to compute relevance to the user's question and sort the feature array column by the relevance.
|
|
When the query is asking for {top_k} closest row, you have to use this distance function to calculate distance to entity's array on vector column and order by the distance to retrieve relevant rows.
|
|
|
|
*NOTICE*: `DISTANCE(column, array)` only accept an array column as its first argument and a `NeuralArray(entity)` as its second argument. You also need a user defined function called `NeuralArray(entity)` to retrieve the entity's array.
|
|
|
|
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 MyScale. You should only order according to the distance function.
|
|
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". `ORDER BY` clause should always be after `WHERE` clause. DO NOT add semicolon to the end of SQL. Pay attention to the comment in table schema.
|
|
|
|
Use the following format:
|
|
|
|
======== table info ========
|
|
<some table infos>
|
|
|
|
Question: "Question here"
|
|
SQLQuery: "SQL Query to run"
|
|
|
|
|
|
Here are some examples:
|
|
|
|
======== table info ========
|
|
CREATE TABLE "ChatPaper" (
|
|
abstract String,
|
|
id String,
|
|
vector Array(Float32),
|
|
) ENGINE = ReplicatedReplacingMergeTree()
|
|
ORDER BY id
|
|
PRIMARY KEY id
|
|
|
|
Question: What is Feature Pyramid Network?
|
|
SQLQuery: SELECT ChatPaper.title, ChatPaper.id, ChatPaper.authors FROM ChatPaper ORDER BY DISTANCE(vector, NeuralArray(PaperRank contribution)) LIMIT {top_k}
|
|
|
|
|
|
Let's begin:
|
|
======== table info ========
|
|
{table_info}
|
|
|
|
Question: {input}
|
|
SQLQuery: """
|
|
|
|
MYSCALE_PROMPT = PromptTemplate(
|
|
input_variables=["input", "table_info", "top_k"],
|
|
template=_myscale_prompt + PROMPT_SUFFIX,
|
|
)
|
|
|
|
|
|
VECTOR_SQL_PROMPTS = {
|
|
"myscale": MYSCALE_PROMPT,
|
|
}
|