arize-phoenix 4.12.0__py3-none-any.whl → 4.12.1rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of arize-phoenix might be problematic. Click here for more details.
- {arize_phoenix-4.12.0.dist-info → arize_phoenix-4.12.1rc1.dist-info}/METADATA +4 -3
- {arize_phoenix-4.12.0.dist-info → arize_phoenix-4.12.1rc1.dist-info}/RECORD +36 -27
- phoenix/server/api/context.py +3 -7
- phoenix/server/api/openapi/main.py +18 -2
- phoenix/server/api/openapi/schema.py +12 -12
- phoenix/server/api/routers/v1/__init__.py +36 -83
- phoenix/server/api/routers/v1/dataset_examples.py +102 -123
- phoenix/server/api/routers/v1/datasets.py +390 -506
- phoenix/server/api/routers/v1/evaluations.py +73 -66
- phoenix/server/api/routers/v1/experiment_evaluations.py +68 -91
- phoenix/server/api/routers/v1/experiment_runs.py +98 -155
- phoenix/server/api/routers/v1/experiments.py +132 -181
- phoenix/server/api/routers/v1/pydantic_compat.py +78 -0
- phoenix/server/api/routers/v1/spans.py +144 -173
- phoenix/server/api/routers/v1/traces.py +115 -128
- phoenix/server/api/routers/v1/utils.py +95 -0
- phoenix/server/api/types/Project.py +33 -0
- phoenix/server/app.py +172 -176
- phoenix/server/main.py +3 -0
- phoenix/server/static/.vite/manifest.json +78 -0
- phoenix/server/static/assets/components-C8sm_r1F.js +1142 -0
- phoenix/server/static/assets/index-BEKPzgQs.js +100 -0
- phoenix/server/static/assets/pages-bN7juCjh.js +2885 -0
- phoenix/server/static/assets/vendor-CUDAPm8e.js +641 -0
- phoenix/server/static/assets/vendor-DxkFTwjz.css +1 -0
- phoenix/server/static/assets/vendor-arizeai-Do2HOmcL.js +662 -0
- phoenix/server/static/assets/vendor-codemirror-CrdxOlMs.js +12 -0
- phoenix/server/static/assets/vendor-recharts-PKRvByVe.js +59 -0
- phoenix/server/static/assets/vendor-three-DwGkEfCM.js +2998 -0
- phoenix/server/templates/index.html +83 -24
- phoenix/server/thread_server.py +2 -2
- phoenix/session/client.py +3 -2
- phoenix/version.py +1 -1
- phoenix/server/openapi/docs.py +0 -221
- phoenix/server/static/index.css +0 -6
- phoenix/server/static/index.js +0 -8548
- {arize_phoenix-4.12.0.dist-info → arize_phoenix-4.12.1rc1.dist-info}/WHEEL +0 -0
- {arize_phoenix-4.12.0.dist-info → arize_phoenix-4.12.1rc1.dist-info}/licenses/IP_NOTICE +0 -0
- {arize_phoenix-4.12.0.dist-info → arize_phoenix-4.12.1rc1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,178 +1,157 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any, Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
from fastapi import APIRouter, HTTPException, Path, Query
|
|
1
5
|
from sqlalchemy import and_, func, select
|
|
2
6
|
from starlette.requests import Request
|
|
3
|
-
from starlette.responses import JSONResponse, Response
|
|
4
7
|
from starlette.status import HTTP_404_NOT_FOUND
|
|
5
8
|
from strawberry.relay import GlobalID
|
|
6
9
|
|
|
7
|
-
from phoenix.db.models import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
required:
|
|
67
|
-
- id
|
|
68
|
-
- input
|
|
69
|
-
- output
|
|
70
|
-
- metadata
|
|
71
|
-
- updated_at
|
|
72
|
-
required:
|
|
73
|
-
- dataset_id
|
|
74
|
-
- version_id
|
|
75
|
-
- examples
|
|
76
|
-
403:
|
|
77
|
-
description: Forbidden
|
|
78
|
-
404:
|
|
79
|
-
description: Dataset does not exist.
|
|
80
|
-
"""
|
|
81
|
-
dataset_id = GlobalID.from_id(request.path_params["id"])
|
|
82
|
-
raw_version_id = request.query_params.get("version_id")
|
|
83
|
-
version_id = GlobalID.from_id(raw_version_id) if raw_version_id else None
|
|
84
|
-
|
|
85
|
-
if (dataset_type := dataset_id.type_name) != "Dataset":
|
|
86
|
-
return Response(
|
|
87
|
-
content=f"ID {dataset_id} refers to a {dataset_type}", status_code=HTTP_404_NOT_FOUND
|
|
10
|
+
from phoenix.db.models import (
|
|
11
|
+
Dataset as ORMDataset,
|
|
12
|
+
)
|
|
13
|
+
from phoenix.db.models import (
|
|
14
|
+
DatasetExample as ORMDatasetExample,
|
|
15
|
+
)
|
|
16
|
+
from phoenix.db.models import (
|
|
17
|
+
DatasetExampleRevision as ORMDatasetExampleRevision,
|
|
18
|
+
)
|
|
19
|
+
from phoenix.db.models import (
|
|
20
|
+
DatasetVersion as ORMDatasetVersion,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from .pydantic_compat import V1RoutesBaseModel
|
|
24
|
+
from .utils import ResponseBody, add_errors_to_responses
|
|
25
|
+
|
|
26
|
+
router = APIRouter(tags=["datasets"])
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DatasetExample(V1RoutesBaseModel):
|
|
30
|
+
id: str
|
|
31
|
+
input: Dict[str, Any]
|
|
32
|
+
output: Dict[str, Any]
|
|
33
|
+
metadata: Dict[str, Any]
|
|
34
|
+
updated_at: datetime
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ListDatasetExamplesData(V1RoutesBaseModel):
|
|
38
|
+
dataset_id: str
|
|
39
|
+
version_id: str
|
|
40
|
+
examples: List[DatasetExample]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class ListDatasetExamplesResponseBody(ResponseBody[ListDatasetExamplesData]):
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@router.get(
|
|
48
|
+
"/datasets/{id}/examples",
|
|
49
|
+
operation_id="getDatasetExamples",
|
|
50
|
+
summary="Get examples from a dataset",
|
|
51
|
+
responses=add_errors_to_responses([HTTP_404_NOT_FOUND]),
|
|
52
|
+
)
|
|
53
|
+
async def get_dataset_examples(
|
|
54
|
+
request: Request,
|
|
55
|
+
id: str = Path(description="The ID of the dataset"),
|
|
56
|
+
version_id: Optional[str] = Query(
|
|
57
|
+
default=None,
|
|
58
|
+
description=(
|
|
59
|
+
"The ID of the dataset version " "(if omitted, returns data from the latest version)"
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
) -> ListDatasetExamplesResponseBody:
|
|
63
|
+
dataset_gid = GlobalID.from_id(id)
|
|
64
|
+
version_gid = GlobalID.from_id(version_id) if version_id else None
|
|
65
|
+
|
|
66
|
+
if (dataset_type := dataset_gid.type_name) != "Dataset":
|
|
67
|
+
raise HTTPException(
|
|
68
|
+
detail=f"ID {dataset_gid} refers to a {dataset_type}", status_code=HTTP_404_NOT_FOUND
|
|
88
69
|
)
|
|
89
70
|
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
if version_gid and (version_type := version_gid.type_name) != "DatasetVersion":
|
|
72
|
+
raise HTTPException(
|
|
73
|
+
detail=f"ID {version_gid} refers to a {version_type}", status_code=HTTP_404_NOT_FOUND
|
|
93
74
|
)
|
|
94
75
|
|
|
95
76
|
async with request.app.state.db() as session:
|
|
96
77
|
if (
|
|
97
78
|
resolved_dataset_id := await session.scalar(
|
|
98
|
-
select(
|
|
79
|
+
select(ORMDataset.id).where(ORMDataset.id == int(dataset_gid.node_id))
|
|
99
80
|
)
|
|
100
81
|
) is None:
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
raise HTTPException(
|
|
83
|
+
detail=f"No dataset with id {dataset_gid} can be found.",
|
|
103
84
|
status_code=HTTP_404_NOT_FOUND,
|
|
104
85
|
)
|
|
105
86
|
|
|
106
87
|
# Subquery to find the maximum created_at for each dataset_example_id
|
|
107
88
|
# timestamp tiebreaks are resolved by the largest id
|
|
108
89
|
partial_subquery = select(
|
|
109
|
-
func.max(
|
|
110
|
-
).group_by(
|
|
90
|
+
func.max(ORMDatasetExampleRevision.id).label("max_id"),
|
|
91
|
+
).group_by(ORMDatasetExampleRevision.dataset_example_id)
|
|
111
92
|
|
|
112
|
-
if
|
|
93
|
+
if version_gid:
|
|
113
94
|
if (
|
|
114
95
|
resolved_version_id := await session.scalar(
|
|
115
|
-
select(
|
|
96
|
+
select(ORMDatasetVersion.id).where(
|
|
116
97
|
and_(
|
|
117
|
-
|
|
118
|
-
|
|
98
|
+
ORMDatasetVersion.dataset_id == resolved_dataset_id,
|
|
99
|
+
ORMDatasetVersion.id == int(version_gid.node_id),
|
|
119
100
|
)
|
|
120
101
|
)
|
|
121
102
|
)
|
|
122
103
|
) is None:
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
raise HTTPException(
|
|
105
|
+
detail=f"No dataset version with id {version_id} can be found.",
|
|
125
106
|
status_code=HTTP_404_NOT_FOUND,
|
|
126
107
|
)
|
|
127
108
|
# if a version_id is provided, filter the subquery to only include revisions from that
|
|
128
109
|
partial_subquery = partial_subquery.filter(
|
|
129
|
-
|
|
110
|
+
ORMDatasetExampleRevision.dataset_version_id <= resolved_version_id
|
|
130
111
|
)
|
|
131
112
|
else:
|
|
132
113
|
if (
|
|
133
114
|
resolved_version_id := await session.scalar(
|
|
134
|
-
select(func.max(
|
|
135
|
-
|
|
115
|
+
select(func.max(ORMDatasetVersion.id)).where(
|
|
116
|
+
ORMDatasetVersion.dataset_id == resolved_dataset_id
|
|
136
117
|
)
|
|
137
118
|
)
|
|
138
119
|
) is None:
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
raise HTTPException(
|
|
121
|
+
detail="Dataset has no versions.",
|
|
141
122
|
status_code=HTTP_404_NOT_FOUND,
|
|
142
123
|
)
|
|
143
124
|
|
|
144
125
|
subquery = partial_subquery.subquery()
|
|
145
126
|
# Query for the most recent example revisions that are not deleted
|
|
146
127
|
query = (
|
|
147
|
-
select(
|
|
128
|
+
select(ORMDatasetExample, ORMDatasetExampleRevision)
|
|
148
129
|
.join(
|
|
149
|
-
|
|
150
|
-
|
|
130
|
+
ORMDatasetExampleRevision,
|
|
131
|
+
ORMDatasetExample.id == ORMDatasetExampleRevision.dataset_example_id,
|
|
151
132
|
)
|
|
152
133
|
.join(
|
|
153
134
|
subquery,
|
|
154
|
-
(subquery.c.max_id ==
|
|
135
|
+
(subquery.c.max_id == ORMDatasetExampleRevision.id),
|
|
155
136
|
)
|
|
156
|
-
.filter(
|
|
157
|
-
.filter(
|
|
158
|
-
.order_by(
|
|
137
|
+
.filter(ORMDatasetExample.dataset_id == resolved_dataset_id)
|
|
138
|
+
.filter(ORMDatasetExampleRevision.revision_kind != "DELETE")
|
|
139
|
+
.order_by(ORMDatasetExample.id.asc())
|
|
159
140
|
)
|
|
160
141
|
examples = [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
142
|
+
DatasetExample(
|
|
143
|
+
id=str(GlobalID("DatasetExample", str(example.id))),
|
|
144
|
+
input=revision.input,
|
|
145
|
+
output=revision.output,
|
|
146
|
+
metadata=revision.metadata_,
|
|
147
|
+
updated_at=revision.created_at,
|
|
148
|
+
)
|
|
168
149
|
async for example, revision in await session.stream(query)
|
|
169
150
|
]
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
"
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}
|
|
151
|
+
return ListDatasetExamplesResponseBody(
|
|
152
|
+
data=ListDatasetExamplesData(
|
|
153
|
+
dataset_id=str(GlobalID("Dataset", str(resolved_dataset_id))),
|
|
154
|
+
version_id=str(GlobalID("DatasetVersion", str(resolved_version_id))),
|
|
155
|
+
examples=examples,
|
|
156
|
+
)
|
|
178
157
|
)
|