Google Colab
colab.research.google.com
- Upload a dataset of examples containing emails to Phoenix
- Define an experiment task that extracts and formats the key details from those emails
- Devise an evaluator measuring Jaro-Winkler Similarity
- Run experiments to iterate on your prompt template and to compare the summaries produced by different LLMs
Notebook Walkthrough
We will go through key code snippets on this page. To follow the full tutorial, check out the Colab notebook above.Instrument LangChain and OpenAI
First, we need to set up our instrumentors to capture traces from the agent. Since our task runs through LangChain but the evaluation function calls OpenAI directly, we’ll enable both the Langchain and OpenAI auto-instrumentors.Experiments in Phoenix
Experiments in Phoenix are made up of 3 elements: a dataset, a task, and an evaluator. The dataset is a collection of the inputs and expected outputs that we’ll use to evaluate. The task is an operation that should be performed on each input. Finally, the evaluator compares the result against an expected output. For this example, here’s what each looks like:- Dataset: a dataframe of emails to analyze, and the expected output for our agent
- Task: a Langchain agent that extracts key info from our input emails. The result of this task will then be compared against the expected output
- Evaluator: Jaro-Winkler distance calculation on the task’s output and expected output
Dataset
We’ve prepared some example emails and actual responses that we can use to evaluate our two models. Let’s download those and save them to a temporary file. Then, we will upload the dataset to Phoenix.
Create LangChain Agent and Define Task Function
Now we’ll set up our Langchain agent. This is a straightforward agent that makes a call to our specified model and formats the response as JSON.Run Experiment
Evaluate Experiment
Finally, we need to define our evaluation function. Here we’ll use a Jaro-Winkler similarity function that generates a score for how similar the output and expected text are. Jaro-Winkler similarity is technique for measuring edit distance between two strings.Re-run with GPT 3.5 Turbo and Compare Results
Now we have scores on how well GPT-4o does at extracting email facts. This is helpful, but doesn’t mean much on its own. Let’s compare it against another model. To compare results with another model, we simply need to redefine our task. Our dataset and evaluator can stay the same.View Results
Now if you check your Phoenix experiment, you can compare Jaro-Winkler scores on a per query basis, and view aggregate model performance results. The experiment comparison screenshot below shows results from GPT-4o on the left and GPT-3.5-turbo on the far right. The higher the jarowinkler_similarity score, the closer the outputted value is to the actual value. You should see that GPT-4o outperforms its older cousin. From here you could try out different models or iterate on your prompt, then run the same experiment with a modified Task to compare results.


