{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
trace_idstart_timeend_timestatusinputoutput
0717ef090-359f-41c4-84b3-08bec62511852024-06-25 14:02:53.0677072024-06-25 14:02:54.842210success{'messages': [{'lc': 1, 'type': 'constructor',...{'llm_output': {'model_name': 'llama3-70b-8192...
197f1d6b5-17fa-4ebe-8438-2eabb33e6c122024-06-25 14:02:53.0649112024-06-25 14:02:53.066843success{'context': [{'page_content': 'December 31, 20...{'output': {'messages': [{'content': '<|begin_...
278165b64-3961-4b28-8d66-ca17763ff7df2024-06-25 14:02:53.0634692024-06-25 14:02:53.066525success{'context': [{'page_content': 'December 31, 20...{'output': [{'page_content': 'December 31, 202...
36ba40755-4a55-4d8c-a824-7e8f855444cc2024-06-25 14:02:53.0628072024-06-25 14:02:54.844401success{'context': [{'page_content': 'December 31, 20...{'output': {'content': '[BEGIN_SUMMARY]\n", "The to...
43bcafa07-7bdd-48e0-a55a-47b3f8ee32c72024-06-25 14:02:53.0607092024-06-25 14:02:54.845145success{'context': [{'page_content': 'December 31, 20...{'response': {'content': '[BEGIN_SUMMARY]\n", "The ...
.....................
5551013e849-793d-46da-aeea-2a8c3eaa08d42024-06-20 19:35:54.4923142024-06-20 19:35:54.498540success{'question': 'What is Airbnb's 'Description of...{'output': 'What is Airbnb's 'Description of B...
55688e7c281-436f-4cfd-9056-5e6954d2462c2024-06-20 19:35:54.4915792024-06-20 19:35:54.498051success{'question': 'What is Airbnb's 'Description of...{'output': 'What is Airbnb's 'Description of B...
5577ea55086-6ed9-4930-8ba4-0df7a406c8b82024-06-20 19:35:54.4907442024-06-20 19:35:55.556579success{'question': 'What is Airbnb's 'Description of...{'output': [{'page_content': 'Table of Content...
558288e39cf-71e6-4574-bf48-8f902ec7a12f2024-06-20 19:35:54.4890312024-06-20 19:35:55.557354success{'question': 'What is Airbnb's 'Description of...{'context': [{'page_content': 'Table of Conten...
559073e10ba-0a34-4338-9ff0-a7c00584e6bb2024-06-20 19:35:54.4410222024-06-20 19:35:56.962382success{'question': 'What is Airbnb's 'Description of...{'response': {'content': 'Airbnb's 'Descriptio...
\n", "

560 rows × 6 columns

\n", "
" ], "text/plain": [ " trace_id start_time \\\n", "0 717ef090-359f-41c4-84b3-08bec6251185 2024-06-25 14:02:53.067707 \n", "1 97f1d6b5-17fa-4ebe-8438-2eabb33e6c12 2024-06-25 14:02:53.064911 \n", "2 78165b64-3961-4b28-8d66-ca17763ff7df 2024-06-25 14:02:53.063469 \n", "3 6ba40755-4a55-4d8c-a824-7e8f855444cc 2024-06-25 14:02:53.062807 \n", "4 3bcafa07-7bdd-48e0-a55a-47b3f8ee32c7 2024-06-25 14:02:53.060709 \n", ".. ... ... \n", "555 1013e849-793d-46da-aeea-2a8c3eaa08d4 2024-06-20 19:35:54.492314 \n", "556 88e7c281-436f-4cfd-9056-5e6954d2462c 2024-06-20 19:35:54.491579 \n", "557 7ea55086-6ed9-4930-8ba4-0df7a406c8b8 2024-06-20 19:35:54.490744 \n", "558 288e39cf-71e6-4574-bf48-8f902ec7a12f 2024-06-20 19:35:54.489031 \n", "559 073e10ba-0a34-4338-9ff0-a7c00584e6bb 2024-06-20 19:35:54.441022 \n", "\n", " end_time status \\\n", "0 2024-06-25 14:02:54.842210 success \n", "1 2024-06-25 14:02:53.066843 success \n", "2 2024-06-25 14:02:53.066525 success \n", "3 2024-06-25 14:02:54.844401 success \n", "4 2024-06-25 14:02:54.845145 success \n", ".. ... ... \n", "555 2024-06-20 19:35:54.498540 success \n", "556 2024-06-20 19:35:54.498051 success \n", "557 2024-06-20 19:35:55.556579 success \n", "558 2024-06-20 19:35:55.557354 success \n", "559 2024-06-20 19:35:56.962382 success \n", "\n", " input \\\n", "0 {'messages': [{'lc': 1, 'type': 'constructor',... \n", "1 {'context': [{'page_content': 'December 31, 20... \n", "2 {'context': [{'page_content': 'December 31, 20... \n", "3 {'context': [{'page_content': 'December 31, 20... \n", "4 {'context': [{'page_content': 'December 31, 20... \n", ".. ... \n", "555 {'question': 'What is Airbnb's 'Description of... \n", "556 {'question': 'What is Airbnb's 'Description of... \n", "557 {'question': 'What is Airbnb's 'Description of... \n", "558 {'question': 'What is Airbnb's 'Description of... \n", "559 {'question': 'What is Airbnb's 'Description of... \n", "\n", " output \n", "0 {'llm_output': {'model_name': 'llama3-70b-8192... \n", "1 {'output': {'messages': [{'content': '<|begin_... \n", "2 {'output': [{'page_content': 'December 31, 202... \n", "3 {'output': {'content': '[BEGIN_SUMMARY]\n", "The to... \n", "4 {'response': {'content': '[BEGIN_SUMMARY]\n", "The ... \n", ".. ... \n", "555 {'output': 'What is Airbnb's 'Description of B... \n", "556 {'output': 'What is Airbnb's 'Description of B... \n", "557 {'output': [{'page_content': 'Table of Content... \n", "558 {'context': [{'page_content': 'Table of Conten... \n", "559 {'response': {'content': 'Airbnb's 'Descriptio... \n", "\n", "[560 rows x 6 columns]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Save to CSV or display DataFrame\n", "df.to_csv('trace_runs.csv', index=False)\n", "display(df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.8" } }, "nbformat": 4, "nbformat_minor": 2 }