{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

\n", " \"phoenix\n", "
\n", " Docs\n", " |\n", " GitHub\n", " |\n", " Community\n", "

\n", "
\n", "

Logging traces to Phoenix

\n", "\n", "In this tutorial we will learn how to launch Phoenix and upload traces using the client.\n", "\n", "As of Phoenix version `3.22.0`, the client has a `log_traces` method that allows you to upload a `TraceDataset` directly." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, let's download an example `TraceDataset`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from urllib.request import urlopen\n", "\n", "from phoenix.trace.trace_dataset import TraceDataset\n", "from phoenix.trace.utils import json_lines_to_df\n", "\n", "traces_url = \"https://storage.googleapis.com/arize-phoenix-assets/datasets/unstructured/llm/context-retrieval/trace.jsonl\"\n", "with urlopen(traces_url) as response:\n", " lines = [line.decode(\"utf-8\") for line in response.readlines()]\n", "trace_ds = TraceDataset(json_lines_to_df(lines))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Launch Phoenix. You can open use Phoenix within your notebook or in a separate browser window by opening the URL." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import phoenix as px\n", "\n", "(session := px.launch_app()).view()\n", "session_url = session.url" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a client and use `log_traces` to upload the `TraceDataset`. We can optionally add these traces to a specific project." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "client = px.Client(endpoint=session_url)\n", "client.log_traces(trace_ds, project_name=\"old-traces\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You should now see a view like this.\n", "\n", "![A view of the Phoenix UI prior to adding evaluation annotations](https://storage.googleapis.com/arize-phoenix-assets/assets/docs/notebooks/evals/traces_without_evaluation_annotations.png)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }