Update chat prompt structure in LLaMA SQL cookbook (#12364)

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Lance Martin 2023-11-01 16:37:03 -07:00 committed by GitHub
parent 58b90f30b0
commit 33810126bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 1,
"id": "6a75a5c6-34ee-4ab9-a664-d9b432d812ee", "id": "6a75a5c6-34ee-4ab9-a664-d9b432d812ee",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -80,7 +80,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 2,
"id": "ce96f7ea-b3d5-44e1-9fa5-a79e04a9e1fb", "id": "ce96f7ea-b3d5-44e1-9fa5-a79e04a9e1fb",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -103,7 +103,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 3,
"id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c", "id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -133,7 +133,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 4,
"id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b", "id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -143,7 +143,7 @@
"' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'" "' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
] ]
}, },
"execution_count": 14, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -260,8 +260,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 7,
"id": "1985aa1c-eb8f-4fb1-a54f-c8aa10744687", "id": "022868f2-128e-42f5-8d90-d3bb2f11d994",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -270,7 +270,7 @@
"' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'" "' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
] ]
}, },
"execution_count": 19, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -280,16 +280,14 @@
"from langchain.memory import ConversationBufferMemory\n", "from langchain.memory import ConversationBufferMemory\n",
"from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n", "from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
"\n", "\n",
"template = \"\"\"Based on the table schema below, write a SQL query that would answer the user's question:\n", "template = \"\"\"Given an input question, convert it to a SQL query. No pre-amble. Based on the table schema below, write a SQL query that would answer the user's question:\n",
"{schema}\n", "{schema}\n",
"\n", "\"\"\"\n",
"Question: {question}\n",
"SQL Query:\"\"\"\n",
"prompt = ChatPromptTemplate.from_messages(\n", "prompt = ChatPromptTemplate.from_messages(\n",
" [\n", " [\n",
" (\"system\", \"Given an input question, convert it to a SQL query. No pre-amble.\"),\n", " (\"system\", template),\n",
" MessagesPlaceholder(variable_name=\"history\"),\n", " MessagesPlaceholder(variable_name=\"history\"),\n",
" (\"human\", template),\n", " (\"human\", \"{question}\"),\n",
" ]\n", " ]\n",
")\n", ")\n",
"\n", "\n",
@ -319,27 +317,6 @@
"sql_response_memory.invoke({\"question\": \"What team is Klay Thompson on?\"})" "sql_response_memory.invoke({\"question\": \"What team is Klay Thompson on?\"})"
] ]
}, },
{
"cell_type": "code",
"execution_count": 20,
"id": "0b45818a-1498-441d-b82d-23c29428c2bb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"' SELECT \"SALARY\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sql_response_memory.invoke({\"question\": \"What is his salary?\"})"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 21,