Skip to content

Commit

Permalink
fix: span and trace evaluation summaries (#3013)
Browse files Browse the repository at this point in the history
  • Loading branch information
axiomofjoy committed Apr 26, 2024
1 parent c8e85fc commit 088e6c2
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/phoenix/server/api/types/Project.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from datetime import datetime
from typing import List, Optional
from typing import List, Optional, cast

import numpy as np
import strawberry
from openinference.semconv.trace import SpanAttributes
from sqlalchemy import and_, distinct, func, select
from sqlalchemy import ScalarResult, and_, distinct, func, select
from sqlalchemy.orm import contains_eager, selectinload
from sqlalchemy.sql.functions import coalesce
from strawberry import ID, UNSET
Expand Down Expand Up @@ -283,13 +283,17 @@ async def trace_evaluation_summary(
# todo: implement filter condition
async with info.context.db() as session:
evaluations = list(await session.scalars(filtered))
all_labels = await session.scalars(
unfiltered.with_only_columns(distinct(models.TraceAnnotation.label))
if not evaluations:
return None
labels = cast(
ScalarResult[str],
await session.scalars(
unfiltered.with_only_columns(distinct(models.TraceAnnotation.label)).where(
models.TraceAnnotation.label.is_not(None)
)
),
)
labels = [label for label in all_labels if label is not None]
if not evaluations or labels:
return None
return EvaluationSummary(evaluations, labels)
return EvaluationSummary(evaluations, list(labels))

@strawberry.field
async def span_evaluation_summary(
Expand Down Expand Up @@ -320,13 +324,17 @@ async def span_evaluation_summary(
# todo: implement filter condition
async with info.context.db() as session:
evaluations = list(await session.scalars(filtered))
all_labels = await session.scalars(
unfiltered.with_only_columns(distinct(models.SpanAnnotation.label))
if not evaluations:
return None
labels = cast(
ScalarResult[str],
await session.scalars(
unfiltered.with_only_columns(distinct(models.SpanAnnotation.label)).where(
models.SpanAnnotation.label.is_not(None)
)
),
)
labels = [label for label in all_labels if label is not None]
if not evaluations or labels:
return None
return EvaluationSummary(evaluations, labels)
return EvaluationSummary(evaluations, list(labels))

@strawberry.field
async def document_evaluation_summary(
Expand Down

0 comments on commit 088e6c2

Please sign in to comment.