From 447ffbc674fb4a5d65450070b9c0094331c6a36d Mon Sep 17 00:00:00 2001 From: Ted Sanders Date: Fri, 16 Jun 2023 17:02:42 -0700 Subject: [PATCH] cleaned up notebook --- ...estion_answering_using_a_search_API.ipynb} | 196 +++--------------- 1 file changed, 27 insertions(+), 169 deletions(-) rename examples/{Search_augmented_by_query_generation_and_embeddings_reranking.ipynb => Question_answering_using_a_search_API.ipynb} (60%) diff --git a/examples/Search_augmented_by_query_generation_and_embeddings_reranking.ipynb b/examples/Question_answering_using_a_search_API.ipynb similarity index 60% rename from examples/Search_augmented_by_query_generation_and_embeddings_reranking.ipynb rename to examples/Question_answering_using_a_search_API.ipynb index 02dc0a4d..17baf643 100644 --- a/examples/Search_augmented_by_query_generation_and_embeddings_reranking.ipynb +++ b/examples/Question_answering_using_a_search_API.ipynb @@ -5,7 +5,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Search augmented by query generation and embeddings reranking\n", + "# Question answering using a search API and re-ranking\n", "\n", "Searching for relevant information can sometimes feel like looking for a needle in a haystack, but don’t despair, GPTs can actually do a lot of this work for us. In this guide we explore a way to augment existing search systems with various AI techniques, helping us sift through the noise.\n", "\n", @@ -44,16 +44,17 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "%env NEWS_API_KEY = YOUR_API_KEY\n" + "%%capture\n", + "%env NEWS_API_KEY = NEWS_API_KEY\n" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -70,16 +71,17 @@ "# Load environment variables\n", "news_api_key = os.getenv(\"NEWS_API_KEY\")\n", "\n", + "GPT_MODEL = \"gpt-3.5-turbo\"\n", "\n", "# Helper functions\n", "def json_gpt(input: str):\n", " completion = openai.ChatCompletion.create(\n", - " model=\"gpt-4\",\n", + " model=GPT_MODEL,\n", " messages=[\n", " {\"role\": \"system\", \"content\": \"Output only valid JSON\"},\n", " {\"role\": \"user\", \"content\": input},\n", " ],\n", - " temperature=1,\n", + " temperature=0.5,\n", " )\n", "\n", " text = completion.choices[0].message.content\n", @@ -106,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -124,33 +126,12 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['NBA championship winner',\n", - " 'NBA finals MVP',\n", - " 'last NBA championship game',\n", - " 'recent NBA finals results',\n", - " 'NBA finals champions',\n", - " 'NBA finals MVP and winner',\n", - " 'latest NBA championship game details',\n", - " 'NBA championship winning team',\n", - " 'most recent NBA finals MVP',\n", - " 'last NBA finals game summary',\n", - " 'latest NBA finals champion and MVP',\n", - " 'Who won the NBA championship? And who was the MVP? Tell me a bit about the last game.']" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "QUERIES_INPUT = f\"\"\"\n", + "You have access to a search API that returns recent news articles.\n", "Generate an array of search queries that are relevant to this question.\n", "Use a variation of related keywords for the queries, trying to be as general as possible.\n", "Include as many queries as you can think of, including and excluding terms.\n", @@ -180,17 +161,9 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "100%|██████████| 12/12 [00:04<00:00, 2.69it/s]\n" - ] - } - ], + "outputs": [], "source": [ "def search_news(\n", " query: str,\n", @@ -226,41 +199,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Total number of articles: 356\n", - "Top 5 articles of query 1: \n", - "\n", - "Title: Nascar takes on Le Mans as LeBron James gets centenary race under way\n", - "Description: The crowd chanted “U-S-A! U-S-A!” as Nascar driver lineup for the 24 Hours of Le Mans passed through the city cente…\n", - "Content: The crowd chanted U-S-A! U-S-A! as Nascar driver lineup for the 24 Hours of Le Mans passed through t...\n", - "\n", - "Title: Futura and Michelob ULTRA Toast to the NBA Finals With Abstract Artwork Crafted From the Brand’s 2023 Limited-Edition Championship Bottles\n", - "Description: The sun is out to play, and so is Michelob ULTRA. With the 2022-2023 NBA Finals underway, the beermaker is back with its celebratory NBA Champ Bottles. This year, the self-proclaimed MVP of joy is dropping a limited-edition bottle made in collaboration with a…\n", - "Content: The sun is out to play, and so is Michelob ULTRA. With the 2022-2023 NBA Finals underway, the beerma...\n", - "\n", - "Title: Signed and Delivered, Futura and Michelob ULTRA Will Gift Hand-Painted Bottles to This Year’s NBA Championship Team\n", - "Description: Michelob ULTRA, the MVP of joy and official beer sponsor of the NBA is back to celebrate with basketball lovers and sports fans around the globe as the NBA 2022-2023 season comes to a nail-biting close. In collaboration with artist Futura, Michelob ULTRA will…\n", - "Content: Michelob ULTRA, the MVP of joy and official beer sponsor of the NBA is back to celebrate with basket...\n", - "\n", - "Title: Alexis Ohanian and Serena Williams are building a mini-sports empire with a new golf team that's part of a league created by Tiger Woods and Rory McIlroy\n", - "Description: Ohanian and Williams are already co-owners of the National Women's Soccer League Los Angeles team, Angel City FC.\n", - "Content: Alexis Ohanian and Serena Williams attend The 2023 Met Gala.Cindy Ord/Getty Images\n", - "