Add deps and minor cleaning to cookbooks (#11886)

pull/11501/head
Lance Martin 12 months ago committed by GitHub
parent e3664272f0
commit 18a4fdded6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,17 +12,19 @@
"source": [ "source": [
"## LLaMA2 chat with SQL\n", "## LLaMA2 chat with SQL\n",
"\n", "\n",
"LangChain makes it easy to build diverse chains from building blocks.\n", "[LangChain Expression Langugae (LCEL)](https://python.langchain.com/docs/expression_language/) makes it easy to build diverse chains \"from scratch.\"\n",
"\n", "\n",
"![cake.png](attachment:02bd3e70-6db4-40e2-9f6b-c83127eb2339.png)\n", "This cookbook shows how to combine three ideas using LCEL:\n",
"\n",
"* We want to enable a chat application\n",
"* We want to apply chat to a SQL database\n",
"* We want to use an open source LLM (LLaMA2)\n",
"\n", "\n",
"This cookbook shows how to combine three ideas:\n", "![cake.png](attachment:02bd3e70-6db4-40e2-9f6b-c83127eb2339.png)\n",
"\n", "\n",
"* Chat\n", "We can do this on SQLite DB containing 2023-24 NBA rosters.\n",
"* SQL\n",
"* An OSS model (LLaMA2)\n",
"\n", "\n",
"It demonstrates chat over a SQLite DB containing 2023-24 NBA rosters." "## Packages"
] ]
}, },
{ {
@ -44,12 +46,12 @@
"\n", "\n",
"Use Replicate API for `llama-2-13b-chat`.\n", "Use Replicate API for `llama-2-13b-chat`.\n",
"\n", "\n",
"Note there is also support for running LLaMA2 locally (see [here](https://python.langchain.com/docs/guides/local_llms)). " "Note: there is also support for running `LLaMA2` locally (see [here](https://python.langchain.com/docs/guides/local_llms))."
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27, "execution_count": 1,
"id": "416ecce7-8aec-4145-b3f1-587a9b8a4fe9", "id": "416ecce7-8aec-4145-b3f1-587a9b8a4fe9",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -69,9 +71,6 @@
"\n", "\n",
"# Replicate API\n", "# Replicate API\n",
"llama2_13b_chat = \"meta/llama-2-13b-chat:f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d\"\n", "llama2_13b_chat = \"meta/llama-2-13b-chat:f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d\"\n",
"\n",
"# Set the system_prompt so that LLaMA will generate only the SQL statement, instead of being wordy and adding something like\n",
"# \"Sure! Here's the SQL query for the given input question: \" before the SQL query; otherwise custom parsing will be needed.\n",
"llm = Replicate(\n", "llm = Replicate(\n",
" model=llama2_13b_chat,\n", " model=llama2_13b_chat,\n",
" input={\"temperature\": 0.01, \n", " input={\"temperature\": 0.01, \n",
@ -87,12 +86,14 @@
"source": [ "source": [
"## DB\n", "## DB\n",
"\n", "\n",
"Connect to a SQLite DB." "Connect to a SQLite DB.\n",
"\n",
"To create this particular DB, you can use the code and follow the steps shown [here](https://github.com/facebookresearch/llama-recipes/blob/main/demo_apps/StructuredLlama.ipynb)."
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28, "execution_count": 2,
"id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c", "id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -119,7 +120,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 72, "execution_count": 3,
"id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b", "id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -129,7 +130,7 @@
"\" SELECT * FROM nba_roster WHERE NAME = 'Klay Thompson';\"" "\" SELECT * FROM nba_roster WHERE NAME = 'Klay Thompson';\""
] ]
}, },
"execution_count": 72, "execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save