{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Capture LangSmith data in a Pandas DataFrame" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "from langsmith import Client" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Initialize the client\n", "client = Client(\n", " api_key=os.getenv(\"LANGCHAIN_API_KEY\"),\n", " api_url=os.getenv(\"LANGCHAIN_ENDPOINT\")\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Retrieve trace runs\n", "project_name = \"AirBnB RAG Evaluation\"\n", "traces = client.list_runs(project_name=project_name)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Convert trace data to DataFrame\n", "trace_data = []\n", "\n", "for trace in traces:\n", " trace_data.append({\n", " 'trace_id': trace.id,\n", " 'start_time': trace.start_time,\n", " 'end_time': trace.end_time,\n", " 'status': trace.status,\n", " 'input': trace.inputs,\n", " 'output': trace.outputs\n", " })" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(trace_data)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | trace_id | \n", "start_time | \n", "end_time | \n", "status | \n", "input | \n", "output | \n", "
---|---|---|---|---|---|---|
0 | \n", "717ef090-359f-41c4-84b3-08bec6251185 | \n", "2024-06-25 14:02:53.067707 | \n", "2024-06-25 14:02:54.842210 | \n", "success | \n", "{'messages': [{'lc': 1, 'type': 'constructor',... | \n", "{'llm_output': {'model_name': 'llama3-70b-8192... | \n", "
1 | \n", "97f1d6b5-17fa-4ebe-8438-2eabb33e6c12 | \n", "2024-06-25 14:02:53.064911 | \n", "2024-06-25 14:02:53.066843 | \n", "success | \n", "{'context': [{'page_content': 'December 31, 20... | \n", "{'output': {'messages': [{'content': '<|begin_... | \n", "
2 | \n", "78165b64-3961-4b28-8d66-ca17763ff7df | \n", "2024-06-25 14:02:53.063469 | \n", "2024-06-25 14:02:53.066525 | \n", "success | \n", "{'context': [{'page_content': 'December 31, 20... | \n", "{'output': [{'page_content': 'December 31, 202... | \n", "
3 | \n", "6ba40755-4a55-4d8c-a824-7e8f855444cc | \n", "2024-06-25 14:02:53.062807 | \n", "2024-06-25 14:02:54.844401 | \n", "success | \n", "{'context': [{'page_content': 'December 31, 20... | \n", "{'output': {'content': '[BEGIN_SUMMARY]\n", "The to... | \n", "
4 | \n", "3bcafa07-7bdd-48e0-a55a-47b3f8ee32c7 | \n", "2024-06-25 14:02:53.060709 | \n", "2024-06-25 14:02:54.845145 | \n", "success | \n", "{'context': [{'page_content': 'December 31, 20... | \n", "{'response': {'content': '[BEGIN_SUMMARY]\n", "The ... | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
555 | \n", "1013e849-793d-46da-aeea-2a8c3eaa08d4 | \n", "2024-06-20 19:35:54.492314 | \n", "2024-06-20 19:35:54.498540 | \n", "success | \n", "{'question': 'What is Airbnb's 'Description of... | \n", "{'output': 'What is Airbnb's 'Description of B... | \n", "
556 | \n", "88e7c281-436f-4cfd-9056-5e6954d2462c | \n", "2024-06-20 19:35:54.491579 | \n", "2024-06-20 19:35:54.498051 | \n", "success | \n", "{'question': 'What is Airbnb's 'Description of... | \n", "{'output': 'What is Airbnb's 'Description of B... | \n", "
557 | \n", "7ea55086-6ed9-4930-8ba4-0df7a406c8b8 | \n", "2024-06-20 19:35:54.490744 | \n", "2024-06-20 19:35:55.556579 | \n", "success | \n", "{'question': 'What is Airbnb's 'Description of... | \n", "{'output': [{'page_content': 'Table of Content... | \n", "
558 | \n", "288e39cf-71e6-4574-bf48-8f902ec7a12f | \n", "2024-06-20 19:35:54.489031 | \n", "2024-06-20 19:35:55.557354 | \n", "success | \n", "{'question': 'What is Airbnb's 'Description of... | \n", "{'context': [{'page_content': 'Table of Conten... | \n", "
559 | \n", "073e10ba-0a34-4338-9ff0-a7c00584e6bb | \n", "2024-06-20 19:35:54.441022 | \n", "2024-06-20 19:35:56.962382 | \n", "success | \n", "{'question': 'What is Airbnb's 'Description of... | \n", "{'response': {'content': 'Airbnb's 'Descriptio... | \n", "
560 rows × 6 columns
\n", "