Add deps and minor cleaning to cookbooks (#11886)

This commit is contained in:
Lance Martin
2023-10-16 13:37:51 -07:00
committed by GitHub
parent e3664272f0
commit 18a4fdded6
4 changed files with 120 additions and 167 deletions

View File

@@ -12,17 +12,19 @@
"source": [
"## LLaMA2 chat with SQL\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",
"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",
"![cake.png](attachment:02bd3e70-6db4-40e2-9f6b-c83127eb2339.png)\n",
"\n",
"This cookbook shows how to combine three ideas:\n",
"We can do this on SQLite DB containing 2023-24 NBA rosters.\n",
"\n",
"* Chat\n",
"* SQL\n",
"* An OSS model (LLaMA2)\n",
"\n",
"It demonstrates chat over a SQLite DB containing 2023-24 NBA rosters."
"## Packages"
]
},
{
@@ -44,12 +46,12 @@
"\n",
"Use Replicate API for `llama-2-13b-chat`.\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",
"execution_count": 27,
"execution_count": 1,
"id": "416ecce7-8aec-4145-b3f1-587a9b8a4fe9",
"metadata": {},
"outputs": [
@@ -69,9 +71,6 @@
"\n",
"# Replicate API\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",
" model=llama2_13b_chat,\n",
" input={\"temperature\": 0.01, \n",
@@ -87,12 +86,14 @@
"source": [
"## DB\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",
"execution_count": 28,
"execution_count": 2,
"id": "025bdd82-3bb1-4948-bc7c-c3ccd94fd05c",
"metadata": {},
"outputs": [],
@@ -119,7 +120,7 @@
},
{
"cell_type": "code",
"execution_count": 72,
"execution_count": 3,
"id": "5a4933ea-d9c0-4b0a-8177-ba4490c6532b",
"metadata": {},
"outputs": [
@@ -129,7 +130,7 @@
"\" SELECT * FROM nba_roster WHERE NAME = 'Klay Thompson';\""
]
},
"execution_count": 72,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}