-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert graphql api to pull trace evaluations from db (#2867)
makes graphql api pull trace evaluations from db
- Loading branch information
1 parent
73ca2d7
commit 11aa455
Showing
8 changed files
with
76 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from .document_evaluations import DocumentEvaluationsDataLoader | ||
from .latency_ms_quantile import LatencyMsQuantileDataLoader | ||
from .span_evaluations import SpanEvaluationsDataLoader | ||
from .trace_evaluations import TraceEvaluationsDataLoader | ||
|
||
__all__ = [ | ||
"DocumentEvaluationsDataLoader", | ||
"LatencyMsQuantileDataLoader", | ||
"SpanEvaluationsDataLoader", | ||
"TraceEvaluationsDataLoader", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from collections import defaultdict | ||
from typing import ( | ||
AsyncContextManager, | ||
Callable, | ||
DefaultDict, | ||
List, | ||
) | ||
|
||
from sqlalchemy import and_, select | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from strawberry.dataloader import DataLoader | ||
from typing_extensions import TypeAlias | ||
|
||
from phoenix.db import models | ||
from phoenix.server.api.types.Evaluation import TraceEvaluation | ||
|
||
Key: TypeAlias = int | ||
|
||
|
||
class TraceEvaluationsDataLoader(DataLoader[Key, List[TraceEvaluation]]): | ||
def __init__(self, db: Callable[[], AsyncContextManager[AsyncSession]]) -> None: | ||
super().__init__(load_fn=self._load_fn) | ||
self._db = db | ||
|
||
async def _load_fn(self, keys: List[Key]) -> List[List[TraceEvaluation]]: | ||
trace_evaluations_by_id: DefaultDict[Key, List[TraceEvaluation]] = defaultdict(list) | ||
async with self._db() as session: | ||
for trace_evaluation in await session.scalars( | ||
select(models.TraceAnnotation).where( | ||
and_( | ||
models.TraceAnnotation.trace_rowid.in_(keys), | ||
models.TraceAnnotation.annotator_kind == "LLM", | ||
) | ||
) | ||
): | ||
trace_evaluations_by_id[trace_evaluation.trace_rowid].append( | ||
TraceEvaluation.from_sql_trace_annotation(trace_evaluation) | ||
) | ||
return [trace_evaluations_by_id[key] for key in keys] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters