Chong-U Lim
commited on
Commit
·
f19aca2
1
Parent(s):
e2a35fb
Update notebook
Browse files- notebook.ipynb +46 -34
notebook.ipynb
CHANGED
@@ -12,7 +12,7 @@
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
-
"execution_count":
|
16 |
"metadata": {
|
17 |
"notebookRunGroups": {
|
18 |
"groupValue": ""
|
@@ -28,7 +28,7 @@
|
|
28 |
},
|
29 |
{
|
30 |
"cell_type": "code",
|
31 |
-
"execution_count":
|
32 |
"metadata": {},
|
33 |
"outputs": [
|
34 |
{
|
@@ -37,20 +37,20 @@
|
|
37 |
"text": [
|
38 |
"\n",
|
39 |
"\n",
|
40 |
-
"
|
41 |
]
|
42 |
}
|
43 |
],
|
44 |
"source": [
|
45 |
-
"from
|
46 |
"llm = OpenAI(temperature=0.6)\n",
|
47 |
-
"name = llm(\"I want to open a restaurant for Chinese food. Suggest a fancy name for this.\")\n",
|
48 |
"print(name)"
|
49 |
]
|
50 |
},
|
51 |
{
|
52 |
"cell_type": "code",
|
53 |
-
"execution_count":
|
54 |
"metadata": {},
|
55 |
"outputs": [
|
56 |
{
|
@@ -59,7 +59,7 @@
|
|
59 |
"'I want to open a restaurant for Mexican food. Suggest a fancy name for this.'"
|
60 |
]
|
61 |
},
|
62 |
-
"execution_count":
|
63 |
"metadata": {},
|
64 |
"output_type": "execute_result"
|
65 |
}
|
@@ -77,16 +77,24 @@
|
|
77 |
},
|
78 |
{
|
79 |
"cell_type": "code",
|
80 |
-
"execution_count":
|
81 |
"metadata": {},
|
82 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
{
|
84 |
"data": {
|
85 |
"text/plain": [
|
86 |
-
"'\\n\\n\"La Cantina de
|
87 |
]
|
88 |
},
|
89 |
-
"execution_count":
|
90 |
"metadata": {},
|
91 |
"output_type": "execute_result"
|
92 |
}
|
@@ -107,7 +115,7 @@
|
|
107 |
},
|
108 |
{
|
109 |
"cell_type": "code",
|
110 |
-
"execution_count":
|
111 |
"metadata": {},
|
112 |
"outputs": [],
|
113 |
"source": [
|
@@ -120,7 +128,7 @@
|
|
120 |
},
|
121 |
{
|
122 |
"cell_type": "code",
|
123 |
-
"execution_count":
|
124 |
"metadata": {},
|
125 |
"outputs": [
|
126 |
{
|
@@ -129,21 +137,17 @@
|
|
129 |
"text": [
|
130 |
"\n",
|
131 |
"\n",
|
132 |
-
"1.
|
133 |
-
"2.
|
134 |
-
"3.
|
135 |
-
"4.
|
136 |
-
"5.
|
137 |
-
"6.
|
138 |
-
"7.
|
139 |
-
"8.
|
140 |
-
"9.
|
141 |
-
"10.
|
142 |
-
"
|
143 |
-
"12. Chicken Korma\n",
|
144 |
-
"13. Garlic Naan\n",
|
145 |
-
"14. Masala Dosa (Stuffed Crepe)\n",
|
146 |
-
"15. Gulab Jamun (Sweet Fried Dumplings)\n"
|
147 |
]
|
148 |
}
|
149 |
],
|
@@ -164,7 +168,7 @@
|
|
164 |
},
|
165 |
{
|
166 |
"cell_type": "code",
|
167 |
-
"execution_count":
|
168 |
"metadata": {},
|
169 |
"outputs": [],
|
170 |
"source": [
|
@@ -179,7 +183,7 @@
|
|
179 |
"\n",
|
180 |
"prompt_template_items = PromptTemplate(\n",
|
181 |
" input_variables=[\"restaurant_name\"],\n",
|
182 |
-
" template = \"Suggest some menu items for {restaurant_name}.\",\n",
|
183 |
")\n",
|
184 |
"\n",
|
185 |
"food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key=\"menu_items\")\n",
|
@@ -188,18 +192,26 @@
|
|
188 |
},
|
189 |
{
|
190 |
"cell_type": "code",
|
191 |
-
"execution_count":
|
192 |
"metadata": {},
|
193 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
{
|
195 |
"data": {
|
196 |
"text/plain": [
|
197 |
"{'cuisine': 'Singaporean',\n",
|
198 |
-
" 'restaurant_name': '\\n\\n\"Singapore Spice
|
199 |
-
" 'menu_items': '\\n\\
|
200 |
]
|
201 |
},
|
202 |
-
"execution_count":
|
203 |
"metadata": {},
|
204 |
"output_type": "execute_result"
|
205 |
}
|
@@ -213,7 +225,7 @@
|
|
213 |
" output_variables = [\"restaurant_name\", \"menu_items\"]\n",
|
214 |
")\n",
|
215 |
"\n",
|
216 |
-
"chain({\"cuisine\": \"Singaporean\"})"
|
217 |
]
|
218 |
},
|
219 |
{
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
+
"execution_count": 3,
|
16 |
"metadata": {
|
17 |
"notebookRunGroups": {
|
18 |
"groupValue": ""
|
|
|
28 |
},
|
29 |
{
|
30 |
"cell_type": "code",
|
31 |
+
"execution_count": 6,
|
32 |
"metadata": {},
|
33 |
"outputs": [
|
34 |
{
|
|
|
37 |
"text": [
|
38 |
"\n",
|
39 |
"\n",
|
40 |
+
"Golden Dragon Palace \n"
|
41 |
]
|
42 |
}
|
43 |
],
|
44 |
"source": [
|
45 |
+
"from langchain_community.llms import OpenAI\n",
|
46 |
"llm = OpenAI(temperature=0.6)\n",
|
47 |
+
"name = llm.invoke(\"I want to open a restaurant for Chinese food. Suggest a fancy name for this.\")\n",
|
48 |
"print(name)"
|
49 |
]
|
50 |
},
|
51 |
{
|
52 |
"cell_type": "code",
|
53 |
+
"execution_count": 7,
|
54 |
"metadata": {},
|
55 |
"outputs": [
|
56 |
{
|
|
|
59 |
"'I want to open a restaurant for Mexican food. Suggest a fancy name for this.'"
|
60 |
]
|
61 |
},
|
62 |
+
"execution_count": 7,
|
63 |
"metadata": {},
|
64 |
"output_type": "execute_result"
|
65 |
}
|
|
|
77 |
},
|
78 |
{
|
79 |
"cell_type": "code",
|
80 |
+
"execution_count": 8,
|
81 |
"metadata": {},
|
82 |
"outputs": [
|
83 |
+
{
|
84 |
+
"name": "stderr",
|
85 |
+
"output_type": "stream",
|
86 |
+
"text": [
|
87 |
+
"/home/chong-u/mambaforge/envs/codebasics-langchain-crash-course/lib/python3.10/site-packages/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `run` was deprecated in LangChain 0.1.0 and will be removed in 0.2.0. Use invoke instead.\n",
|
88 |
+
" warn_deprecated(\n"
|
89 |
+
]
|
90 |
+
},
|
91 |
{
|
92 |
"data": {
|
93 |
"text/plain": [
|
94 |
+
"'\\n\\n\"La Cantina de Sabores\" (The Flavor Cantina)'"
|
95 |
]
|
96 |
},
|
97 |
+
"execution_count": 8,
|
98 |
"metadata": {},
|
99 |
"output_type": "execute_result"
|
100 |
}
|
|
|
115 |
},
|
116 |
{
|
117 |
"cell_type": "code",
|
118 |
+
"execution_count": 9,
|
119 |
"metadata": {},
|
120 |
"outputs": [],
|
121 |
"source": [
|
|
|
128 |
},
|
129 |
{
|
130 |
"cell_type": "code",
|
131 |
+
"execution_count": 10,
|
132 |
"metadata": {},
|
133 |
"outputs": [
|
134 |
{
|
|
|
137 |
"text": [
|
138 |
"\n",
|
139 |
"\n",
|
140 |
+
"1. Chicken Tikka Masala\n",
|
141 |
+
"2. Vegetable Samosas\n",
|
142 |
+
"3. Lamb Vindaloo\n",
|
143 |
+
"4. Palak Paneer\n",
|
144 |
+
"5. Tandoori Chicken\n",
|
145 |
+
"6. Garlic Naan\n",
|
146 |
+
"7. Chana Masala\n",
|
147 |
+
"8. Aloo Gobi\n",
|
148 |
+
"9. Butter Chicken\n",
|
149 |
+
"10. Mango Lassi \n",
|
150 |
+
"\n"
|
|
|
|
|
|
|
|
|
151 |
]
|
152 |
}
|
153 |
],
|
|
|
168 |
},
|
169 |
{
|
170 |
"cell_type": "code",
|
171 |
+
"execution_count": 11,
|
172 |
"metadata": {},
|
173 |
"outputs": [],
|
174 |
"source": [
|
|
|
183 |
"\n",
|
184 |
"prompt_template_items = PromptTemplate(\n",
|
185 |
" input_variables=[\"restaurant_name\"],\n",
|
186 |
+
" template = \"Suggest some menu items for {restaurant_name}. Return the menu items as a single, comma separated string with no additional preamble.\",\n",
|
187 |
")\n",
|
188 |
"\n",
|
189 |
"food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key=\"menu_items\")\n",
|
|
|
192 |
},
|
193 |
{
|
194 |
"cell_type": "code",
|
195 |
+
"execution_count": 12,
|
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\\n\"Singapore Spice Emporium\"',\n",
|
211 |
+
" 'menu_items': '\\n\\n\"Nasi Lemak, Hainanese Chicken Rice, Laksa, Chili Crab, Char Kway Teow, Satay, Rojak, Bak Kut Teh, Curry Puffs, Teh Tarik\"'}"
|
212 |
]
|
213 |
},
|
214 |
+
"execution_count": 12,
|
215 |
"metadata": {},
|
216 |
"output_type": "execute_result"
|
217 |
}
|
|
|
225 |
" output_variables = [\"restaurant_name\", \"menu_items\"]\n",
|
226 |
")\n",
|
227 |
"\n",
|
228 |
+
"chain.invoke({\"cuisine\": \"Singaporean\"})"
|
229 |
]
|
230 |
},
|
231 |
{
|