Chong-U Lim
commited on
Commit
·
7077707
1
Parent(s):
4169230
Update readme
Browse files- README.md +9 -8
- notebook.ipynb +52 -14
README.md
CHANGED
@@ -14,18 +14,19 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
14 |
|
15 |
```
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
# In (codebasics-langchain-crash-course)
|
25 |
|
26 |
# Acknowledgements
|
27 |
The code is based on original tutorial series by [@codebasics](https://twitter.com/codebasicshub).
|
28 |
-
* [LangChain Crash Course For Beginners](https://www.youtube.com/watch?v=nAmC7SoVLd8&list=PLeo1K3hjS3uu0N_0W6giDXzZIcB07Ng_F&ab_channel=codebasics)
|
29 |
-
|
30 |
|
31 |
```
|
|
|
14 |
|
15 |
```
|
16 |
|
17 |
+
# Introduction
|
18 |
+
This repository contains the code for generating a restaurant name and menu items based on an input cuisine.
|
19 |
+
It makes use of [LangChain](http://www.langchain.com) and OpenAI's chatGPT API, along with [Gradio](http://gradio.app) to serve an application.
|
20 |
|
21 |
+
The original [LangChain Crash Course For Beginners tutorial](https://www.youtube.com/watch?v=nAmC7SoVLd8&list=PLeo1K3hjS3uu0N_0W6giDXzZIcB07Ng_F&ab_channel=codebasics) by [@codebasics](https://twitter.com/codebasicshub) used an older version of LangChain and Streamlit for the app.
|
22 |
+
|
23 |
+
The code here uses updated libraries and Gradio in place of Streamlit.
|
24 |
+
|
25 |
+
# Demo
|
26 |
+
You can play around with the demo app on [this Hugging Face Space](https://huggingface.co/spaces/chongdashu/langchain-crash-course-gradio)
|
27 |
|
|
|
28 |
|
29 |
# Acknowledgements
|
30 |
The code is based on original tutorial series by [@codebasics](https://twitter.com/codebasicshub).
|
|
|
|
|
31 |
|
32 |
```
|
notebook.ipynb
CHANGED
@@ -6,8 +6,8 @@
|
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
-
"# !pip install -q langchain\n",
|
10 |
-
"# !pip install -q openai"
|
11 |
]
|
12 |
},
|
13 |
{
|
@@ -192,26 +192,18 @@
|
|
192 |
},
|
193 |
{
|
194 |
"cell_type": "code",
|
195 |
-
"execution_count":
|
196 |
"metadata": {},
|
197 |
"outputs": [
|
198 |
-
{
|
199 |
-
"name": "stderr",
|
200 |
-
"output_type": "stream",
|
201 |
-
"text": [
|
202 |
-
"/home/chong-u/mambaforge/envs/codebasics-langchain-crash-course/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.0 and will be removed in 0.2.0. Use invoke instead.\n",
|
203 |
-
" warn_deprecated(\n"
|
204 |
-
]
|
205 |
-
},
|
206 |
{
|
207 |
"data": {
|
208 |
"text/plain": [
|
209 |
"{'cuisine': 'Singaporean',\n",
|
210 |
-
" 'restaurant_name': '\\n
|
211 |
-
" 'menu_items': '\\n\\
|
212 |
]
|
213 |
},
|
214 |
-
"execution_count":
|
215 |
"metadata": {},
|
216 |
"output_type": "execute_result"
|
217 |
}
|
@@ -228,6 +220,52 @@
|
|
228 |
"chain.invoke({\"cuisine\": \"Singaporean\"})"
|
229 |
]
|
230 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
{
|
232 |
"cell_type": "code",
|
233 |
"execution_count": null,
|
|
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
+
"# !pip install -q langchain==0.1.9\n",
|
10 |
+
"# !pip install -q openai==1.13.3"
|
11 |
]
|
12 |
},
|
13 |
{
|
|
|
192 |
},
|
193 |
{
|
194 |
"cell_type": "code",
|
195 |
+
"execution_count": 13,
|
196 |
"metadata": {},
|
197 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
{
|
199 |
"data": {
|
200 |
"text/plain": [
|
201 |
"{'cuisine': 'Singaporean',\n",
|
202 |
+
" 'restaurant_name': '\\n\"Straits Flavors\"',\n",
|
203 |
+
" 'menu_items': '\\n\\nSambal Shrimp, Roti Canai, Nasi Lemak, Beef Rendang, Satay Skewers, Hainanese Chicken Rice, Char Kway Teow, Laksa Soup, Rojak Salad, Curry Puffs'}"
|
204 |
]
|
205 |
},
|
206 |
+
"execution_count": 13,
|
207 |
"metadata": {},
|
208 |
"output_type": "execute_result"
|
209 |
}
|
|
|
220 |
"chain.invoke({\"cuisine\": \"Singaporean\"})"
|
221 |
]
|
222 |
},
|
223 |
+
{
|
224 |
+
"cell_type": "markdown",
|
225 |
+
"metadata": {},
|
226 |
+
"source": [
|
227 |
+
"## Agents"
|
228 |
+
]
|
229 |
+
},
|
230 |
+
{
|
231 |
+
"cell_type": "code",
|
232 |
+
"execution_count": 20,
|
233 |
+
"metadata": {},
|
234 |
+
"outputs": [],
|
235 |
+
"source": [
|
236 |
+
"!pip install -q wikipedia\n",
|
237 |
+
"!pip install -q numexpr # for llm-math"
|
238 |
+
]
|
239 |
+
},
|
240 |
+
{
|
241 |
+
"cell_type": "code",
|
242 |
+
"execution_count": 21,
|
243 |
+
"metadata": {
|
244 |
+
"notebookRunGroups": {
|
245 |
+
"groupValue": "1"
|
246 |
+
}
|
247 |
+
},
|
248 |
+
"outputs": [],
|
249 |
+
"source": [
|
250 |
+
"from langchain.agents import AgentType, initialize_agent, load_tools\n",
|
251 |
+
"from langchain.llms import OpenAI"
|
252 |
+
]
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"cell_type": "code",
|
256 |
+
"execution_count": 22,
|
257 |
+
"metadata": {},
|
258 |
+
"outputs": [],
|
259 |
+
"source": [
|
260 |
+
"tools = load_tools([\"wikipedia\", \"llm-math\"], llm=llm)\n",
|
261 |
+
"\n",
|
262 |
+
"initialize_agent(\n",
|
263 |
+
" tools,\n",
|
264 |
+
" llm,\n",
|
265 |
+
" agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,\n",
|
266 |
+
")"
|
267 |
+
]
|
268 |
+
},
|
269 |
{
|
270 |
"cell_type": "code",
|
271 |
"execution_count": null,
|