-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add containedInDataset boolean field to gql Spans (#4015)
* Add containedInDataset boolean field to gql Spans * Improve names and resolve missing type annotations * Build gql
- Loading branch information
1 parent
0587462
commit 3c096ca
Showing
7 changed files
with
157 additions
and
0 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
38 changes: 38 additions & 0 deletions
38
src/phoenix/server/api/dataloaders/span_dataset_examples.py
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,38 @@ | ||
from typing import ( | ||
AsyncContextManager, | ||
Callable, | ||
Dict, | ||
List, | ||
) | ||
|
||
from sqlalchemy import select | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
from strawberry.dataloader import DataLoader | ||
from typing_extensions import TypeAlias | ||
|
||
from phoenix.db import models | ||
|
||
SpanID: TypeAlias = int | ||
Key: TypeAlias = SpanID | ||
Result: TypeAlias = List[models.DatasetExample] | ||
|
||
|
||
class SpanDatasetExamplesDataLoader(DataLoader[Key, Result]): | ||
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[Result]: | ||
span_rowids = keys | ||
async with self._db() as session: | ||
dataset_examples: Dict[Key, List[models.DatasetExample]] = { | ||
span_rowid: [] for span_rowid in span_rowids | ||
} | ||
async for span_rowid, dataset_example in await session.stream( | ||
select(models.Span.id, models.DatasetExample) | ||
.select_from(models.Span) | ||
.join(models.DatasetExample, models.DatasetExample.span_rowid == models.Span.id) | ||
.where(models.Span.id.in_(span_rowids)) | ||
): | ||
dataset_examples[span_rowid].append(dataset_example) | ||
return [dataset_examples.get(span_rowid, []) for span_rowid in span_rowids] |
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