Chong-U Lim commited on
Commit
f19aca2
·
1 Parent(s): e2a35fb

Update notebook

Browse files
Files changed (1) hide show
  1. notebook.ipynb +46 -34
notebook.ipynb CHANGED
@@ -12,7 +12,7 @@
12
  },
13
  {
14
  "cell_type": "code",
15
- "execution_count": 7,
16
  "metadata": {
17
  "notebookRunGroups": {
18
  "groupValue": ""
@@ -28,7 +28,7 @@
28
  },
29
  {
30
  "cell_type": "code",
31
- "execution_count": 9,
32
  "metadata": {},
33
  "outputs": [
34
  {
@@ -37,20 +37,20 @@
37
  "text": [
38
  "\n",
39
  "\n",
40
- "\"Imperial Dragon Palace\"\n"
41
  ]
42
  }
43
  ],
44
  "source": [
45
- "from langchain.llms import OpenAI\n",
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": 10,
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": 10,
63
  "metadata": {},
64
  "output_type": "execute_result"
65
  }
@@ -77,16 +77,24 @@
77
  },
78
  {
79
  "cell_type": "code",
80
- "execution_count": 15,
81
  "metadata": {},
82
  "outputs": [
 
 
 
 
 
 
 
 
83
  {
84
  "data": {
85
  "text/plain": [
86
- "'\\n\\n\"La Cantina de Oro\"'"
87
  ]
88
  },
89
- "execution_count": 15,
90
  "metadata": {},
91
  "output_type": "execute_result"
92
  }
@@ -107,7 +115,7 @@
107
  },
108
  {
109
  "cell_type": "code",
110
- "execution_count": 19,
111
  "metadata": {},
112
  "outputs": [],
113
  "source": [
@@ -120,7 +128,7 @@
120
  },
121
  {
122
  "cell_type": "code",
123
- "execution_count": 20,
124
  "metadata": {},
125
  "outputs": [
126
  {
@@ -129,21 +137,17 @@
129
  "text": [
130
  "\n",
131
  "\n",
132
- "1. Spicy Chicken Curry\n",
133
- "2. Lamb Vindaloo\n",
134
- "3. Vegetable Samosas\n",
135
- "4. Tandoori Shrimp\n",
136
- "5. Naan Bread\n",
137
- "6. Chicken Tikka Masala\n",
138
- "7. Aloo Gobi (Potato and Cauliflower Curry)\n",
139
- "8. Palak Paneer (Spinach and Cheese Curry)\n",
140
- "9. Mango Lassi\n",
141
- "10. Biryani Rice\n",
142
- "11. Chana Masala (Chickpea Curry)\n",
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": 24,
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": 25,
192
  "metadata": {},
193
  "outputs": [
 
 
 
 
 
 
 
 
194
  {
195
  "data": {
196
  "text/plain": [
197
  "{'cuisine': 'Singaporean',\n",
198
- " 'restaurant_name': '\\n\\n\"Singapore Spice House\"',\n",
199
- " 'menu_items': '\\n\\n1. Singaporean Chili Crab\\n2. Hainanese Chicken Rice\\n3. Laksa Soup\\n4. Char Kway Teow (Stir-fried noodles with shrimp, egg, and sausage)\\n5. Satay Skewers (grilled marinated meat on skewers)\\n6. Nasi Lemak (coconut rice dish with fried chicken, fried anchovies, peanuts, and sambal chili sauce)\\n7. Roti Prata (Indian-style flatbread served with curry)\\n8. Bak Kut Teh (pork rib soup with herbs and spices)\\n9. Murtabak (stuffed pancake with chicken or mutton)\\n10. Singaporean-style Fried Rice\\n11. Beef Rendang (spicy braised beef in coconut milk)\\n12. Chilli Prawns\\n13. Gado Gado (Indonesian salad with peanut sauce)\\n14. Sambal Stingray (grilled stingray with spicy sambal sauce)\\n15. Biryani Rice (fragrant rice dish with spices and choice of meat)'}"
200
  ]
201
  },
202
- "execution_count": 25,
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
  {