Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(wren-ai-service): update langfuse analysis notebook #836

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions wren-ai-service/eval/dashboard/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import os\n",
"from datetime import datetime, timedelta\n",
"from typing import Optional\n",
"\n",
"from dotenv import load_dotenv\n",
Expand All @@ -33,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -47,16 +48,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"def get_all_traces(client: Langfuse, name: Optional[str]=None):\n",
"def get_all_traces(client: Langfuse, name: Optional[str]=None, from_timestamp: Optional[datetime]=None, to_timestamp: Optional[datetime]=None):\n",
" traces = []\n",
" page = 1\n",
"\n",
" while True:\n",
" data = client.fetch_traces(name=name, page=page).data\n",
" data = client.fetch_traces(name=name, page=page, from_timestamp=from_timestamp, to_timestamp=to_timestamp).data\n",
" if len(data) == 0:\n",
" break\n",
" traces += data\n",
Expand All @@ -67,16 +68,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"def get_all_observations(client: Langfuse, name: Optional[str]=None):\n",
"def get_all_observations(client: Langfuse, name: Optional[str]=None, from_timestamp: Optional[datetime]=None, to_timestamp: Optional[datetime]=None):\n",
" observations = []\n",
" page = 1\n",
"\n",
" while True:\n",
" data = client.fetch_observations(name=name, page=page).data\n",
" data = client.fetch_observations(name=name, page=page, from_start_time=from_timestamp, to_start_time=to_timestamp).data\n",
" if len(data) == 0:\n",
" break\n",
" observations += data\n",
Expand All @@ -87,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -97,7 +98,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -115,7 +116,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -132,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -180,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -271,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -290,7 +291,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -317,7 +318,7 @@
" \"metadata\": {\n",
" },\n",
" \"name\": \"Prepare Semantics\",\n",
" \"release\": RELEASE,\n",
" # \"release\": RELEASE,\n",
"}\n",
"error_results, no_error_results = get_traces_by_conditions(traces, conditions)"
]
Expand Down Expand Up @@ -371,13 +372,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"def get_dry_run_failed_cases(client):\n",
"def get_dry_run_failed_cases(client, from_timestamp = None, to_timestamp = None):\n",
" results = []\n",
" for data in get_all_observations(client, name=\"post_process\"):\n",
" for data in get_all_observations(client, name=\"post_process\", from_timestamp=from_timestamp, to_timestamp=to_timestamp):\n",
" if invalid_generation_results := data.output.get('invalid_generation_results', []):\n",
" for result in invalid_generation_results:\n",
" result['trace_id'] = data.trace_id\n",
Expand All @@ -396,7 +397,7 @@
" \"metadata\": {\n",
" },\n",
" \"name\": \"Ask Question\",\n",
" \"release\": RELEASE,\n",
" # \"release\": RELEASE,\n",
"}\n",
"error_results, no_error_results = get_traces_by_conditions(traces, conditions)"
]
Expand Down Expand Up @@ -436,7 +437,7 @@
"metadata": {},
"outputs": [],
"source": [
"dry_run_failed_cases = get_dry_run_failed_cases(client)\n",
"dry_run_failed_cases = get_dry_run_failed_cases(client, from_timestamp=datetime.now() - timedelta(days=14))\n",
"len(dry_run_failed_cases)"
]
},
Expand Down
Loading