|
47 | 47 | },
|
48 | 48 | {
|
49 | 49 | "cell_type": "code",
|
50 |
| - "execution_count": 8, |
| 50 | + "execution_count": 1, |
51 | 51 | "id": "6a75a5c6-34ee-4ab9-a664-d9b432d812ee",
|
52 | 52 | "metadata": {},
|
53 | 53 | "outputs": [
|
|
80 | 80 | },
|
81 | 81 | {
|
82 | 82 | "cell_type": "code",
|
83 |
| - "execution_count": 12, |
| 83 | + "execution_count": 2, |
84 | 84 | "id": "ce96f7ea-b3d5-44e1-9fa5-a79e04a9e1fb",
|
85 | 85 | "metadata": {},
|
86 | 86 | "outputs": [],
|
|
103 | 103 | },
|
104 | 104 | {
|
105 | 105 | "cell_type": "code",
|
106 |
| - "execution_count": 13, |
| 106 | + "execution_count": 3, |
107 | 107 | "id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c",
|
108 | 108 | "metadata": {},
|
109 | 109 | "outputs": [],
|
|
133 | 133 | },
|
134 | 134 | {
|
135 | 135 | "cell_type": "code",
|
136 |
| - "execution_count": 14, |
| 136 | + "execution_count": 4, |
137 | 137 | "id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b",
|
138 | 138 | "metadata": {},
|
139 | 139 | "outputs": [
|
|
143 | 143 | "' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
|
144 | 144 | ]
|
145 | 145 | },
|
146 |
| - "execution_count": 14, |
| 146 | + "execution_count": 4, |
147 | 147 | "metadata": {},
|
148 | 148 | "output_type": "execute_result"
|
149 | 149 | }
|
|
260 | 260 | },
|
261 | 261 | {
|
262 | 262 | "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", |
265 | 265 | "metadata": {},
|
266 | 266 | "outputs": [
|
267 | 267 | {
|
|
270 | 270 | "' SELECT \"Team\" FROM nba_roster WHERE \"NAME\" = \\'Klay Thompson\\';'"
|
271 | 271 | ]
|
272 | 272 | },
|
273 |
| - "execution_count": 19, |
| 273 | + "execution_count": 7, |
274 | 274 | "metadata": {},
|
275 | 275 | "output_type": "execute_result"
|
276 | 276 | }
|
|
280 | 280 | "from langchain.memory import ConversationBufferMemory\n",
|
281 | 281 | "from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
|
282 | 282 | "\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", |
284 | 284 | "{schema}\n",
|
285 |
| - "\n", |
286 |
| - "Question: {question}\n", |
287 |
| - "SQL Query:\"\"\"\n", |
| 285 | + "\"\"\"\n", |
288 | 286 | "prompt = ChatPromptTemplate.from_messages(\n",
|
289 | 287 | " [\n",
|
290 |
| - " (\"system\", \"Given an input question, convert it to a SQL query. No pre-amble.\"),\n", |
| 288 | + " (\"system\", template),\n", |
291 | 289 | " MessagesPlaceholder(variable_name=\"history\"),\n",
|
292 |
| - " (\"human\", template),\n", |
| 290 | + " (\"human\", \"{question}\"),\n", |
293 | 291 | " ]\n",
|
294 | 292 | ")\n",
|
295 | 293 | "\n",
|
|
319 | 317 | "sql_response_memory.invoke({\"question\": \"What team is Klay Thompson on?\"})"
|
320 | 318 | ]
|
321 | 319 | },
|
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 |
| - }, |
343 | 320 | {
|
344 | 321 | "cell_type": "code",
|
345 | 322 | "execution_count": 21,
|
|
0 commit comments