{ "cells": [ { "cell_type": "code", "outputs": [], "source": [ "import instructor\n", "from pydantic import BaseModel\n", "from openai import OpenAI\n", "\n", "import dotenv\n", "from tqdm.auto import trange\n", "\n", "import json" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-23T21:23:26.793952Z", "start_time": "2024-05-23T21:23:26.789582Z" } }, "id": "1b2180343e5180dd", "execution_count": 36 }, { "cell_type": "code", "outputs": [ { "data": { "text/plain": "True" }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dotenv.load_dotenv()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-23T20:49:24.686772Z", "start_time": "2024-05-23T20:49:24.683815Z" } }, "id": "1296d472faf81f48", "execution_count": 20 }, { "cell_type": "code", "outputs": [], "source": [ "def get_initial_messages(transcript: str):\n", " return [\n", " {\n", " \"role\": \"system\",\n", " \"content\": [\n", " {\n", " \"type\": \"text\",\n", " \"text\": \"You are a trivia bot writing fun questions for a trivia game. You have been given a transcript of a video. You need to write two questions based on the transcript. Do not refer explicitly to the transcript - it should be a valid question at a trivia night, for fans of the show, which is Hot Ones, Season 19. The questions should be in a JSON format.\"\n", " }\n", " ]\n", " },\n", " {\n", " \"role\": \"user\",\n", " \"content\": [\n", " {\n", " \"type\": \"text\",\n", " \"text\": f\"Transcript: {transcript}\"\n", " }\n", " ]\n", " }\n", " ]" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-23T21:19:34.503329Z", "start_time": "2024-05-23T21:19:34.498Z" } }, "id": "e511c7f86475ac01", "execution_count": 30 }, { "cell_type": "code", "outputs": [], "source": [ "class TriviaQuestions(BaseModel):\n", " question1: str\n", " answer1: str\n", " question2: str\n", " answer2: str\n" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-23T21:19:34.945726Z", "start_time": "2024-05-23T21:19:34.944360Z" } }, "id": "66b2c3c81748b42e", "execution_count": 31 }, { "cell_type": "code", "outputs": [], "source": [ "\n", "# Patch the OpenAI client\n", "client = instructor.from_openai(OpenAI())" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-23T21:19:35.327482Z", "start_time": "2024-05-23T21:19:35.313726Z" } }, "id": "e3f857ded1a29732", "execution_count": 32 }, { "cell_type": "code", "outputs": [ { "data": { "text/plain": " 0%| | 0/17 [00:00