Skip to content

Commit f9e9025

Browse files
committed
Code Update
1 parent f36889c commit f9e9025

File tree

3 files changed

+85
-107
lines changed

3 files changed

+85
-107
lines changed

Module 9 - GenAI (LLMs and Prompt Engineering)/6. Building Apps Powered by GenAI using LangChain/1. Introduction to LangChain/1. Introduction/introduction_to_langchain.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"name": "stdout",
110110
"output_type": "stream",
111111
"text": [
112-
"content='Feature engineering is the process of selecting, extracting, and transforming features (variables) from raw data to improve the performance of machine learning models. It involves creating new features, selecting the most relevant ones, and transforming existing features to make them more informative for the model. Feature engineering is a critical step in the machine learning pipeline, as the quality of the features often has a significant impact on the performance of the model. By carefully engineering features, data scientists can improve the accuracy, efficiency, and interpretability of their machine learning models.' response_metadata={'token_usage': {'completion_tokens': 106, 'prompt_tokens': 12, 'total_tokens': 118}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'stop', 'logprobs': None}\n"
112+
"content=\"Feature engineering is the process of selecting, extracting, and transforming raw data into features that are suitable for use in machine learning models. It involves identifying and creating relevant features from the input data to improve the performance and accuracy of the model. Feature engineering plays a crucial role in machine learning, as the quality of the features used can have a significant impact on the model's predictive power and overall performance.\" response_metadata={'token_usage': {'completion_tokens': 79, 'prompt_tokens': 12, 'total_tokens': 91}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_d9767fc5b9', 'finish_reason': 'stop', 'logprobs': None}\n"
113113
]
114114
}
115115
],
@@ -194,7 +194,7 @@
194194
{
195195
"data": {
196196
"text/plain": [
197-
"AIMessage(content='NLP stands for Natural Language Processing. It is a field of artificial intelligence that focuses on the interaction between computers and humans using natural language. NLP involves the development of algorithms and models that allow computers to understand, interpret, and generate human language. Applications of NLP include sentiment analysis, language translation, chatbots, and text summarization.', response_metadata={'token_usage': {'completion_tokens': 69, 'prompt_tokens': 32, 'total_tokens': 101}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'stop', 'logprobs': None})"
197+
"AIMessage(content='NLP stands for Natural Language Processing. It is a branch of artificial intelligence that focuses on the interaction between computers and humans using natural language. NLP techniques enable computers to understand, interpret, and generate human language in a way that is valuable. NLP is used in various applications such as sentiment analysis, language translation, speech recognition, and text classification.', response_metadata={'token_usage': {'completion_tokens': 71, 'prompt_tokens': 32, 'total_tokens': 103}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_d9767fc5b9', 'finish_reason': 'stop', 'logprobs': None})"
198198
]
199199
},
200200
"execution_count": 6,
@@ -249,7 +249,7 @@
249249
{
250250
"data": {
251251
"text/plain": [
252-
"'Deep learning is a subfield of machine learning that focuses on training artificial neural networks to learn from data. These neural networks are composed of multiple layers of interconnected nodes that enable the model to learn complex patterns in the data. Deep learning algorithms have been shown to be highly effective in tasks such as image and speech recognition, natural language processing, and many other domains where large amounts of data are available for training. The term \"deep\" refers to the multiple layers in the neural network, allowing the model to learn hierarchical representations of the data.'"
252+
"'Deep learning is a subfield of machine learning that focuses on training and using artificial neural networks to model and solve complex problems. These neural networks are composed of multiple layers of interconnected nodes (neurons) that work together to process data and extract meaningful patterns or representations. Deep learning algorithms are capable of automatically learning hierarchical representations of data, which allows them to effectively handle tasks such as image and speech recognition, natural language processing, and more. Deep learning has been highly successful in various applications, including computer vision, speech recognition, and autonomous driving.'"
253253
]
254254
},
255255
"execution_count": 8,

Module 9 - GenAI (LLMs and Prompt Engineering)/6. Building Apps Powered by GenAI using LangChain/1. Introduction to LangChain/4. Output Parsing/output_parsing.ipynb

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@
2424
"etc..."
2525
]
2626
},
27-
{
28-
"cell_type": "code",
29-
"execution_count": 1,
30-
"id": "653b4ff2-bde5-408b-afd6-14fd804399d0",
31-
"metadata": {},
32-
"outputs": [],
33-
"source": [
34-
"# Setup API Key\n",
35-
"\n",
36-
"f = open('keys/.openai_api_key.txt')\n",
37-
"\n",
38-
"OPENAI_API_KEY = f.read()"
39-
]
40-
},
4127
{
4228
"cell_type": "markdown",
4329
"id": "5567d306-c0bd-4c14-ab46-8710bcf1d132",
@@ -50,19 +36,19 @@
5036
},
5137
{
5238
"cell_type": "code",
53-
"execution_count": 2,
39+
"execution_count": 1,
5440
"id": "fb66a263-96cc-42d2-9ccb-eecda7950b5d",
5541
"metadata": {},
5642
"outputs": [],
5743
"source": [
58-
"from langchain.output_parsers import CommaSeparatedListOutputParser\n",
44+
"from langchain_core.output_parsers import CommaSeparatedListOutputParser\n",
5945
"\n",
6046
"output_parser = CommaSeparatedListOutputParser()"
6147
]
6248
},
6349
{
6450
"cell_type": "code",
65-
"execution_count": 3,
51+
"execution_count": 2,
6652
"id": "bb683e6d-7d19-4bcc-92c1-a7993686d999",
6753
"metadata": {},
6854
"outputs": [
@@ -72,7 +58,7 @@
7258
"'Your response should be a list of comma separated values, eg: `foo, bar, baz`'"
7359
]
7460
},
75-
"execution_count": 3,
61+
"execution_count": 2,
7662
"metadata": {},
7763
"output_type": "execute_result"
7864
}
@@ -85,7 +71,7 @@
8571
},
8672
{
8773
"cell_type": "code",
88-
"execution_count": 4,
74+
"execution_count": 3,
8975
"id": "d19eb38e-6fc3-48c1-bd6e-c33c3790fbf7",
9076
"metadata": {},
9177
"outputs": [
@@ -95,7 +81,7 @@
9581
"['Python', 'DA', 'SQL', 'ML', 'DL']"
9682
]
9783
},
98-
"execution_count": 4,
84+
"execution_count": 3,
9985
"metadata": {},
10086
"output_type": "execute_result"
10187
}
@@ -109,22 +95,50 @@
10995
},
11096
{
11197
"cell_type": "code",
112-
"execution_count": 5,
98+
"execution_count": 17,
11399
"id": "67f5242f-1517-4b77-bb01-2507894a6fbe",
114100
"metadata": {},
115-
"outputs": [],
101+
"outputs": [
102+
{
103+
"data": {
104+
"text/plain": [
105+
"[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template='You are a helpful AI Chef.')),\n",
106+
" HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['dish_name', 'output_format_instructions'], template='Give me the ingredients for cooking {dish_name}. {output_format_instructions}'))]"
107+
]
108+
},
109+
"execution_count": 17,
110+
"metadata": {},
111+
"output_type": "execute_result"
112+
}
113+
],
116114
"source": [
117115
"from langchain_core.prompts import ChatPromptTemplate\n",
118116
"\n",
119117
"prompt_template = ChatPromptTemplate.from_messages([\n",
120118
" (\"system\", \"You are a helpful AI Chef.\"),\n",
121119
" (\"human\", \"Give me the ingredients for cooking {dish_name}. {output_format_instructions}\"),\n",
122-
"])"
120+
"])\n",
121+
"\n",
122+
"prompt_template.messages"
123+
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": 18,
128+
"id": "653b4ff2-bde5-408b-afd6-14fd804399d0",
129+
"metadata": {},
130+
"outputs": [],
131+
"source": [
132+
"# Setup API Key\n",
133+
"\n",
134+
"f = open('keys/.openai_api_key.txt')\n",
135+
"\n",
136+
"OPENAI_API_KEY = f.read()"
123137
]
124138
},
125139
{
126140
"cell_type": "code",
127-
"execution_count": 6,
141+
"execution_count": 19,
128142
"id": "b734ae2c-bb0c-40a7-9e67-586eede34f7a",
129143
"metadata": {},
130144
"outputs": [],
@@ -137,7 +151,7 @@
137151
},
138152
{
139153
"cell_type": "code",
140-
"execution_count": 7,
154+
"execution_count": 20,
141155
"id": "d5a6a423-ae97-4536-a898-ae9322478d22",
142156
"metadata": {},
143157
"outputs": [],
@@ -147,7 +161,7 @@
147161
},
148162
{
149163
"cell_type": "code",
150-
"execution_count": 8,
164+
"execution_count": 21,
151165
"id": "f7fe8e3d-f2b8-4008-ac02-bc00f6bff39d",
152166
"metadata": {},
153167
"outputs": [
@@ -156,28 +170,24 @@
156170
"text/plain": [
157171
"['paneer',\n",
158172
" 'basmati rice',\n",
173+
" 'yogurt',\n",
159174
" 'onions',\n",
160175
" 'tomatoes',\n",
161-
" 'yogurt',\n",
162-
" 'ginger-garlic paste',\n",
176+
" 'ginger',\n",
177+
" 'garlic',\n",
163178
" 'green chilies',\n",
164-
" 'cilantro',\n",
165-
" 'mint leaves',\n",
166-
" 'garam masala',\n",
167-
" 'turmeric powder',\n",
168-
" 'red chili powder',\n",
169-
" 'cumin seeds',\n",
170-
" 'cinnamon',\n",
171-
" 'cardamom',\n",
172-
" 'cloves',\n",
173-
" 'bay leaves',\n",
174-
" 'saffron strands',\n",
179+
" 'biryani masala',\n",
175180
" 'ghee',\n",
181+
" 'mint leaves',\n",
182+
" 'coriander leaves',\n",
183+
" 'saffron',\n",
184+
" 'milk',\n",
185+
" 'salt',\n",
176186
" 'oil',\n",
177-
" 'salt']"
187+
" 'spices']"
178188
]
179189
},
180-
"execution_count": 8,
190+
"execution_count": 21,
181191
"metadata": {},
182192
"output_type": "execute_result"
183193
}
@@ -200,7 +210,7 @@
200210
},
201211
{
202212
"cell_type": "code",
203-
"execution_count": 9,
213+
"execution_count": 22,
204214
"id": "072bd02b-c06d-4d05-97b2-f62862e8dcc2",
205215
"metadata": {},
206216
"outputs": [],
@@ -212,17 +222,17 @@
212222
},
213223
{
214224
"cell_type": "code",
215-
"execution_count": 10,
225+
"execution_count": 23,
216226
"id": "00755d45-e38a-4c09-8412-c12eb4540175",
217227
"metadata": {},
218228
"outputs": [
219229
{
220230
"data": {
221231
"text/plain": [
222-
"\"Write a datetime string that matches the following pattern: '%Y-%m-%dT%H:%M:%S.%fZ'.\\n\\nExamples: 1954-03-17T22:08:55.730057Z, 0137-07-03T04:19:03.372185Z, 1525-07-14T06:53:07.534119Z\\n\\nReturn ONLY this string, no other words!\""
232+
"\"Write a datetime string that matches the following pattern: '%Y-%m-%dT%H:%M:%S.%fZ'.\\n\\nExamples: 0789-09-27T20:15:58.070587Z, 0146-06-12T19:06:59.697461Z, 1178-01-28T21:50:31.033531Z\\n\\nReturn ONLY this string, no other words!\""
223233
]
224234
},
225-
"execution_count": 10,
235+
"execution_count": 23,
226236
"metadata": {},
227237
"output_type": "execute_result"
228238
}
@@ -235,7 +245,7 @@
235245
},
236246
{
237247
"cell_type": "code",
238-
"execution_count": 11,
248+
"execution_count": 24,
239249
"id": "3bd3acd4-2cda-4776-a90c-968e87133d9f",
240250
"metadata": {},
241251
"outputs": [],
@@ -253,7 +263,7 @@
253263
},
254264
{
255265
"cell_type": "code",
256-
"execution_count": 12,
266+
"execution_count": 25,
257267
"id": "c18efe6f-b8d4-4839-b8d0-8cfc01fc3587",
258268
"metadata": {},
259269
"outputs": [],
@@ -266,7 +276,7 @@
266276
},
267277
{
268278
"cell_type": "code",
269-
"execution_count": 13,
279+
"execution_count": 26,
270280
"id": "69182c25-2ba5-4ad4-9287-41b31011880f",
271281
"metadata": {},
272282
"outputs": [
@@ -276,7 +286,7 @@
276286
"datetime.datetime(1947, 8, 15, 0, 0)"
277287
]
278288
},
279-
"execution_count": 13,
289+
"execution_count": 26,
280290
"metadata": {},
281291
"output_type": "execute_result"
282292
}

0 commit comments

Comments
 (0)