Skip to content

Commit 3381012

Browse files
rlancemartinErick Friis
andauthored
Update chat prompt structure in LLaMA SQL cookbook (#12364)
Co-authored-by: Erick Friis <[email protected]>
1 parent 58b90f3 commit 3381012

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

cookbook/LLaMA2_sql_chat.ipynb

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
{
4949
"cell_type": "code",
50-
"execution_count": 8,
50+
"execution_count": 1,
5151
"id": "6a75a5c6-34ee-4ab9-a664-d9b432d812ee",
5252
"metadata": {},
5353
"outputs": [
@@ -80,7 +80,7 @@
8080
},
8181
{
8282
"cell_type": "code",
83-
"execution_count": 12,
83+
"execution_count": 2,
8484
"id": "ce96f7ea-b3d5-44e1-9fa5-a79e04a9e1fb",
8585
"metadata": {},
8686
"outputs": [],
@@ -103,7 +103,7 @@
103103
},
104104
{
105105
"cell_type": "code",
106-
"execution_count": 13,
106+
"execution_count": 3,
107107
"id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c",
108108
"metadata": {},
109109
"outputs": [],
@@ -133,7 +133,7 @@
133133
},
134134
{
135135
"cell_type": "code",
136-
"execution_count": 14,
136+
"execution_count": 4,
137137
"id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b",
138138
"metadata": {},
139139
"outputs": [
@@ -143,7 +143,7 @@
143143
"' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
144144
]
145145
},
146-
"execution_count": 14,
146+
"execution_count": 4,
147147
"metadata": {},
148148
"output_type": "execute_result"
149149
}
@@ -260,8 +260,8 @@
260260
},
261261
{
262262
"cell_type": "code",
263-
"execution_count": 19,
264-
"id": "1985aa1c-eb8f-4fb1-a54f-c8aa10744687",
263+
"execution_count": 7,
264+
"id": "022868f2-128e-42f5-8d90-d3bb2f11d994",
265265
"metadata": {},
266266
"outputs": [
267267
{
@@ -270,7 +270,7 @@
270270
"' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
271271
]
272272
},
273-
"execution_count": 19,
273+
"execution_count": 7,
274274
"metadata": {},
275275
"output_type": "execute_result"
276276
}
@@ -280,16 +280,14 @@
280280
"from langchain.memory import ConversationBufferMemory\n",
281281
"from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
282282
"\n",
283-
"template = \"\"\"Based on the table schema below, write a SQL query that would answer the user's question:\n",
283+
"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",
284284
"{schema}\n",
285-
"\n",
286-
"Question: {question}\n",
287-
"SQL Query:\"\"\"\n",
285+
"\"\"\"\n",
288286
"prompt = ChatPromptTemplate.from_messages(\n",
289287
" [\n",
290-
" (\"system\", \"Given an input question, convert it to a SQL query. No pre-amble.\"),\n",
288+
" (\"system\", template),\n",
291289
" MessagesPlaceholder(variable_name=\"history\"),\n",
292-
" (\"human\", template),\n",
290+
" (\"human\", \"{question}\"),\n",
293291
" ]\n",
294292
")\n",
295293
"\n",
@@ -319,27 +317,6 @@
319317
"sql_response_memory.invoke({\"question\": \"What team is Klay Thompson on?\"})"
320318
]
321319
},
322-
{
323-
"cell_type": "code",
324-
"execution_count": 20,
325-
"id": "0b45818a-1498-441d-b82d-23c29428c2bb",
326-
"metadata": {},
327-
"outputs": [
328-
{
329-
"data": {
330-
"text/plain": [
331-
"' SELECT \"SALARY\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
332-
]
333-
},
334-
"execution_count": 20,
335-
"metadata": {},
336-
"output_type": "execute_result"
337-
}
338-
],
339-
"source": [
340-
"sql_response_memory.invoke({\"question\": \"What is his salary?\"})"
341-
]
342-
},
343320
{
344321
"cell_type": "code",
345322
"execution_count": 21,

0 commit comments

Comments
 (0)