|
174 | 174 | ], |
175 | 175 | "source": [ |
176 | 176 | "import os\n", |
| 177 | + "\n", |
177 | 178 | "from openai import OpenAI\n", |
178 | 179 | "\n", |
179 | 180 | "# Initialize OpenAI client (for demonstration - API key needed for actual calls)\n", |
180 | 181 | "api_key = os.getenv(\"OPENAI_API_KEY\", \"demo-key-for-notebook\")\n", |
181 | 182 | "client = OpenAI(api_key=api_key) if api_key != \"demo-key-for-notebook\" else None\n", |
182 | 183 | "\n", |
| 184 | + "\n", |
183 | 185 | "def ask_agent(messages, system_prompt=\"You are a helpful assistant.\"):\n", |
184 | 186 | " \"\"\"Simple function to call OpenAI with context\"\"\"\n", |
185 | 187 | " if client and api_key != \"demo-key-for-notebook\":\n", |
186 | 188 | " # Real OpenAI API call\n", |
187 | 189 | " response = client.chat.completions.create(\n", |
188 | 190 | " model=\"gpt-4o-mini\",\n", |
189 | | - " messages=[\n", |
190 | | - " {\"role\": \"system\", \"content\": system_prompt},\n", |
191 | | - " *messages\n", |
192 | | - " ]\n", |
| 191 | + " messages=[{\"role\": \"system\", \"content\": system_prompt}, *messages],\n", |
193 | 192 | " )\n", |
194 | 193 | " return response.choices[0].message.content\n", |
195 | 194 | " else:\n", |
196 | 195 | " # Demo response for notebook execution\n", |
197 | | - " user_content = messages[0]['content'] if messages else \"general query\"\n", |
| 196 | + " user_content = messages[0][\"content\"] if messages else \"general query\"\n", |
198 | 197 | " if \"Redis course\" in user_content:\n", |
199 | 198 | " return \"Based on your background and goals, I recommend starting with RU101 (Introduction to Redis) to build a solid foundation, then progressing to RU201 (Redis for Python) which aligns with your programming experience and interests.\"\n", |
200 | 199 | " elif \"long will that take\" in user_content:\n", |
201 | 200 | " return \"RU201 (Redis for Python) typically takes 6-8 hours to complete, including hands-on exercises. Given your evening and weekend availability, you could finish it in 2-3 weeks at a comfortable pace.\"\n", |
202 | 201 | " else:\n", |
203 | 202 | " return \"I'd be happy to help with your Redis learning journey. Could you tell me more about your background and what you're hoping to achieve?\"\n", |
204 | 203 | "\n", |
| 204 | + "\n", |
205 | 205 | "print(\"Setup complete! (Using demo responses - set OPENAI_API_KEY for real API calls)\")" |
206 | 206 | ] |
207 | 207 | }, |
|
325 | 325 | " \"preferred_format\": \"online\",\n", |
326 | 326 | " \"preferred_difficulty\": \"intermediate\",\n", |
327 | 327 | " \"learning_style\": \"hands-on projects\",\n", |
328 | | - " \"time_availability\": \"evenings and weekends\"\n", |
| 328 | + " \"time_availability\": \"evenings and weekends\",\n", |
329 | 329 | "}\n", |
330 | 330 | "\n", |
331 | 331 | "print(\"Student Profile Example:\")\n", |
332 | 332 | "print(f\"Name: {student_profile['name']}\")\n", |
333 | 333 | "print(f\"Major: {student_profile['major']}\")\n", |
334 | 334 | "print(f\"Interests: {', '.join(student_profile['interests'])}\")\n", |
335 | 335 | "print(f\"Completed: {len(student_profile['completed_courses'])} courses\")\n", |
336 | | - "print(f\"Preferences: {student_profile['preferred_format']}, {student_profile['preferred_difficulty']} level\")" |
| 336 | + "print(\n", |
| 337 | + " f\"Preferences: {student_profile['preferred_format']}, {student_profile['preferred_difficulty']} level\"\n", |
| 338 | + ")" |
337 | 339 | ] |
338 | 340 | }, |
339 | 341 | { |
|
0 commit comments