You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openai-cookbook/examples/gpt4o/introduction_to_gpt4o.ipynb

825 lines
1.2 MiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction to GPT-4o and GPT-4o mini\n",
"\n",
"GPT-4o (\"o\" for \"omni\") and GPT-4o mini are natively multimodal models designed to handle a combination of text, audio, and video inputs, and can generate outputs in text, audio, and image formats. GPT-4o mini is the lightweight version of GPT-4o.\n",
"\n",
"### Background\n",
"\n",
"Before GPT-4o, users could interact with ChatGPT using Voice Mode, which operated with three separate models. GPT-4o integrates these capabilities into a single model that's trained across text, vision, and audio. This unified approach ensures that all inputs — whether text, visual, or auditory — are processed cohesively by the same neural network.\n",
"\n",
"GPT-4o mini is the next iteration of this omni model family, available in a smaller and cheaper version. This model offers higher accuracy than GPT-3.5 Turbo while being just as fast and supporting multimodal inputs and outputs.\n",
"\n",
"### Current API Capabilities\n",
"\n",
"Currently, the API supports `{text, image}` inputs only, with `{text}` outputs, the same modalities as `gpt-4-turbo`.\n",
"\n",
"Additional modalities, including audio, will be introduced soon. This guide will help you get started with using GPT-4o mini for text, image, and video understanding."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting Started"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Install OpenAI SDK for Python\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install --upgrade openai"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Configure the OpenAI client and submit a test request\n",
"To setup the client for our use, we need to create an API key to use with our request. Skip these steps if you already have an API key for usage. \n",
"\n",
"You can get an API key by following these steps:\n",
"1. [Create a new project](https://help.openai.com/en/articles/9186755-managing-your-work-in-the-api-platform-with-projects)\n",
"2. [Generate an API key in your project](https://platform.openai.com/api-keys)\n",
"3. (RECOMMENDED, BUT NOT REQUIRED) [Setup your API key for all projects as an env var](https://platform.openai.com/docs/quickstart/step-2-set-up-your-api-key)\n",
"\n",
"Once we have this setup, let's start with a simple {text} input to the model for our first request. We'll use both `system` and `user` messages for our first request, and we'll receive a response from the `assistant` role."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from openai import OpenAI \n",
"import os\n",
"\n",
"## Set the API key and model name\n",
"MODEL=\"gpt-4o-mini\"\n",
"client = OpenAI(api_key=os.environ.get(\"OPENAI_API_KEY\", \"<your OpenAI API key if not set as an env var>\"))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Assistant: Of course! \\( 2 + 2 = 4 \\).\n"
]
}
],
"source": [
"completion = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant. Help me with my math homework!\"}, # <-- This is the system message that provides context to the model\n",
" {\"role\": \"user\", \"content\": \"Hello! Could you solve 2+2?\"} # <-- This is the user message for which the model will generate a response\n",
" ]\n",
")\n",
"\n",
"print(\"Assistant: \" + completion.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Image Processing\n",
"GPT-4o mini can directly process images and take intelligent actions based on the image. We can provide images in two formats:\n",
"1. Base64 Encoded\n",
"2. URL\n",
"\n",
"Let's first view the image we'll use, then try sending this image as both Base64 and as a URL link to the API"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnEAAAEcCAAAAACNZL39AAAACXBIWXMAAAsSAAALEgHS3X78AAAfF0lEQVR42u2d63LjuLKlv0xAAMmyXKf3mT3v/34zs0902S2JFICcH3K55Lsk60JKWBHd0W1bFJhYyAQSeRGjouKM0CqCisq4isq4iorKuIrKuIqKyriKyriKyriKisq4iiuFryI4BwTEfKLe8FTGnYVv4qw4S3iplKtW9QyE82TFMlqIlXGVEKdGF7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QxvL6gIayRs+9kt0Y1LfGqaaFZOcrTbZb3vejn3eXF4XstFy2IdUIdB0KzwuXXl/RqNEOhWb3wXHorBj5dqu7mxBgn+Gy8KDovsUfaxceUc79Fe8lyWCdlHAjE9etAcgnSE/wibLVbEtHclFS4lDtualbVk01jLNvH0x7CIgwf3CNFKR0uOv59hQb1GSauL+2r3tNS+rkOCx388Pyz4HJcDSWG5aWGOjEd58k+8SLIS2j74hPvuzR9RuIKCP1FB35iHQe+aCam/OKMcPfI/S8Nf27BXIFowzvHjMq496EGtEPevjNQc5kwvCtEIQzzB9zF9dvJGYeII9EMeXu5NevcrJ5vWH7XjnJxUWNHdoQFR7PMvDxpBZohmrw3zz7zOCddsUF9Fg0pO1Zl6/Yhsc6smphEpZNWXG5zTBwlVfvwlTGxk4Oa5lfx/a6IZt4Jp276sDZ8HkOd8NPrOGh6l3F5O2ROECngE2hBNYXh8FTL42Byt1zWvl4lyizDm/RNEXQwdamMgXAe5qcex4osCNuXrGaIJxacK47iSITVZVfg1M6qpXsk3b0o/efaITa
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import Image, display, Audio, Markdown\n",
"import base64\n",
"\n",
"IMAGE_PATH = \"data/triangle.png\"\n",
"\n",
"# Preview image for context\n",
"display(Image(IMAGE_PATH))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Base64 Image Processing"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"To find the area of the triangle, you can use the formula:\n",
"\n",
"\\[\n",
"\\text{Area} = \\frac{1}{2} \\times \\text{base} \\times \\text{height}\n",
"\\]\n",
"\n",
"In the triangle you provided:\n",
"\n",
"- The base is \\(9\\) (the length at the bottom).\n",
"- The height is \\(5\\) (the vertical line from the top vertex to the base).\n",
"\n",
"Now, plug in the values:\n",
"\n",
"\\[\n",
"\\text{Area} = \\frac{1}{2} \\times 9 \\times 5\n",
"\\]\n",
"\n",
"Calculating this:\n",
"\n",
"\\[\n",
"\\text{Area} = \\frac{1}{2} \\times 45 = 22.5\n",
"\\]\n",
"\n",
"Thus, the area of the triangle is **22.5 square units**.\n"
]
}
],
"source": [
"# Open the image file and encode it as a base64 string\n",
"def encode_image(image_path):\n",
" with open(image_path, \"rb\") as image_file:\n",
" return base64.b64encode(image_file.read()).decode(\"utf-8\")\n",
"\n",
"base64_image = encode_image(IMAGE_PATH)\n",
"\n",
"response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant that responds in Markdown. Help me with my math homework!\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" {\"type\": \"text\", \"text\": \"What's the area of the triangle?\"},\n",
" {\"type\": \"image_url\", \"image_url\": {\n",
" \"url\": f\"data:image/png;base64,{base64_image}\"}\n",
" }\n",
" ]}\n",
" ],\n",
" temperature=0.0,\n",
")\n",
"\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### URL Image Processing"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"To find the area of the triangle, you can use the formula:\n",
"\n",
"\\[\n",
"\\text{Area} = \\frac{1}{2} \\times \\text{base} \\times \\text{height}\n",
"\\]\n",
"\n",
"In the triangle you provided:\n",
"\n",
"- The base is \\(9\\) (the length at the bottom).\n",
"- The height is \\(5\\) (the vertical line from the top vertex to the base).\n",
"\n",
"Now, plug in the values:\n",
"\n",
"\\[\n",
"\\text{Area} = \\frac{1}{2} \\times 9 \\times 5\n",
"\\]\n",
"\n",
"Calculating this gives:\n",
"\n",
"\\[\n",
"\\text{Area} = \\frac{1}{2} \\times 45 = 22.5\n",
"\\]\n",
"\n",
"Thus, the area of the triangle is **22.5 square units**.\n"
]
}
],
"source": [
"response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant that responds in Markdown. Help me with my math homework!\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" {\"type\": \"text\", \"text\": \"What's the area of the triangle?\"},\n",
" {\"type\": \"image_url\", \"image_url\": {\n",
" \"url\": \"https://upload.wikimedia.org/wikipedia/commons/e/e2/The_Algebra_of_Mohammed_Ben_Musa_-_page_82b.png\"}\n",
" }\n",
" ]}\n",
" ],\n",
" temperature=0.0,\n",
")\n",
"\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Video Processing\n",
"While it's not possible to directly send a video to the API, GPT-4o can understand videos if you sample frames and then provide them as images. \n",
"\n",
"Since GPT-4o mini in the API does not yet support audio-in (as of July 2024), we'll use a combination of GPT-4o mini and Whisper to process both the audio and visual for a provided video, and showcase two usecases:\n",
"1. Summarization\n",
"2. Question and Answering\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setup for Video Processing\n",
"We'll use two python packages for video processing - opencv-python and moviepy. \n",
"\n",
"These require [ffmpeg](https://ffmpeg.org/about.html), so make sure to install this beforehand. Depending on your OS, you may need to run `brew install ffmpeg` or `sudo apt install ffmpeg`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install opencv-python\n",
"%pip install moviepy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Process the video into two components: frames and audio"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"from moviepy.editor import VideoFileClip\n",
"import time\n",
"import base64\n",
"\n",
"# We'll be using the OpenAI DevDay Keynote Recap video. You can review the video here: https://www.youtube.com/watch?v=h02ti0Bl6zk\n",
"VIDEO_PATH = \"data/keynote_recap.mp4\""
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MoviePy - Writing audio in data/keynote_recap.mp3\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" "
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"MoviePy - Done.\n",
"Extracted 218 frames\n",
"Extracted audio to data/keynote_recap.mp3\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\r"
]
}
],
"source": [
"def process_video(video_path, seconds_per_frame=2):\n",
" base64Frames = []\n",
" base_video_path, _ = os.path.splitext(video_path)\n",
"\n",
" video = cv2.VideoCapture(video_path)\n",
" total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))\n",
" fps = video.get(cv2.CAP_PROP_FPS)\n",
" frames_to_skip = int(fps * seconds_per_frame)\n",
" curr_frame=0\n",
"\n",
" # Loop through the video and extract frames at specified sampling rate\n",
" while curr_frame < total_frames - 1:\n",
" video.set(cv2.CAP_PROP_POS_FRAMES, curr_frame)\n",
" success, frame = video.read()\n",
" if not success:\n",
" break\n",
" _, buffer = cv2.imencode(\".jpg\", frame)\n",
" base64Frames.append(base64.b64encode(buffer).decode(\"utf-8\"))\n",
" curr_frame += frames_to_skip\n",
" video.release()\n",
"\n",
" # Extract audio from video\n",
" audio_path = f\"{base_video_path}.mp3\"\n",
" clip = VideoFileClip(video_path)\n",
" clip.audio.write_audiofile(audio_path, bitrate=\"32k\")\n",
" clip.audio.close()\n",
" clip.close()\n",
"\n",
" print(f\"Extracted {len(base64Frames)} frames\")\n",
" print(f\"Extracted audio to {audio_path}\")\n",
" return base64Frames, audio_path\n",
"\n",
"# Extract 1 frame per second. You can adjust the `seconds_per_frame` parameter to change the sampling rate\n",
"base64Frames, audio_path = process_video(VIDEO_PATH, seconds_per_frame=1)\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCALQBQADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD4Dooor6g/lcKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooA
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {
"image/jpeg": {
"width": 600
}
},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <audio controls=\"controls\" >\n",
" <source src=\"data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAB+PAAziXQADBggLDRASFRcaHB8hJCYpKy4wMzU4Oj1AQkZIS01QUlVXWlxfYWRmaWtucHN1eHp9gIKFh4qMkJKVl5qcn6GkpqmrrrCztbi6vcDCxcfKzM/R1Nba3N/h5Obp6+7w8/X4+v0AAAAATGF2YzU4LjU0AAAAAAAAAAAAAAAAJAU0AAAAAAAM4l1dmhK4AAAAAAAAAAAAAAAAAAAAAP/7EGQAD/AAAGkAAAAIAAANIAAAAQAAAaQAAAAgAAA0gAAABAUQKxYyaP/mjIKIFYqaMnPzJpUx8eTAfuTAz4CD8MHfgy0p0DOUWP4gqYR24rJ+wBBIBamBwyjXBuQSvMpccm1qsYxi//sSZCIP8AAAaQAAAAgAAA0gAAABAAABpAAAACAAADSAAAAEgGaL0VOC5ASBJQ73I/uwxtkNYvd+/RVrTSoAB0RmACncQCJRQfBmKSihL11Oos9n0a7g4zAS7oGjySnpFxsZQ7Tm0Mcx//sQZESP8AAAaQAAAAgAAA0gAAABAAABpAAAACAAADSAAAAE3TJ0QNh4UGD3mm/16dfx+v//Q4vUTMLN7jBhSjGpl6m+rf/31cf8KT8mHhogqBBzeILNZ6z1N/1ABCDSABeAHgkuAj7/+xJkZo/wAABpAAAACAAADSAAAAEAAAGkAAAAIAAANIAAAASU0396/z37EUAAMx+BhCXhjkqQO+Yvc/i/9X+uAANQTYAAtuzjKHNKbjIteSUABAmVBlUAAbbRWl/w/eARcwXJ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Ag46P+VmiVgKSaYPOxjOdYR1Xf14liqP4UqwFpI+3g6sR/8tYiBWglrwIw32xvpOoGYWnXW//sQZCcP8H0GzoMPKJAOYNmQPAIwAeQbOAw84kA+A2YBhKxITkGspEkOex1qqBxv/K1gxAoYBRG0pqisLJA2W9v/6IISsvwAUVzIeEUhE3/p/pWoDpU4N2keFAi53j08TR/hi6hqvoT/+xJkKo/wgQhNgwgRmA6A2bBh6hICLBs4DDziQD4DZsDzKIACDZyARR4aNu/ojoiiCAJxZUrcU71ELy9+7ys0OmHnpqBGvWL+mBN0j0J8ASGUoCyQx0zmNfPTj3JySPf/bSg0JkEZ5J7/+xBkLQ/whAhNgwwQsA6A2bBhKhICHB84DDziQDsDJsGGIExxPk843FX/01ArY3AIvkUHoOiTKwJpPW7yVcQNFtPkUPm7dVfW//9dpRU5cYMAmraZCNYFGt/7/5T+teAAWGAAKQ3gEv/7EmQvj/CdBk4B+HgAD0DZoGAGMAIwGzYMJCSAOQHmgYxgALi0wN//XdHJjrwE4aG7ZA3TAki//u/VodoSQEAVmWD0r/CHv3+U6xBgw7NJSlWHfBhZH/EP8rUfxecGKXndsY3YWaoyPv/7EGQwjzCUEc6DCTkADyDZ5T1CEQIoGzoMICSAPINmwYMEkKphTgVkFAFrX8PIqcA7j/+p/81ii6DUrPBxuxo1Qif/1ApABohIuxQwY0uGikEb93Lwmh5CrCQ4IjO+gz+j34LaMBUu//sSZDGP8IMGzoMGOQAPIMmgPwYCAlQZOAxhAEA3AycBhhxIQEV/yIjr6G/V8pAyArDAApSPlWmA6q7+usHLOj0dQpKOM4q3mQg03uu8QwfGgSYRuRnNZ5wWzpD/OQaTgsqnm1+AOFt+//sQZDQD8IMG0CsPKJgNgMmwQekCAfAbPAwkBIA4g2cAp5wQI8Rf/I9DAIReyxobS0Aqb/
" Your browser does not support the audio element.\n",
" </audio>\n",
" "
],
"text/plain": [
"<IPython.lib.display.Audio object>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"## Display the frames and audio for context\n",
"display_handle = display(None, display_id=True)\n",
"for img in base64Frames:\n",
" display_handle.update(Image(data=base64.b64decode(img.encode(\"utf-8\")), width=600))\n",
" time.sleep(0.025)\n",
"\n",
"Audio(audio_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Example 1: Summarization\n",
"Now that we have both the video frames and the audio, let's run a few different tests to generate a video summary to compare the results of using the models with different modalities. We should expect to see that the summary generated with context from both visual and audio inputs will be the most accurate, as the model is able to use the entire context from the video.\n",
"\n",
"1. Visual Summary\n",
"2. Audio Summary\n",
"3. Visual + Audio Summary\n",
"\n",
"#### Visual Summary\n",
"The visual summary is generated by sending the model only the frames from the video. With just the frames, the model is likely to capture the visual aspects, but will miss any details discussed by the speaker."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# OpenAI Dev Day Summary\n",
"\n",
"## Overview\n",
"The video captures highlights from OpenAI's Dev Day, showcasing new advancements and features in AI technology, particularly focusing on the latest developments in the GPT-4 model and its applications.\n",
"\n",
"## Key Highlights\n",
"\n",
"### Event Introduction\n",
"- The event is branded as \"OpenAI Dev Day,\" setting the stage for discussions on AI advancements.\n",
"\n",
"### Keynote Recap\n",
"- The keynote features a recap of significant updates and innovations in AI, particularly around the GPT-4 model.\n",
"\n",
"### New Features\n",
"- **GPT-4 Turbo**: Introduction of a faster and more efficient version of GPT-4, emphasizing improved performance and reduced costs.\n",
"- **DALL-E 3**: Updates on the image generation model, showcasing its capabilities and integration with other tools.\n",
"- **Custom Models**: Introduction of features allowing users to create tailored AI models for specific tasks.\n",
"\n",
"### Technical Innovations\n",
"- **Function Calling**: Demonstration of how the model can handle complex instructions and execute functions based on user queries.\n",
"- **JSON Mode**: A new feature that allows for structured data handling, enhancing the model's ability to process and respond to requests.\n",
"\n",
"### User Experience Enhancements\n",
"- **Threading and Retrieval**: New functionalities that improve how users can interact with the model, making it easier to manage conversations and retrieve information.\n",
"- **Code Interpreter**: Introduction of a tool that allows the model to execute code, expanding its utility for developers.\n",
"\n",
"### Community Engagement\n",
"- The event emphasizes community involvement, encouraging developers to explore and utilize the new features in their applications.\n",
"\n",
"### Conclusion\n",
"- The event wraps up with a call to action for developers to engage with the new tools and features, fostering innovation in AI applications.\n",
"\n",
"## Closing Remarks\n",
"The OpenAI Dev Day serves as a platform for showcasing the latest advancements in AI technology, encouraging developers to leverage these innovations for enhanced applications and user experiences.\n"
]
}
],
"source": [
"response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You are generating a video summary. Please provide a summary of the video. Respond in Markdown.\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" \"These are the frames from the video.\",\n",
" *map(lambda x: {\"type\": \"image_url\", \n",
" \"image_url\": {\"url\": f'data:image/jpg;base64,{x}', \"detail\": \"low\"}}, base64Frames)\n",
" ],\n",
" }\n",
" ],\n",
" temperature=0,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The results are as expected - the model is able to capture the high level aspects of the video visuals, but misses the details provided in the speech.\n",
"\n",
"#### Audio Summary\n",
"The audio summary is generated by sending the model the audio transcript. With just the audio, the model is likely to bias towards the audio content, and will miss the context provided by the presentations and visuals.\n",
"\n",
"`{audio}` input for GPT-4o isn't currently available but will be coming soon! For now, we use our existing `whisper-1` model to process the audio"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# OpenAI Dev Day Summary\n",
"\n",
"On the inaugural OpenAI Dev Day, several significant updates and features were announced:\n",
"\n",
"- **Launch of GPT-4 Turbo**: This new model supports up to 128,000 tokens of context and is designed to follow instructions more effectively.\n",
" \n",
"- **JSON Mode**: A new feature that ensures the model responds with valid JSON.\n",
"\n",
"- **Function Calling**: Users can now call multiple functions simultaneously, enhancing the model's capabilities.\n",
"\n",
"- **Retrieval Feature**: This allows models to access external knowledge from documents or databases, improving their contextual understanding.\n",
"\n",
"- **Knowledge Base**: GPT-4 Turbo has knowledge up to April 2023, with plans for ongoing improvements.\n",
"\n",
"- **Dolly 3 and New Models**: The introduction of Dolly 3, GPT-4 Turbo with Vision, and a new Text-to-Speech model, all available via the API.\n",
"\n",
"- **Custom Models Program**: A new initiative where researchers collaborate with companies to create tailored models for specific use cases.\n",
"\n",
"- **Increased Rate Limits**: Established GPT-4 customers will see a doubling of tokens per minute, with options to request further changes in API settings.\n",
"\n",
"- **Cost Efficiency**: GPT-4 Turbo is significantly cheaper than its predecessor, with a 3x reduction for prompt tokens and 2x for completion tokens.\n",
"\n",
"- **Introduction of GPTs**: Tailored versions of ChatGPT designed for specific purposes, allowing users to create and share private or public GPTs easily, even without coding skills.\n",
"\n",
"- **Upcoming GPT Store**: A platform for users to share their GPT creations.\n",
"\n",
"- **Assistance API**: Features persistent threads, built-in retrieval, a code interpreter, and improved function calling to streamline user interactions.\n",
"\n",
"The event concluded with excitement about the future of AI technology and an invitation for attendees to return next year to see further advancements.\n"
]
}
],
"source": [
"# Transcribe the audio\n",
"transcription = client.audio.transcriptions.create(\n",
" model=\"whisper-1\",\n",
" file=open(audio_path, \"rb\"),\n",
")\n",
"## OPTIONAL: Uncomment the line below to print the transcription\n",
"#print(\"Transcript: \", transcription.text + \"\\n\\n\")\n",
"\n",
"response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\":\"\"\"You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown.\"\"\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" {\"type\": \"text\", \"text\": f\"The audio transcription is: {transcription.text}\"}\n",
" ],\n",
" }\n",
" ],\n",
" temperature=0,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The audio summary is biased towards the content discussed during the speech, but comes out with much less structure than the video summary.\n",
"\n",
"#### Audio + Visual Summary\n",
"The Audio + Visual summary is generated by sending the model both the visual and the audio from the video at once. When sending both of these, the model is expected to better summarize since it can perceive the entire video at once."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# OpenAI Dev Day Summary\n",
"\n",
"## Overview\n",
"The first-ever OpenAI Dev Day introduced several exciting updates and features, primarily focusing on the launch of **GPT-4 Turbo**. This new model enhances capabilities and expands the potential for developers and users alike.\n",
"\n",
"## Key Announcements\n",
"\n",
"### 1. **GPT-4 Turbo**\n",
"- **Token Support**: Supports up to **128,000 tokens** of context.\n",
"- **JSON Mode**: A new feature that ensures responses are in valid JSON format.\n",
"- **Function Calling**: Improved ability to call multiple functions simultaneously and better adherence to instructions.\n",
"\n",
"### 2. **Knowledge Retrieval**\n",
"- **Enhanced Knowledge Access**: Users can now integrate external documents or databases, allowing models to access updated information beyond their training cut-off (April 2023).\n",
"\n",
"### 3. **DALL-E 3 and Other Models**\n",
"- Launch of **DALL-E 3**, **GPT-4 Turbo with Vision**, and a new **Text-to-Speech model** in the API.\n",
"\n",
"### 4. **Custom Models Program**\n",
"- Introduction of a program where OpenAI researchers collaborate with companies to create tailored models for specific use cases.\n",
"\n",
"### 5. **Rate Limits and Pricing**\n",
"- **Increased Rate Limits**: Doubling tokens per minute for established GPT-4 customers.\n",
"- **Cost Efficiency**: GPT-4 Turbo is **3x cheaper** for prompt tokens and **2x cheaper** for completion tokens compared to GPT-4.\n",
"\n",
"### 6. **Introduction of GPTs**\n",
"- **Tailored Versions**: GPTs are customized versions of ChatGPT designed for specific tasks, combining instructions, expanded knowledge, and actions.\n",
"- **User-Friendly Creation**: Users can create GPTs through conversation, making it accessible even for those without coding skills.\n",
"- **GPT Store**: A new platform for sharing and discovering GPTs, launching later this month.\n",
"\n",
"### 7. **Assistance API Enhancements**\n",
"- Features include persistent threads, built-in retrieval, a code interpreter, and improved function calling.\n",
"\n",
"## Conclusion\n",
"The event highlighted OpenAI's commitment to enhancing AI capabilities and accessibility for developers. The advancements presented are expected to empower users to create innovative applications and solutions. OpenAI looks forward to future developments and encourages ongoing engagement with the community. \n",
"\n",
"Thank you for attending!\n"
]
}
],
"source": [
"## Generate a summary with visual and audio\n",
"response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\":\"\"\"You are generating a video summary. Create a summary of the provided video and its transcript. Respond in Markdown\"\"\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" \"These are the frames from the video.\",\n",
" *map(lambda x: {\"type\": \"image_url\", \n",
" \"image_url\": {\"url\": f'data:image/jpg;base64,{x}', \"detail\": \"low\"}}, base64Frames),\n",
" {\"type\": \"text\", \"text\": f\"The audio transcription is: {transcription.text}\"}\n",
" ],\n",
" }\n",
"],\n",
" temperature=0,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After combining both the video and audio, we're able to get a much more detailed and comprehensive summary for the event which uses information from both the visual and audio elements from the video.\n",
"\n",
"### Example 2: Question and Answering\n",
"For the Q&A, we'll use the same concept as before to ask questions of our processed video while running the same 3 tests to demonstrate the benefit of combining input modalities:\n",
"1. Visual Q&A\n",
"2. Audio Q&A\n",
"3. Visual + Audio Q&A "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"QUESTION = \"Question: Why did Sam Altman have an example about raising windows and turning the radio on?\""
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Visual QA:\n",
"Sam Altman used the example of raising windows and turning the radio on to illustrate the concept of function calling in AI. This example demonstrates how AI can interpret natural language commands and translate them into specific function calls, making interactions more intuitive and user-friendly. By showing a relatable scenario, he highlighted the advancements in AI's ability to understand and execute complex tasks based on simple instructions.\n"
]
}
],
"source": [
"qa_visual_response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"Use the video to answer the provided question. Respond in Markdown.\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" \"These are the frames from the video.\",\n",
" *map(lambda x: {\"type\": \"image_url\", \"image_url\": {\"url\": f'data:image/jpg;base64,{x}', \"detail\": \"low\"}}, base64Frames),\n",
" QUESTION\n",
" ],\n",
" }\n",
" ],\n",
" temperature=0,\n",
")\n",
"print(\"Visual QA:\\n\" + qa_visual_response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Audio QA:\n",
"The transcription provided does not include any mention of Sam Altman discussing raising windows or turning the radio on. Therefore, I cannot provide an answer to that specific question based on the given text. If you have more context or another transcription that includes that example, please share it, and I would be happy to help!\n"
]
}
],
"source": [
"qa_audio_response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\":\"\"\"Use the transcription to answer the provided question. Respond in Markdown.\"\"\"},\n",
" {\"role\": \"user\", \"content\": f\"The audio transcription is: {transcription.text}. \\n\\n {QUESTION}\"},\n",
" ],\n",
" temperature=0,\n",
")\n",
"print(\"Audio QA:\\n\" + qa_audio_response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Both QA:\n",
"Sam Altman used the example of raising windows and turning the radio on to illustrate the new function calling feature in GPT-4 Turbo. This example demonstrates how the model can interpret natural language commands and translate them into specific function calls, making it easier for users to interact with the model in a more intuitive way. It highlights the model's ability to understand context and perform multiple actions based on user instructions.\n"
]
}
],
"source": [
"qa_both_response = client.chat.completions.create(\n",
" model=MODEL,\n",
" messages=[\n",
" {\"role\": \"system\", \"content\":\"\"\"Use the video and transcription to answer the provided question.\"\"\"},\n",
" {\"role\": \"user\", \"content\": [\n",
" \"These are the frames from the video.\",\n",
" *map(lambda x: {\"type\": \"image_url\", \n",
" \"image_url\": {\"url\": f'data:image/jpg;base64,{x}', \"detail\": \"low\"}}, base64Frames),\n",
" {\"type\": \"text\", \"text\": f\"The audio transcription is: {transcription.text}\"},\n",
" QUESTION\n",
" ],\n",
" }\n",
" ],\n",
" temperature=0,\n",
")\n",
"print(\"Both QA:\\n\" + qa_both_response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Comparing the three answers, the most accurate answer is generated by using both the audio and visual from the video. Sam Altman did not discuss the raising windows or radio on during the Keynote, but referenced an improved capability for the model to execute multiple functions in a single request while the examples were shown behind him.\n",
"\n",
"## Conclusion\n",
"\n",
"Integrating many input modalities such as audio, visual, and textual, significantly enhances the performance of the model on a diverse range of tasks. This multimodal approach allows for more comprehensive understanding and interaction, mirroring more closely how humans perceive and process information. \n",
"\n",
"Currently, GPT-4o and GPT-4o mini in the API support text and image inputs, with audio capabilities coming soon."
]
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}