Skip to content

Commit c1b6ce0

Browse files
ficed devcontainer and ch04 issues
1 parent 6c23489 commit c1b6ce0

File tree

3 files changed

+243
-21
lines changed

3 files changed

+243
-21
lines changed

Diff for: .devcontainer/post-create.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/bin/bash
22

33
# Install OpenAI and Dotenv for Python
44
# TODO: Check why this can't be done in requirements.txt

Diff for: .env.copy

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
OPENAI_API_KEY=
1+
AZURE_OPENAI_ENDPOINT=<add your endpoint here>
2+
AZURE_OPENAI_DEPLOYMENT=<add your deployment here>
3+
AZURE_OPENAI_KEY=<add your key here>

Diff for: 04-prompt-engineering-fundamentals/1-introduction.ipynb

+239-19
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,161 @@
2626
},
2727
{
2828
"cell_type": "code",
29-
"execution_count": null,
29+
"execution_count": 1,
3030
"metadata": {},
31-
"outputs": [],
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"[198, 41, 20089, 374, 279, 18172, 11841, 505, 279, 8219, 323, 279, 7928, 304, 279, 25450, 744, 13, 1102, 374, 264, 6962, 14880, 449, 264, 3148, 832, 7716, 52949, 339, 430, 315, 279, 8219, 11, 719, 1403, 9976, 7561, 34902, 3115, 430, 315, 682, 279, 1023, 33975, 304, 279, 25450, 744, 11093, 13, 50789, 374, 832, 315, 279, 72021, 6302, 9621, 311, 279, 19557, 8071, 304, 279, 3814, 13180, 11, 323, 706, 1027, 3967, 311, 14154, 86569, 2533, 1603, 12715, 3925, 13, 1102, 374, 7086, 1306, 279, 13041, 10087, 50789, 8032, 777, 60, 3277, 19894, 505, 9420, 11, 50789, 649, 387, 10107, 3403, 369, 1202, 27000, 3177, 311, 6445, 9621, 35612, 17706, 508, 60, 323, 374, 389, 5578, 279, 4948, 1481, 1315, 478, 5933, 1665, 304, 279, 3814, 13180, 1306, 279, 17781, 323, 50076, 627]\n"
37+
]
38+
},
39+
{
40+
"data": {
41+
"text/plain": [
42+
"[b'\\n',\n",
43+
" b'J',\n",
44+
" b'upiter',\n",
45+
" b' is',\n",
46+
" b' the',\n",
47+
" b' fifth',\n",
48+
" b' planet',\n",
49+
" b' from',\n",
50+
" b' the',\n",
51+
" b' Sun',\n",
52+
" b' and',\n",
53+
" b' the',\n",
54+
" b' largest',\n",
55+
" b' in',\n",
56+
" b' the',\n",
57+
" b' Solar',\n",
58+
" b' System',\n",
59+
" b'.',\n",
60+
" b' It',\n",
61+
" b' is',\n",
62+
" b' a',\n",
63+
" b' gas',\n",
64+
" b' giant',\n",
65+
" b' with',\n",
66+
" b' a',\n",
67+
" b' mass',\n",
68+
" b' one',\n",
69+
" b'-th',\n",
70+
" b'ousand',\n",
71+
" b'th',\n",
72+
" b' that',\n",
73+
" b' of',\n",
74+
" b' the',\n",
75+
" b' Sun',\n",
76+
" b',',\n",
77+
" b' but',\n",
78+
" b' two',\n",
79+
" b'-and',\n",
80+
" b'-a',\n",
81+
" b'-half',\n",
82+
" b' times',\n",
83+
" b' that',\n",
84+
" b' of',\n",
85+
" b' all',\n",
86+
" b' the',\n",
87+
" b' other',\n",
88+
" b' planets',\n",
89+
" b' in',\n",
90+
" b' the',\n",
91+
" b' Solar',\n",
92+
" b' System',\n",
93+
" b' combined',\n",
94+
" b'.',\n",
95+
" b' Jupiter',\n",
96+
" b' is',\n",
97+
" b' one',\n",
98+
" b' of',\n",
99+
" b' the',\n",
100+
" b' brightest',\n",
101+
" b' objects',\n",
102+
" b' visible',\n",
103+
" b' to',\n",
104+
" b' the',\n",
105+
" b' naked',\n",
106+
" b' eye',\n",
107+
" b' in',\n",
108+
" b' the',\n",
109+
" b' night',\n",
110+
" b' sky',\n",
111+
" b',',\n",
112+
" b' and',\n",
113+
" b' has',\n",
114+
" b' been',\n",
115+
" b' known',\n",
116+
" b' to',\n",
117+
" b' ancient',\n",
118+
" b' civilizations',\n",
119+
" b' since',\n",
120+
" b' before',\n",
121+
" b' recorded',\n",
122+
" b' history',\n",
123+
" b'.',\n",
124+
" b' It',\n",
125+
" b' is',\n",
126+
" b' named',\n",
127+
" b' after',\n",
128+
" b' the',\n",
129+
" b' Roman',\n",
130+
" b' god',\n",
131+
" b' Jupiter',\n",
132+
" b'.[',\n",
133+
" b'19',\n",
134+
" b']',\n",
135+
" b' When',\n",
136+
" b' viewed',\n",
137+
" b' from',\n",
138+
" b' Earth',\n",
139+
" b',',\n",
140+
" b' Jupiter',\n",
141+
" b' can',\n",
142+
" b' be',\n",
143+
" b' bright',\n",
144+
" b' enough',\n",
145+
" b' for',\n",
146+
" b' its',\n",
147+
" b' reflected',\n",
148+
" b' light',\n",
149+
" b' to',\n",
150+
" b' cast',\n",
151+
" b' visible',\n",
152+
" b' shadows',\n",
153+
" b',[',\n",
154+
" b'20',\n",
155+
" b']',\n",
156+
" b' and',\n",
157+
" b' is',\n",
158+
" b' on',\n",
159+
" b' average',\n",
160+
" b' the',\n",
161+
" b' third',\n",
162+
" b'-b',\n",
163+
" b'right',\n",
164+
" b'est',\n",
165+
" b' natural',\n",
166+
" b' object',\n",
167+
" b' in',\n",
168+
" b' the',\n",
169+
" b' night',\n",
170+
" b' sky',\n",
171+
" b' after',\n",
172+
" b' the',\n",
173+
" b' Moon',\n",
174+
" b' and',\n",
175+
" b' Venus',\n",
176+
" b'.\\n']"
177+
]
178+
},
179+
"execution_count": 1,
180+
"metadata": {},
181+
"output_type": "execute_result"
182+
}
183+
],
32184
"source": [
33185
"# EXERCISE:\n",
34186
"# 1. Run the exercise as is first\n",
@@ -72,27 +224,39 @@
72224
},
73225
{
74226
"cell_type": "code",
75-
"execution_count": null,
227+
"execution_count": 2,
76228
"metadata": {},
77-
"outputs": [],
229+
"outputs": [
230+
{
231+
"name": "stdout",
232+
"output_type": "stream",
233+
"text": [
234+
"By the dawn's early light,\n"
235+
]
236+
}
237+
],
78238
"source": [
79239
"# The OpenAI SDK was updated on Nov 8, 2023 with new guidance for migration\n",
80240
"# See: https://github.com/openai/openai-python/discussions/742\n",
81241
"\n",
82242
"## Updated\n",
83243
"import os\n",
84244
"import openai\n",
85-
"from openai import OpenAI\n",
245+
"from openai import AzureOpenAI\n",
86246
"\n",
87-
"client = OpenAI(\n",
88-
" api_key=os.environ['OPENAI_API_KEY'], # this is also the default, it can be omitted\n",
89-
")\n",
247+
"client = AzureOpenAI(\n",
248+
" api_key=os.environ['AZURE_OPENAI_KEY'], # this is also the default, it can be omitted\n",
249+
" api_version = \"2023-05-15\",\n",
250+
" azure_endpoint = os.environ['AZURE_OPENAI_ENDPOINT']\n",
251+
" )\n",
252+
"\n",
253+
"deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
90254
"\n",
91255
"## Updated\n",
92-
"def get_completion(prompt, model=\"gpt-3.5-turbo\"):\n",
256+
"def get_completion(prompt):\n",
93257
" messages = [{\"role\": \"user\", \"content\": prompt}]\n",
94-
" response = openai.chat.completions.create(\n",
95-
" model=model,\n",
258+
" response = client.chat.completions.create( \n",
259+
" model=deployment, \n",
96260
" messages=messages,\n",
97261
" temperature=0, # this is the degree of randomness of the model's output\n",
98262
" max_tokens=1024\n",
@@ -126,9 +290,49 @@
126290
},
127291
{
128292
"cell_type": "code",
129-
"execution_count": null,
293+
"execution_count": 3,
130294
"metadata": {},
131-
"outputs": [],
295+
"outputs": [
296+
{
297+
"name": "stdout",
298+
"output_type": "stream",
299+
"text": [
300+
"Title: The Martian War of 2076\n",
301+
"\n",
302+
"Grade Level: High School\n",
303+
"\n",
304+
"Objective: Students will be able to understand the causes, events, and consequences of the Martian War of 2076.\n",
305+
"\n",
306+
"Materials:\n",
307+
"- Textbook or online resources on the Martian War of 2076\n",
308+
"- Maps of Mars and Earth\n",
309+
"- Images and videos of Martian colonies and military equipment\n",
310+
"- Writing materials\n",
311+
"\n",
312+
"Procedure:\n",
313+
"\n",
314+
"Introduction (10 minutes)\n",
315+
"- Begin by asking students if they have heard of the Martian War of 2076 and what they know about it.\n",
316+
"- Explain that the Martian War of 2076 was a conflict between Earth and Mars that lasted for several years and had significant consequences for both planets.\n",
317+
"\n",
318+
"Causes of the War (20 minutes)\n",
319+
"- Provide students with background information on the causes of the Martian War of 2076, including the political, economic, and environmental factors that led to the conflict.\n",
320+
"- Ask students to discuss in small groups the causes of the war and how they might have been prevented.\n",
321+
"\n",
322+
"Events of the War (30 minutes)\n",
323+
"- Using maps and images, explain the major events of the Martian War of 2076, including the battles, strategies, and technologies used by both sides.\n",
324+
"- Ask students to create a timeline of the war and identify the key turning points.\n",
325+
"\n",
326+
"Consequences of the War (20 minutes)\n",
327+
"- Discuss the consequences of the Martian War of 2076, including the impact on the Martian colonies, the Earth's economy and environment, and the political relationships between the two planets.\n",
328+
"- Ask students to write a short essay on the consequences of the war and how they might have been avoided.\n",
329+
"\n",
330+
"Conclusion (10 minutes)\n",
331+
"- Summarize the key points of the lesson and ask students to reflect on what they have learned.\n",
332+
"- Encourage students to think about the lessons that can be learned from the Martian War of 2076 and how they might apply to current global issues.\n"
333+
]
334+
}
335+
],
132336
"source": [
133337
"\n",
134338
"## Set the text for simple prompt or primary content\n",
@@ -159,9 +363,17 @@
159363
},
160364
{
161365
"cell_type": "code",
162-
"execution_count": null,
366+
"execution_count": 4,
163367
"metadata": {},
164-
"outputs": [],
368+
"outputs": [
369+
{
370+
"name": "stdout",
371+
"output_type": "stream",
372+
"text": [
373+
"Jupiter is a really big planet that is fifth from the Sun. It is much bigger than all the other planets combined! People have known about Jupiter for a very long time because it is very bright in the night sky. It is named after a Roman god. When we look at Jupiter from Earth, it can be so bright that it makes shadows. It is usually the third-brightest thing we can see at night after the Moon and Venus.\n"
374+
]
375+
}
376+
],
165377
"source": [
166378
"# Test Example\n",
167379
"# https://platform.openai.com/playground/p/default-summarize\n",
@@ -206,12 +418,20 @@
206418
},
207419
{
208420
"cell_type": "code",
209-
"execution_count": null,
421+
"execution_count": 5,
210422
"metadata": {},
211-
"outputs": [],
423+
"outputs": [
424+
{
425+
"name": "stdout",
426+
"output_type": "stream",
427+
"text": [
428+
"Why don't you take a wild guess? It was played in the only place that could hold such a prestigious event in the middle of a global pandemic... a neutral site: Globe Life Field in Arlington, Texas.\n"
429+
]
430+
}
431+
],
212432
"source": [
213-
"response = openai.chat.completions.create(\n",
214-
" model=\"gpt-3.5-turbo\",\n",
433+
"response = client.chat.completions.create(\n",
434+
" model=deployment,\n",
215435
" messages=[\n",
216436
" {\"role\": \"system\", \"content\": \"You are a sarcastic assistant.\"},\n",
217437
" {\"role\": \"user\", \"content\": \"Who won the world series in 2020?\"},\n",

0 commit comments

Comments
 (0)