Skip to content

Commit 2fec093

Browse files
authored
Add files via upload
1 parent 22fad9d commit 2fec093

1 file changed

Lines changed: 352 additions & 0 deletions

File tree

Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "e8ce07da-8653-4c93-baa5-e333f7cb824e",
6+
"metadata": {},
7+
"source": [
8+
"# OpenAI o1 & o1-mini demo"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "5af8ec97-604b-4d7d-9614-64b9439aec0f",
14+
"metadata": {},
15+
"source": [
16+
"### Install required libraries"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 62,
22+
"id": "c25d8f14-a8a3-4fa5-9f14-c4ab76b1aacd",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"!pip install openai -q"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 63,
32+
"id": "ff82f97b-a670-402c-88d2-5c9bca654da5",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": [
36+
"!pip install --upgrade openai -q"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"id": "4a14db2a-724a-44a6-8dd2-cd134be0c908",
42+
"metadata": {},
43+
"source": [
44+
"### Load Environment variables"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": 66,
50+
"id": "8867a51b-4bf3-4a5d-bce8-de49409f822c",
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/plain": [
56+
"True"
57+
]
58+
},
59+
"execution_count": 66,
60+
"metadata": {},
61+
"output_type": "execute_result"
62+
}
63+
],
64+
"source": [
65+
"from openai import OpenAI\n",
66+
"from dotenv import load_dotenv, find_dotenv\n",
67+
"\n",
68+
"load_dotenv(find_dotenv(), override=True)"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"id": "af9531dc-7377-41a3-8372-8e560395ba70",
74+
"metadata": {},
75+
"source": [
76+
"### Define the Chatbot Application"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 78,
82+
"id": "9b4a93f4-2c67-4eb2-9f15-fa20d40b5522",
83+
"metadata": {},
84+
"outputs": [],
85+
"source": [
86+
"def chat_with_o1_mini(prompt):\n",
87+
" client = OpenAI()\n",
88+
" response = client.chat.completions.create(\n",
89+
" model=\"o1-mini\",\n",
90+
" messages=[{\"role\": \"user\", \"content\": prompt}]\n",
91+
" )\n",
92+
" return response.choices[0].message.content"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"id": "6eef7557-9a4d-4b46-96f6-2609f878ab65",
98+
"metadata": {},
99+
"source": [
100+
"### Test the Chatbot"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": 81,
106+
"id": "c6763990-f2f2-424d-ab2f-497816ece701",
107+
"metadata": {},
108+
"outputs": [
109+
{
110+
"name": "stdout",
111+
"output_type": "stream",
112+
"text": [
113+
"AI Response: Certainly! Let's find the **indefinite integral** (also known as the antiderivative) of \\( x^2 \\).\n",
114+
"\n",
115+
"### Problem:\n",
116+
"\\[\n",
117+
"\\int x^2 \\, dx\n",
118+
"\\]\n",
119+
"\n",
120+
"### Solution:\n",
121+
"To compute the integral of \\( x^2 \\), we can use the **power rule for integration**. The power rule states:\n",
122+
"\n",
123+
"\\[\n",
124+
"\\int x^n \\, dx = \\frac{x^{n+1}}{n+1} + C \\quad \\text{(where \\( n \\neq -1 \\))}\n",
125+
"\\]\n",
126+
"\n",
127+
"Here, \\( n = 2 \\). Applying the power rule:\n",
128+
"\n",
129+
"\\[\n",
130+
"\\int x^2 \\, dx = \\frac{x^{2+1}}{2+1} + C = \\frac{x^3}{3} + C\n",
131+
"\\]\n",
132+
"\n",
133+
"### Final Answer:\n",
134+
"\\[\n",
135+
"\\int x^2 \\, dx = \\frac{1}{3}x^3 + C\n",
136+
"\\]\n",
137+
"\n",
138+
"Where \\( C \\) is the **constant of integration**, representing an infinite number of possible antiderivatives differing by a constant.\n",
139+
"\n",
140+
"---\n",
141+
"\n",
142+
"**Example:**\n",
143+
"\n",
144+
"If you want to evaluate the integral from \\( x = 0 \\) to \\( x = 2 \\):\n",
145+
"\n",
146+
"\\[\n",
147+
"\\int_{0}^{2} x^2 \\, dx = \\left[ \\frac{x^3}{3} \\right]_0^2 = \\frac{2^3}{3} - \\frac{0^3}{3} = \\frac{8}{3} - 0 = \\frac{8}{3}\n",
148+
"\\]\n",
149+
"\n",
150+
"So, the definite integral of \\( x^2 \\) from 0 to 2 is \\( \\frac{8}{3} \\).\n",
151+
"\n",
152+
"If you have any more questions or need further clarification, feel free to ask!\n"
153+
]
154+
}
155+
],
156+
"source": [
157+
"prompt = \"Can you solve this math problem for me? What is the integral of x^2?\"\n",
158+
"response = chat_with_o1_mini(prompt)\n",
159+
"print(\"AI Response:\", response)"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": null,
165+
"id": "4dc4c608-f1a8-403b-a55d-171ad37d26a0",
166+
"metadata": {},
167+
"outputs": [],
168+
"source": []
169+
},
170+
{
171+
"cell_type": "code",
172+
"execution_count": null,
173+
"id": "6f2bda36-5464-4baa-9323-8bfa9dd357c6",
174+
"metadata": {},
175+
"outputs": [],
176+
"source": []
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "868a5b6d-22e1-4a56-8e9a-0228f9bbecf8",
182+
"metadata": {},
183+
"outputs": [],
184+
"source": []
185+
},
186+
{
187+
"cell_type": "code",
188+
"execution_count": null,
189+
"id": "9faf1ca7-917a-4e71-b56f-fdbdd3e6254b",
190+
"metadata": {},
191+
"outputs": [],
192+
"source": []
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": null,
197+
"id": "01518516-f371-4ebd-b0fb-9dc5915d53c8",
198+
"metadata": {},
199+
"outputs": [],
200+
"source": []
201+
},
202+
{
203+
"cell_type": "code",
204+
"execution_count": null,
205+
"id": "3c3e79c3-e0c8-4094-a74b-d2344b523dcc",
206+
"metadata": {},
207+
"outputs": [],
208+
"source": []
209+
},
210+
{
211+
"cell_type": "code",
212+
"execution_count": null,
213+
"id": "dba9df14-f022-4c7e-8096-7a44b0db9fe9",
214+
"metadata": {},
215+
"outputs": [],
216+
"source": []
217+
},
218+
{
219+
"cell_type": "code",
220+
"execution_count": null,
221+
"id": "fbe308ae-0341-4634-8e03-fc08c028aa12",
222+
"metadata": {},
223+
"outputs": [],
224+
"source": []
225+
},
226+
{
227+
"cell_type": "code",
228+
"execution_count": null,
229+
"id": "299b20e1-494d-4122-b93c-37dc8e710113",
230+
"metadata": {},
231+
"outputs": [],
232+
"source": []
233+
},
234+
{
235+
"cell_type": "code",
236+
"execution_count": null,
237+
"id": "fd5deb2b-daf1-4cc8-98f5-ceb90e6ab33e",
238+
"metadata": {},
239+
"outputs": [],
240+
"source": []
241+
},
242+
{
243+
"cell_type": "code",
244+
"execution_count": null,
245+
"id": "618d43d1-1cf8-41f3-915e-ac491da7655e",
246+
"metadata": {},
247+
"outputs": [],
248+
"source": []
249+
},
250+
{
251+
"cell_type": "code",
252+
"execution_count": null,
253+
"id": "18956ec0-ebac-45e6-83d8-4f11bd559fdc",
254+
"metadata": {},
255+
"outputs": [],
256+
"source": []
257+
},
258+
{
259+
"cell_type": "code",
260+
"execution_count": null,
261+
"id": "d0787861-409c-43b0-8a19-4bc8ba814c4e",
262+
"metadata": {},
263+
"outputs": [],
264+
"source": []
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": null,
269+
"id": "cdc9df23-b5c4-4224-8e44-8528123361ae",
270+
"metadata": {},
271+
"outputs": [],
272+
"source": []
273+
},
274+
{
275+
"cell_type": "code",
276+
"execution_count": null,
277+
"id": "66172388-cb4f-4ce9-bb08-5037b4893033",
278+
"metadata": {},
279+
"outputs": [],
280+
"source": []
281+
},
282+
{
283+
"cell_type": "code",
284+
"execution_count": null,
285+
"id": "db6a6aa3-0c31-4a2e-a1c0-a5a760a74c37",
286+
"metadata": {},
287+
"outputs": [],
288+
"source": []
289+
},
290+
{
291+
"cell_type": "code",
292+
"execution_count": null,
293+
"id": "65ceed4e-54d6-4abb-abde-85ced69e908b",
294+
"metadata": {},
295+
"outputs": [],
296+
"source": []
297+
},
298+
{
299+
"cell_type": "code",
300+
"execution_count": null,
301+
"id": "1ccfe146-9ea2-4508-89f5-0599305de9d2",
302+
"metadata": {},
303+
"outputs": [],
304+
"source": []
305+
},
306+
{
307+
"cell_type": "code",
308+
"execution_count": null,
309+
"id": "4d9b3396-6090-40df-98c6-0d3427eafb62",
310+
"metadata": {},
311+
"outputs": [],
312+
"source": []
313+
},
314+
{
315+
"cell_type": "code",
316+
"execution_count": null,
317+
"id": "11f1cda0-aa89-47ab-b18c-f2f97954e526",
318+
"metadata": {},
319+
"outputs": [],
320+
"source": []
321+
},
322+
{
323+
"cell_type": "code",
324+
"execution_count": null,
325+
"id": "0cd7fb3d-3f59-4a4d-81ae-7d15bb426381",
326+
"metadata": {},
327+
"outputs": [],
328+
"source": []
329+
}
330+
],
331+
"metadata": {
332+
"kernelspec": {
333+
"display_name": "Python 3 (ipykernel)",
334+
"language": "python",
335+
"name": "python3"
336+
},
337+
"language_info": {
338+
"codemirror_mode": {
339+
"name": "ipython",
340+
"version": 3
341+
},
342+
"file_extension": ".py",
343+
"mimetype": "text/x-python",
344+
"name": "python",
345+
"nbconvert_exporter": "python",
346+
"pygments_lexer": "ipython3",
347+
"version": "3.11.7"
348+
}
349+
},
350+
"nbformat": 4,
351+
"nbformat_minor": 5
352+
}

0 commit comments

Comments
 (0)