diff --git a/week1/community-contributions/Week1-Day1-Exercise.ipynb b/week1/community-contributions/Week1-Day1-Exercise.ipynb new file mode 100644 index 0000000..fa1cb81 --- /dev/null +++ b/week1/community-contributions/Week1-Day1-Exercise.ipynb @@ -0,0 +1,85 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "88cfea73-04f1-41ca-b2e3-46e0bf4588ce", + "metadata": {}, + "outputs": [], + "source": [ + "# imports\n", + "\n", + "import os\n", + "import requests\n", + "from dotenv import load_dotenv\n", + "from bs4 import BeautifulSoup\n", + "from IPython.display import Markdown, display\n", + "from openai import OpenAI" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "830fdf5c-0f18-49a7-b1ce-94b57187b8fc", + "metadata": {}, + "outputs": [], + "source": [ + "openai = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2e20a5e-0809-409e-bc31-c939172167e4", + "metadata": {}, + "outputs": [], + "source": [ + "# Step 1: Create your prompts\n", + "\n", + "system_prompt = \"You are a Software Developer Assistant\"\n", + "user_prompt = \"\"\"\n", + " You are a Software Engineer assistant. \\\n", + " When a user asks a technical question about any concept, explain the answer to the question \\\n", + " along with code examples or usage in a simple way \\\n", + " Always format the answer in markdown\n", + "\"\"\"\n", + "\n", + "# Step 2: Make the messages list\n", + "\n", + "messages = [\n", + " {\"role\": \"system\", \"content\": \"You are a Software Developer Assistant\"},\n", + " {\"role\": \"user\", \"content\": \"What is LLM?\"}\n", + "]\n", + "\n", + "# Step 3: Call OpenAI\n", + "\n", + "response = openai.chat.completions.create(model=\"llama3.2\", messages=messages)\n", + "\n", + "\n", + "# Step 4: print the result\n", + "print(response.choices[0].message.content)\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}