{ "cells": [ { "cell_type": "markdown", "id": "fe12c203-e6a6-452c-a655-afb8a03a4ff5", "metadata": {}, "source": [ "# End of week 1 exercise\n", "\n", "To demonstrate your familiarity with OpenAI API, and also Ollama, build a tool that takes a technical question, \n", "and responds with an explanation. This is a tool that you will be able to use yourself during the course!" ] }, { "cell_type": "code", "execution_count": 13, "id": "fa9aa00e-806d-4d42-911f-a58114f343df", "metadata": {}, "outputs": [], "source": [ "# imports\n", "import os\n", "import json\n", "import requests\n", "from dotenv import load_dotenv\n", "from bs4 import BeautifulSoup\n", "from IPython.display import Markdown, display, clear_output\n", "from openai import OpenAI\n", "import ollama\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 14, "id": "4a456906-915a-4bfd-bb9d-57e505c5093f", "metadata": {}, "outputs": [], "source": [ "# constants\n", "MODEL_GPT = 'gpt-4o-mini'\n", "MODEL_LLAMA = 'llama3.2'\n", "URL_LLAMA = 'http://localhost:11434/api/chat'" ] }, { "cell_type": "code", "execution_count": 15, "id": "a8d7923c-5f28-4c30-8556-342d7c8497c1", "metadata": {}, "outputs": [], "source": [ "# set up environment\n", "load_dotenv()\n", "api_key = os.getenv('OPENAI_API_KEY')\n", "openai = OpenAI()" ] }, { "cell_type": "code", "execution_count": 25, "id": "3f0d0137-52b0-47a8-81a8-11a90a010798", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7872\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "