{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Custom model-graded evals \n",
    "\n",
    "**Note: This lesson lives in a folder that contains relevant code files. Download the entire folder if you want to follow along and run the evaluation yourself**\n",
    "\n",
    "\n",
    "In this lesson, we'll see how we can write custom model-graded evaluations using promptfoo. We'll start with a simple prompting goal: we want to write a prompt that can turn long, technically complex Wikipedia articles into short summaries appropriate for a grade school audience.\n",
    "\n",
    "For example, given the entire [Wikipedia entry on convolutional neural networks](https://en.wikipedia.org/wiki/Convolutional_neural_network), we want simple output summary like this one:\n",
    "\n",
    "> Convolutional neural networks, or CNNs, are a special type of computer program that can learn to recognize images and patterns. They work a bit like the human brain, using layers of artificial \"neurons\" to process information.\n",
    "CNNs are really good at tasks like identifying objects in pictures or recognizing faces. They do this by breaking down images into smaller pieces and looking for important features, kind of like putting together a puzzle.\n",
    "What makes CNNs special is that they can learn these features on their own by looking at lots of examples. This allows them to get better and better at recognizing things, sometimes even matching human-level performance.\n",
    "Scientists and engineers use CNNs for all sorts of cool applications, like helping self-driving cars see the road, finding new medicines, or even teaching computers to play games like chess and Go.\n",
    "\n",
    "To evaluate the effectiveness of our prompts, we're going to write a custom model-graded assertion that assesses a resulting summary across three metrics:\n",
    "\n",
    "* Conciseness (1-5) - is the summary as concise as possible?\n",
    "* Accuracy (1-5) - is the summary completely accurate based on the initial article'?\n",
    "* Tone (1-5) - is the summary appropriate for a grade school student with no technical training?\n",
    "\n",
    "Each of these metrics will result in a score between 1 and 5.  We'll average them together and aim for an average score of at least 4.5/5. To do this, we'll define a custom model-grader function!\n",
    "\n",
    "---\n",
    "    \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The input data\n",
    "\n",
    "Our goal is to write a prompt to summarize complex Wikipedia articles into short, easy to understand summaries.  We'll start by collecting the articles we want to summarize as part of our evaluation.\n",
    "\n",
    "In this folder we've provided an `articles` directory than contains eight different txt files.  Each file contains the text content from a Wikipedia article.   We'll use these articles as the inputs in our evaluation. Take a look at some of the article files to get a sense of how long and complex they are.\n",
    "\n",
    "This dataset consists of only eight test cases, which is far too small for a real-world evaluation.  As we've mentioned many times throughout this course, we highly recommend using evaluation dataset of at least 100 entries.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Our prompts\n",
    "\n",
    "Take a look at the `prompts.py` file. It contains three different prompt-generating functions that we'll evaluate using promptfoo:\n",
    "\n",
    "```py\n",
    "def basic_summarize(article):\n",
    "  return f\"Summarize this article {article}\"\n",
    "\n",
    "def better_summarize(article):\n",
    "  return f\"\"\"\n",
    "  Summarize this article for a grade-school audience: {article}\"\"\"\n",
    "\n",
    "def best_summarize(article):\n",
    "  return f\"\"\"\n",
    "  You are tasked with summarizing long wikipedia articles for a grade-school audience.\n",
    "  Write a short summary, keeping it as concise as possible. \n",
    "  The summary is intended for a non-technical, grade-school audience. \n",
    "  This is the article: {article}\"\"\"\n",
    "```\n",
    "**It's important to note than these prompts are all generally mediocre prompts.  We kept the prompts deliberately short and did not follow best practices, like adding in comprehensive examples, to minimize the number of tokens used when running this evaluation set.** \n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Updating the config file\n",
    "\n",
    "The `promptfooconfig.yaml` file contains fields we've mostly seen before:\n",
    "\n",
    "\n",
    "```yaml\n",
    "description: 'Summarization Evaluation'\n",
    "\n",
    "prompts:\n",
    "  - prompts.py:basic_summarize\n",
    "  - prompts.py:better_summarize\n",
    "  - prompts.py:best_summarize\n",
    "\n",
    "providers:\n",
    "  - id: anthropic:messages:claude-3-5-sonnet-20240620\n",
    "    label: \"3.5 Sonnet\"\n",
    "\n",
    "tests:\n",
    "  - vars:\n",
    "      article: file://articles/article1.txt\n",
    "  - vars:\n",
    "      article: file://articles/article2.txt\n",
    "  - vars:\n",
    "      article: file://articles/article3.txt\n",
    "  - vars:\n",
    "      article: file://articles/article4.txt\n",
    "  - vars:\n",
    "      article: file://articles/article5.txt\n",
    "  - vars:\n",
    "      article: file://articles/article6.txt\n",
    "  - vars:\n",
    "      article: file://articles/article7.txt\n",
    "  - vars:\n",
    "      article: file://articles/article8.txt\n",
    "\n",
    "defaultTest:\n",
    "  assert:\n",
    "    - type: python\n",
    "      value: file://custom_llm_eval.py\n",
    "\n",
    "```\n",
    "\n",
    "We're telling promptfoo that we want to use each of the three prompts we defined in `prompts.py`.  Next, we configure promptfoo to use Claude 3.5 Sonnet as the provider.\n",
    "\n",
    "We're writing a series of `tests` where we provide a different value for `article` in each test.  The one thing that is new here is that we're loading the values from a text file.  The articles are so long, it didn't make sense to put them inline in the YAML file.  For example, this bit of the configuration file: \n",
    "\n",
    "```yaml\n",
    "tests:\n",
    "  - vars:\n",
    "      article: file://articles/article1.txt\n",
    "```\n",
    "\n",
    "tells promptfoo we want to run a test where the `article` variable is set to the text contents of the `article1.txt` file.  We repeat this process for all of the eight article files.\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Writing the custom model-grader function\n",
    "\n",
    "Next, lets turn our attention to the very last field in the YAML file:\n",
    "\n",
    "```yaml\n",
    "defaultTest:\n",
    "  assert:\n",
    "    - type: python\n",
    "      value: file://custom_llm_eval.py\n",
    "```\n",
    "\n",
    "This field tells promptfoo that for every single test, we want to run a particular python assertion we've defined in the file `custom_llm_eval.py`.  We've seen this syntax before when defining a custom code-graded assertion.  The only difference is that this time we're going to write a function that grades a model's output using another model.\n",
    "\n",
    "Let's take a look at the contents of the `custom_llm_eval.py` file.  It contains quite a bit of code:\n",
    "\n",
    "```py\n",
    "import anthropic\n",
    "import os\n",
    "import json\n",
    "\n",
    "def llm_eval(summary, article):\n",
    "    client = anthropic.Anthropic(api_key=os.getenv(\"ANTHROPIC_API_KEY\"))\n",
    "\n",
    "    prompt = f\"\"\"Evaluate the following summary based on these criteria:\n",
    "    1. Conciseness (1-5) - is the summary as concise as possible?\n",
    "        - Conciseness of 1: The summary is unnecessarily long, including excessive details, repetitions, or irrelevant information. It fails to distill the key points effectively.\n",
    "        - Conciseness of 3:  The summary captures most key points but could be more focused. It may include some unnecessary details or slightly over explain certain concepts.\n",
    "        - Conciseness of 5: The summary effectively condenses the main ideas into a brief, focused text. It includes all essential information without any superfluous details or explanations.\n",
    "    2. Accuracy (1-5) - is the summary completely accurate based on the initial article'?\n",
    "        - Accuracy of 1: The summary contains significant errors, misrepresentations, or omissions that fundamentally alter the meaning or key points of the original article.\n",
    "        - Accuracy of 3:  The summary captures some key points correctly but may have minor inaccuracies or omissions. The overall message is generally correct, but some details may be wrong.\n",
    "        - Accuracy of 5: The summary faithfully represents the main gist of the original article without any errors or misinterpretations. All included information is correct and aligns with the source material.\n",
    "    3. Tone (1-5) - is the summary appropriate for a grade school student with no technical training?\n",
    "        - Tone of 1: The summary uses language or concepts that are too complex, technical, or mature for a grade school audience. It may contain jargon, advanced terminology, or themes that are not suitable for young readers.\n",
    "        - Tone of 2:  The summary mostly uses language suitable for grade school students but occasionally includes terms or concepts that may be challenging. Some explanations might be needed for full comprehension.\n",
    "        - Tone of 3: The summary consistently uses simple, clear language that is easily understandable by grade school students. It explains complex ideas in a way that is accessible and engaging for young readers.\n",
    "    4. Explanation - a general description of the way the summary is evaluated\n",
    "\n",
    "    <examples>\n",
    "    <example>\n",
    "    This summary:\n",
    "    <summary>\n",
    "    Artificial neural networks are computer systems inspired by how the human brain works. They are made up of interconnected \"neurons\" that process information. These networks can learn to do tasks by looking at lots of examples, similar to how humans learn. \n",
    "\n",
    "    Some key things about neural networks:\n",
    "    - They can recognize patterns and make predictions\n",
    "    - They improve with more data and practice\n",
    "    - They're used for things like identifying objects in images, translating languages, and playing games\n",
    "\n",
    "    Neural networks are a powerful tool in artificial intelligence and are behind many of the \"smart\" technologies we use today. While they can do amazing things, they still aren't as complex or capable as the human brain.\n",
    "    <summary>\n",
    "    Should receive a 5 for tone, a 5 for accuracy, and a 5 for conciseness\n",
    "    </example>\n",
    "\n",
    "    <example>\n",
    "    This summary:\n",
    "    <summary>\n",
    "    Here is a summary of the key points from the article on artificial neural networks (ANNs):\n",
    "\n",
    "    1. ANNs are computational models inspired by biological neural networks in animal brains. They consist of interconnected artificial neurons that process and transmit signals.\n",
    "\n",
    "    2. Basic structure:\n",
    "    - Input layer receives data\n",
    "    - Hidden layers process information \n",
    "    - Output layer produces results\n",
    "    - Neurons are connected by weighted edges\n",
    "\n",
    "    3. Learning process:\n",
    "    - ANNs learn by adjusting connection weights\n",
    "    - Use techniques like backpropagation to minimize errors\n",
    "    - Can perform supervised, unsupervised, and reinforcement learning\n",
    "\n",
    "    4. Key developments:\n",
    "    - Convolutional neural networks (CNNs) for image processing\n",
    "    - Recurrent neural networks (RNNs) for sequential data\n",
    "    - Deep learning with many hidden layers\n",
    "\n",
    "    5. Applications:\n",
    "    - Pattern recognition, classification, regression\n",
    "    - Computer vision, speech recognition, natural language processing\n",
    "    - Game playing, robotics, financial modeling\n",
    "\n",
    "    6. Advantages:\n",
    "    - Can model complex non-linear relationships\n",
    "    - Ability to learn and generalize from data\n",
    "    - Adaptable to many different types of problems\n",
    "\n",
    "    7. Challenges:\n",
    "    - Require large amounts of training data\n",
    "    - Can be computationally intensive\n",
    "    - \"Black box\" nature can make interpretability difficult\n",
    "\n",
    "    8. Recent advances:\n",
    "    - Improved hardware (GPUs) enabling deeper networks\n",
    "    - New architectures like transformers for language tasks\n",
    "    - Progress in areas like generative AI\n",
    "\n",
    "    The article provides a comprehensive overview of ANN concepts, history, types, applications, and ongoing research areas in this field of artificial intelligence and machine learning.\n",
    "    </summary>\n",
    "    Should receive a 1 for tone, a 5 for accuracy, and a 3 for conciseness\n",
    "    </example>\n",
    "    </examples>\n",
    "\n",
    "    Provide a score for each criterion in JSON format. Here is the format you should follow always:\n",
    "\n",
    "    <json>\n",
    "    {{\n",
    "    \"conciseness\": <number>,\n",
    "    \"accuracy\": <number>,\n",
    "    \"tone\": <number>,\n",
    "    \"explanation\": <string>,\n",
    "    }}\n",
    "    </json>\n",
    "\n",
    "\n",
    "    Original Text: <original_article>{article}</original_article>\n",
    "    \n",
    "    Summary to Evaluate: <summary>{summary}</summary>\n",
    "    \"\"\"\n",
    "    \n",
    "    response = client.messages.create(\n",
    "        model=\"claude-3-5-sonnet-20240620\",\n",
    "        max_tokens=1000,\n",
    "        temperature=0,\n",
    "        messages=[\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\": prompt\n",
    "            },\n",
    "            {\n",
    "                \"role\": \"assistant\",\n",
    "                \"content\": \"<json>\" \n",
    "            }\n",
    "        ],\n",
    "        stop_sequences=[\"</json>\"]\n",
    "    )\n",
    "    \n",
    "    evaluation = json.loads(response.content[0].text)\n",
    "    # Filter out non-numeric values and calculate the average\n",
    "    numeric_values = [value for key, value in evaluation.items() if isinstance(value, (int, float))]\n",
    "    avg_score = sum(numeric_values) / len(numeric_values)\n",
    "    return avg_score, response.content[0].text\n",
    "\n",
    "def get_assert(output: str, context, threshold=4.5):\n",
    "    article = context['vars']['article']\n",
    "    score, evaluation = llm_eval(output, article )\n",
    "    return {\n",
    "        \"pass\": score >= threshold,\n",
    "        \"score\": score,\n",
    "        \"reason\": evaluation\n",
    "    }\n",
    "\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### `get_assert()`\n",
    "\n",
    "There's a lot to discuss here, but let's begin with the function at the bottom of the file: `get_assert`\n",
    "\n",
    "```py\n",
    "def get_assert(output: str, context, threshold=4.5):\n",
    "    article = context['vars']['article']\n",
    "    score, evaluation = llm_eval(output, article )\n",
    "    return {\n",
    "        \"pass\": score >= threshold,\n",
    "        \"score\": score,\n",
    "        \"reason\": evaluation\n",
    "    }\n",
    "```\n",
    "\n",
    "Recall from our earlier lesson that promptfoo automatically looks for a function called `get_assert` in an assertion file.  It will pass the function the following two arguments:\n",
    "\n",
    "- The `output` from a given model response\n",
    "- The `context` dictionary that includes the variables and prompt that generated the output\n",
    "\n",
    "Promptfoo expects our function to return one of the following:\n",
    "- a bool (pass/fail)\n",
    "- a float (score)\n",
    "- a GradingResult dictionary\n",
    "\n",
    "We've opted to return a GradingResult dictionary, which must include the following properties:\n",
    "\n",
    "- `pass`: boolean\n",
    "- `score`: float\n",
    "- `reason`: a string explanation\n",
    "\n",
    "Here's a commented version of the function that explains what's happening:\n",
    "\n",
    "```py\n",
    "def get_assert(output: str, context, threshold=4.5):\n",
    "    # Get the specific article from the context\n",
    "    article = context['vars']['article']\n",
    "    #Pass the model output and the article to a function we've defined called llm_eval\n",
    "    score, evaluation = llm_eval(output, article ) #capture the resulting score it returns and the evaluation explanation\n",
    "    #return a dictionary indicating whether the output passed the test, its score, and the explanation behind the score\n",
    "    return {\n",
    "        \"pass\": score >= threshold,\n",
    "        \"score\": score,\n",
    "        \"reason\": evaluation\n",
    "    }\n",
    "```\n",
    "\n",
    "### `llm_eval()`\n",
    "Next, let's take a closer look at the `llm_eval` function that is doing the actual grading. The function does the following:\n",
    "\n",
    "1. Defines a very long grading rubric prompt that explains how summaries should be scored\n",
    "2. Runs the grading prompt by sending a request to the Anthropic API \n",
    "3. Parses the response and calculates an average score \n",
    "4. Returns the average score and the model's full text response\n",
    "\n",
    "Here's the code in its entirety:\n",
    "\n",
    "```py\n",
    "def llm_eval(summary, article):\n",
    "    \"\"\"\n",
    "    Evaluate summary using an LLM (Claude).\n",
    "    \n",
    "    Args:\n",
    "    summary (str): The summary to evaluate.\n",
    "    article (str): The original text that was summarized.\n",
    "    \n",
    "    Returns:\n",
    "    bool: True if the average score is above the threshold, False otherwise.\n",
    "    \"\"\"\n",
    "    client = anthropic.Anthropic(api_key=os.getenv(\"ANTHROPIC_API_KEY\"))\n",
    "\n",
    "    prompt = f\"\"\"Evaluate the following summary based on these criteria:\n",
    "    1. Conciseness (1-5) - is the summary as concise as possible?\n",
    "        - Conciseness of 1: The summary is unnecessarily long, including excessive details, repetitions, or irrelevant information. It fails to distill the key points effectively.\n",
    "        - Conciseness of 3:  The summary captures most key points but could be more focused. It may include some unnecessary details or slightly overexplain certain concepts.\n",
    "        - Conciseness of 5: The summary effectively condenses the main ideas into a brief, focused text. It includes all essential information without any superfluous details or explanations.\n",
    "    2. Accuracy (1-5) - is the summary completely accurate based on the initial article'?\n",
    "        - Accuracy of 1: The summary contains significant errors, misrepresentations, or omissions that fundamentally alter the meaning or key points of the original article.\n",
    "        - Accuracy of 3:  The summary captures some key points correctly but may have minor inaccuracies or omissions. The overall message is generally correct, but some details may be wrong.\n",
    "        - Accuracy of 5: The summary faithfully represents the main gist of the original article without any errors or misinterpretations. All included information is correct and aligns with the source material.\n",
    "    4. Tone (1-5) - is the summary appropriate for a grade school student with no technical training?\n",
    "        - Tone of 1: The summary uses language or concepts that are too complex, technical, or mature for a grade school audience. It may contain jargon, advanced terminology, or themes that are not suitable for young readers.\n",
    "        - Tone of 2:  The summary mostly uses language suitable for grade school students but occasionally includes terms or concepts that may be challenging. Some explanations might be needed for full comprehension.\n",
    "        - Tone of 3: The summary consistently uses simple, clear language that is easily understandable by grade school students. It explains complex ideas in a way that is accessible and engaging for young readers.\n",
    "    5. Explanation - a general description of the way the summary is evaluated\n",
    "\n",
    "    <examples>\n",
    "    <example>\n",
    "    This summary:\n",
    "    <summary>\n",
    "    Artificial neural networks are computer systems inspired by how the human brain works. They are made up of interconnected \"neurons\" that process information. These networks can learn to do tasks by looking at lots of examples, similar to how humans learn. \n",
    "\n",
    "    Some key things about neural networks:\n",
    "    - They can recognize patterns and make predictions\n",
    "    - They improve with more data and practice\n",
    "    - They're used for things like identifying objects in images, translating languages, and playing games\n",
    "\n",
    "    Neural networks are a powerful tool in artificial intelligence and are behind many of the \"smart\" technologies we use today. While they can do amazing things, they still aren't as complex or capable as the human brain.\n",
    "    <summary>\n",
    "    Should receive a 5 for tone, a 5 for accuracy, and a 5 for conciseness\n",
    "    </example>\n",
    "\n",
    "    <example>\n",
    "    This summary:\n",
    "    <summary>\n",
    "    Here is a summary of the key points from the article on artificial neural networks (ANNs):\n",
    "\n",
    "    1. ANNs are computational models inspired by biological neural networks in animal brains. They consist of interconnected artificial neurons that process and transmit signals.\n",
    "\n",
    "    2. Basic structure:\n",
    "    - Input layer receives data\n",
    "    - Hidden layers process information \n",
    "    - Output layer produces results\n",
    "    - Neurons are connected by weighted edges\n",
    "\n",
    "    3. Learning process:\n",
    "    - ANNs learn by adjusting connection weights\n",
    "    - Use techniques like backpropagation to minimize errors\n",
    "    - Can perform supervised, unsupervised, and reinforcement learning\n",
    "\n",
    "    4. Key developments:\n",
    "    - Convolutional neural networks (CNNs) for image processing\n",
    "    - Recurrent neural networks (RNNs) for sequential data\n",
    "    - Deep learning with many hidden layers\n",
    "\n",
    "    5. Applications:\n",
    "    - Pattern recognition, classification, regression\n",
    "    - Computer vision, speech recognition, natural language processing\n",
    "    - Game playing, robotics, financial modeling\n",
    "\n",
    "    6. Advantages:\n",
    "    - Can model complex non-linear relationships\n",
    "    - Ability to learn and generalize from data\n",
    "    - Adaptable to many different types of problems\n",
    "\n",
    "    7. Challenges:\n",
    "    - Require large amounts of training data\n",
    "    - Can be computationally intensive\n",
    "    - \"Black box\" nature can make interpretability difficult\n",
    "\n",
    "    8. Recent advances:\n",
    "    - Improved hardware (GPUs) enabling deeper networks\n",
    "    - New architectures like transformers for language tasks\n",
    "    - Progress in areas like generative AI\n",
    "\n",
    "    The article provides a comprehensive overview of ANN concepts, history, types, applications, and ongoing research areas in this field of artificial intelligence and machine learning.\n",
    "    </summary>\n",
    "    Should receive a 1 for tone, a 5 for accuracy, and a 3 for conciseness\n",
    "    </example>\n",
    "    </examples>\n",
    "\n",
    "    Provide a score for each criterion in JSON format. Here is the format you should follow always:\n",
    "\n",
    "    <json>\n",
    "    {{\n",
    "    \"conciseness\": <number>,\n",
    "    \"accuracy\": <number>,\n",
    "    \"tone\": <number>,\n",
    "    \"explanation\": <string>,\n",
    "    }}\n",
    "    </json>\n",
    "\n",
    "\n",
    "    Original Text: <original_article>{article}</original_article>\n",
    "    \n",
    "    Summary to Evaluate: <summary>{summary}</summary>\n",
    "    \"\"\"\n",
    "    \n",
    "    response = client.messages.create(\n",
    "        model=\"claude-3-5-sonnet-20240620\",\n",
    "        max_tokens=1000,\n",
    "        temperature=0,\n",
    "        messages=[\n",
    "            {\n",
    "                \"role\": \"user\",\n",
    "                \"content\": prompt\n",
    "            },\n",
    "            {\n",
    "                \"role\": \"assistant\",\n",
    "                \"content\": \"<json>\" \n",
    "            }\n",
    "        ],\n",
    "        stop_sequences=[\"</json>\"]\n",
    "    )\n",
    "    \n",
    "    evaluation = json.loads(response.content[0].text)\n",
    "    # Filter out non-numeric values and calculate the average\n",
    "    numeric_values = [value for key, value in evaluation.items() if isinstance(value, (int, float))]\n",
    "    avg_score = sum(numeric_values) / len(numeric_values)\n",
    "    # Return the average score and the overall model response\n",
    "    return avg_score, response.content[0].text\n",
    "```\n",
    "\n",
    "---"
   ]
  },
  {
   "attachments": {
    "eval_result.png": {
     "image/png": "[encoded data, 964076 characters]"
    },
    "web_view.png": {
     "image/png": "[encoded data, 973060 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Running the eval\n",
    "\n",
    "We use the same command we've seen before to run the evaluation: \n",
    "\n",
    "```bash\n",
    "npx promptfoo@latest eval\n",
    "```\n",
    "This process can take a little while to complete because we're making the initial requests to the model to generate the article summaries and then sending additional requests to grade those summaries!\n",
    "\n",
    "This is a screenshot of the evaluation result we got:\n",
    "\n",
    "![eval_result.png](attachment:eval_result.png)\n",
    "\n",
    "Let's launch the web view to get a better understanding of the results:\n",
    "\n",
    "```bash\n",
    "npx promptfoo@latest view\n",
    "```\n",
    "This is a screenshot of the web dashboard: \n",
    "\n",
    "![web_view.png](attachment:web_view.png)"
   ]
  },
  {
   "attachments": {
    "explanation.png": {
     "image/png": "[encoded data, 142396 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can click on the magnifying glass in each cell to view more information on the test results:\n",
    "\n",
    "![explanation.png](attachment:explanation.png)\n",
    "\n",
    "We can see that this particular output failed our custom llm-eval function because its tone score is so low."
   ]
  },
  {
   "attachments": {
    "overall_scores.png": {
     "image/png": "[encoded data, 79628 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Additionally, the top row of the results shows a summary of the grades for each prompt: \n",
    "\n",
    "![overall_scores.png](attachment:overall_scores.png)\n",
    "\n",
    "Our `best_summary` prompt is, unsurprisingly, performing the best!"
   ]
  },
  {
   "attachments": {
    "distribution.png": {
     "image/png": "[encoded data, 77552 characters]"
    }
   },
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The top of the dashboard also displays some charts to help visualize scores:\n",
    "\n",
    "![distribution.png](attachment:distribution.png)\n",
    "\n",
    "In the above screenshot:\n",
    "\n",
    "* the red is our `basic_summarize` prompt\n",
    "* the blue is our `better_summarize` prompt\n",
    "* the green is our `best_summarize` prompt\n",
    "\n",
    "The chart shows us that not only is the `best_summarize` prompt never failing our test, it outscores the other prompts on all inputs."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
