arize-phoenix 4.10.2rc0__py3-none-any.whl → 4.10.2rc2__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.10.2rc0.dist-info → arize_phoenix-4.10.2rc2.dist-info}/METADATA +4 -3
- {arize_phoenix-4.10.2rc0.dist-info → arize_phoenix-4.10.2rc2.dist-info}/RECORD +27 -35
- 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 +389 -507
- phoenix/server/api/routers/v1/evaluations.py +73 -66
- phoenix/server/api/routers/v1/experiment_evaluations.py +67 -91
- phoenix/server/api/routers/v1/experiment_runs.py +97 -155
- phoenix/server/api/routers/v1/experiments.py +131 -181
- phoenix/server/api/routers/v1/spans.py +143 -173
- phoenix/server/api/routers/v1/traces.py +114 -128
- phoenix/server/api/routers/v1/utils.py +94 -0
- phoenix/server/api/types/Span.py +0 -1
- phoenix/server/app.py +148 -192
- phoenix/server/main.py +0 -3
- phoenix/server/static/index.css +6 -0
- phoenix/server/static/index.js +8547 -0
- phoenix/server/templates/index.html +25 -76
- phoenix/server/thread_server.py +2 -2
- phoenix/trace/schemas.py +0 -1
- phoenix/version.py +1 -1
- phoenix/server/openapi/docs.py +0 -221
- phoenix/server/static/.vite/manifest.json +0 -78
- phoenix/server/static/assets/components-C8sm_r1F.js +0 -1142
- phoenix/server/static/assets/index-BEKPzgQs.js +0 -100
- phoenix/server/static/assets/pages-bN7juCjh.js +0 -2885
- phoenix/server/static/assets/vendor-CUDAPm8e.js +0 -641
- phoenix/server/static/assets/vendor-DxkFTwjz.css +0 -1
- phoenix/server/static/assets/vendor-arizeai-Do2HOmcL.js +0 -662
- phoenix/server/static/assets/vendor-codemirror-CrdxOlMs.js +0 -12
- phoenix/server/static/assets/vendor-recharts-PKRvByVe.js +0 -59
- phoenix/server/static/assets/vendor-three-DwGkEfCM.js +0 -2998
- {arize_phoenix-4.10.2rc0.dist-info → arize_phoenix-4.10.2rc2.dist-info}/WHEEL +0 -0
- {arize_phoenix-4.10.2rc0.dist-info → arize_phoenix-4.10.2rc2.dist-info}/licenses/IP_NOTICE +0 -0
- {arize_phoenix-4.10.2rc0.dist-info → arize_phoenix-4.10.2rc2.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import gzip
|
|
2
2
|
import zlib
|
|
3
|
-
from typing import Any, Dict, List
|
|
3
|
+
from typing import Any, Dict, List, Literal, Optional
|
|
4
4
|
|
|
5
|
+
from fastapi import APIRouter, BackgroundTasks, Header, HTTPException
|
|
5
6
|
from google.protobuf.message import DecodeError
|
|
6
7
|
from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import (
|
|
7
8
|
ExportTraceServiceRequest,
|
|
8
9
|
)
|
|
10
|
+
from pydantic import BaseModel, Field
|
|
9
11
|
from sqlalchemy import select
|
|
10
|
-
from starlette.background import BackgroundTask
|
|
11
12
|
from starlette.concurrency import run_in_threadpool
|
|
12
13
|
from starlette.datastructures import State
|
|
13
14
|
from starlette.requests import Request
|
|
14
|
-
from starlette.responses import JSONResponse, Response
|
|
15
15
|
from starlette.status import (
|
|
16
|
+
HTTP_204_NO_CONTENT,
|
|
16
17
|
HTTP_404_NOT_FOUND,
|
|
17
18
|
HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
|
18
19
|
HTTP_422_UNPROCESSABLE_ENTITY,
|
|
@@ -26,40 +27,50 @@ from phoenix.server.api.types.node import from_global_id_with_expected_type
|
|
|
26
27
|
from phoenix.trace.otel import decode_otlp_span
|
|
27
28
|
from phoenix.utilities.project import get_project_name
|
|
28
29
|
|
|
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
|
-
|
|
30
|
+
from .utils import RequestBody, ResponseBody, add_errors_to_responses
|
|
31
|
+
|
|
32
|
+
router = APIRouter(tags=["traces"], include_in_schema=False)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@router.post(
|
|
36
|
+
"/traces",
|
|
37
|
+
operation_id="addTraces",
|
|
38
|
+
summary="Send traces",
|
|
39
|
+
status_code=HTTP_204_NO_CONTENT,
|
|
40
|
+
responses=add_errors_to_responses(
|
|
41
|
+
[
|
|
42
|
+
{
|
|
43
|
+
"status_code": HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
|
44
|
+
"description": (
|
|
45
|
+
"Unsupported content type (only `application/x-protobuf` is supported)"
|
|
46
|
+
),
|
|
47
|
+
},
|
|
48
|
+
{"status_code": HTTP_422_UNPROCESSABLE_ENTITY, "description": "Invalid request body"},
|
|
49
|
+
]
|
|
50
|
+
),
|
|
51
|
+
openapi_extra={
|
|
52
|
+
"requestBody": {
|
|
53
|
+
"required": True,
|
|
54
|
+
"content": {
|
|
55
|
+
"application/x-protobuf": {"schema": {"type": "string", "format": "binary"}}
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
async def post_traces(
|
|
61
|
+
request: Request,
|
|
62
|
+
background_tasks: BackgroundTasks,
|
|
63
|
+
content_type: Optional[str] = Header(default=None),
|
|
64
|
+
content_encoding: Optional[str] = Header(default=None),
|
|
65
|
+
) -> None:
|
|
54
66
|
if content_type != "application/x-protobuf":
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
raise HTTPException(
|
|
68
|
+
detail=f"Unsupported content type: {content_type}",
|
|
57
69
|
status_code=HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
|
58
70
|
)
|
|
59
|
-
content_encoding = request.headers.get("content-encoding")
|
|
60
71
|
if content_encoding and content_encoding not in ("gzip", "deflate"):
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
raise HTTPException(
|
|
73
|
+
detail=f"Unsupported content encoding: {content_encoding}",
|
|
63
74
|
status_code=HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
|
64
75
|
)
|
|
65
76
|
body = await request.body()
|
|
@@ -71,96 +82,69 @@ async def post_traces(request: Request) -> Response:
|
|
|
71
82
|
try:
|
|
72
83
|
await run_in_threadpool(req.ParseFromString, body)
|
|
73
84
|
except DecodeError:
|
|
74
|
-
|
|
75
|
-
|
|
85
|
+
raise HTTPException(
|
|
86
|
+
detail="Request body is invalid ExportTraceServiceRequest",
|
|
76
87
|
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
|
|
77
88
|
)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
additionalProperties:
|
|
130
|
-
type: string
|
|
131
|
-
required:
|
|
132
|
-
- trace_id
|
|
133
|
-
- name
|
|
134
|
-
- annotator_kind
|
|
135
|
-
responses:
|
|
136
|
-
200:
|
|
137
|
-
description: Trace annotations inserted successfully
|
|
138
|
-
content:
|
|
139
|
-
application/json:
|
|
140
|
-
schema:
|
|
141
|
-
type: object
|
|
142
|
-
properties:
|
|
143
|
-
data:
|
|
144
|
-
type: array
|
|
145
|
-
items:
|
|
146
|
-
type: object
|
|
147
|
-
properties:
|
|
148
|
-
id:
|
|
149
|
-
type: string
|
|
150
|
-
description: The ID of the inserted trace annotation
|
|
151
|
-
404:
|
|
152
|
-
description: Trace not found
|
|
153
|
-
"""
|
|
154
|
-
payload: List[Dict[str, Any]] = (await request.json()).get("data", [])
|
|
155
|
-
trace_gids = [GlobalID.from_id(annotation["trace_id"]) for annotation in payload]
|
|
89
|
+
background_tasks.add_task(_add_spans, req, request.state)
|
|
90
|
+
return None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class TraceAnnotationResult(BaseModel):
|
|
94
|
+
label: Optional[str] = Field(default=None, description="The label assigned by the annotation")
|
|
95
|
+
score: Optional[float] = Field(default=None, description="The score assigned by the annotation")
|
|
96
|
+
explanation: Optional[str] = Field(
|
|
97
|
+
default=None, description="Explanation of the annotation result"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class TraceAnnotation(BaseModel):
|
|
102
|
+
trace_id: str = Field(description="The ID of the trace being annotated")
|
|
103
|
+
name: str = Field(description="The name of the annotation")
|
|
104
|
+
annotator_kind: Literal["LLM", "HUMAN"] = Field(
|
|
105
|
+
description="The kind of annotator used for the annotation"
|
|
106
|
+
)
|
|
107
|
+
result: Optional[TraceAnnotationResult] = Field(
|
|
108
|
+
default=None, description="The result of the annotation"
|
|
109
|
+
)
|
|
110
|
+
metadata: Optional[Dict[str, Any]] = Field(
|
|
111
|
+
default=None, description="Metadata for the annotation"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class AnnotateTracesRequestBody(RequestBody[List[TraceAnnotation]]):
|
|
116
|
+
data: List[TraceAnnotation] = Field(description="The trace annotations to be upserted")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class InsertedTraceAnnotation(BaseModel):
|
|
120
|
+
id: str = Field(description="The ID of the inserted trace annotation")
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class AnnotateTracesResponseBody(ResponseBody[List[InsertedTraceAnnotation]]):
|
|
124
|
+
pass
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@router.post(
|
|
128
|
+
"/trace_annotations",
|
|
129
|
+
operation_id="annotateTraces",
|
|
130
|
+
summary="Create or update trace annotations",
|
|
131
|
+
responses=add_errors_to_responses(
|
|
132
|
+
[{"status_code": HTTP_404_NOT_FOUND, "description": "Trace not found"}]
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
async def annotate_traces(
|
|
136
|
+
request: Request, request_body: AnnotateTracesRequestBody
|
|
137
|
+
) -> AnnotateTracesResponseBody:
|
|
138
|
+
trace_annotations = request_body.data
|
|
139
|
+
trace_gids = [GlobalID.from_id(annotation.trace_id) for annotation in trace_annotations]
|
|
156
140
|
|
|
157
141
|
resolved_trace_ids = []
|
|
158
142
|
for trace_gid in trace_gids:
|
|
159
143
|
try:
|
|
160
144
|
resolved_trace_ids.append(from_global_id_with_expected_type(trace_gid, "Trace"))
|
|
161
145
|
except ValueError:
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
raise HTTPException(
|
|
147
|
+
detail="Trace with ID {trace_gid} does not exist",
|
|
164
148
|
status_code=HTTP_404_NOT_FOUND,
|
|
165
149
|
)
|
|
166
150
|
|
|
@@ -175,24 +159,24 @@ async def annotate_traces(request: Request) -> Response:
|
|
|
175
159
|
missing_trace_gids = [
|
|
176
160
|
str(GlobalID("Trace", str(trace_gid))) for trace_gid in missing_trace_ids
|
|
177
161
|
]
|
|
178
|
-
|
|
179
|
-
|
|
162
|
+
raise HTTPException(
|
|
163
|
+
detail=f"Traces with IDs {', '.join(missing_trace_gids)} do not exist.",
|
|
180
164
|
status_code=HTTP_404_NOT_FOUND,
|
|
181
165
|
)
|
|
182
166
|
|
|
183
167
|
inserted_annotations = []
|
|
184
168
|
|
|
185
|
-
for annotation in
|
|
186
|
-
trace_gid = GlobalID.from_id(annotation
|
|
169
|
+
for annotation in trace_annotations:
|
|
170
|
+
trace_gid = GlobalID.from_id(annotation.trace_id)
|
|
187
171
|
trace_id = from_global_id_with_expected_type(trace_gid, "Trace")
|
|
188
172
|
|
|
189
|
-
name = annotation
|
|
190
|
-
annotator_kind = annotation
|
|
191
|
-
result = annotation.
|
|
192
|
-
label = result.
|
|
193
|
-
score = result.
|
|
194
|
-
explanation = result.
|
|
195
|
-
metadata = annotation.
|
|
173
|
+
name = annotation.name
|
|
174
|
+
annotator_kind = annotation.annotator_kind
|
|
175
|
+
result = annotation.result
|
|
176
|
+
label = result.label if result else None
|
|
177
|
+
score = result.score if result else None
|
|
178
|
+
explanation = result.explanation if result else None
|
|
179
|
+
metadata = annotation.metadata or {}
|
|
196
180
|
|
|
197
181
|
values = dict(
|
|
198
182
|
trace_rowid=trace_id,
|
|
@@ -213,10 +197,12 @@ async def annotate_traces(request: Request) -> Response:
|
|
|
213
197
|
).returning(models.TraceAnnotation.id)
|
|
214
198
|
)
|
|
215
199
|
inserted_annotations.append(
|
|
216
|
-
|
|
200
|
+
InsertedTraceAnnotation(
|
|
201
|
+
id=str(GlobalID("TraceAnnotation", str(trace_annotation_id)))
|
|
202
|
+
)
|
|
217
203
|
)
|
|
218
204
|
|
|
219
|
-
return
|
|
205
|
+
return AnnotateTracesResponseBody(data=inserted_annotations)
|
|
220
206
|
|
|
221
207
|
|
|
222
208
|
async def _add_spans(req: ExportTraceServiceRequest, state: State) -> None:
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from typing import Any, Dict, Generic, List, Optional, TypedDict, Union
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
from typing_extensions import TypeAlias, TypeVar, assert_never
|
|
5
|
+
|
|
6
|
+
StatusCode: TypeAlias = int
|
|
7
|
+
DataType = TypeVar("DataType")
|
|
8
|
+
Responses: TypeAlias = Dict[
|
|
9
|
+
Union[int, str], Dict[str, Any]
|
|
10
|
+
] # input type for the `responses` parameter of a fastapi route
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class StatusCodeWithDescription(TypedDict):
|
|
14
|
+
"""
|
|
15
|
+
A duck type for a status code with a description detailing under what
|
|
16
|
+
conditions the status code is raised.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
status_code: StatusCode
|
|
20
|
+
description: str
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class RequestBody(BaseModel, Generic[DataType]):
|
|
24
|
+
# A generic request type accepted by V1 routes.
|
|
25
|
+
#
|
|
26
|
+
# Don't use """ for this docstring or it will be included as a description
|
|
27
|
+
# in the generated OpenAPI schema.
|
|
28
|
+
data: DataType
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ResponseBody(BaseModel, Generic[DataType]):
|
|
32
|
+
# A generic response type returned by V1 routes.
|
|
33
|
+
#
|
|
34
|
+
# Don't use """ for this docstring or it will be included as a description
|
|
35
|
+
# in the generated OpenAPI schema.
|
|
36
|
+
|
|
37
|
+
data: DataType
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PaginatedResponseBody(BaseModel, Generic[DataType]):
|
|
41
|
+
# A generic paginated response type returned by V1 routes.
|
|
42
|
+
#
|
|
43
|
+
# Don't use """ for this docstring or it will be included as a description
|
|
44
|
+
# in the generated OpenAPI schema.
|
|
45
|
+
|
|
46
|
+
data: List[DataType]
|
|
47
|
+
next_cursor: Optional[str]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def add_errors_to_responses(
|
|
51
|
+
errors: List[Union[StatusCode, StatusCodeWithDescription]],
|
|
52
|
+
/,
|
|
53
|
+
*,
|
|
54
|
+
responses: Optional[Responses] = None,
|
|
55
|
+
) -> Responses:
|
|
56
|
+
"""
|
|
57
|
+
Creates or updates a patch for an OpenAPI schema's `responses` section to
|
|
58
|
+
include status codes in the generated OpenAPI schema.
|
|
59
|
+
"""
|
|
60
|
+
output_responses: Responses = responses or {}
|
|
61
|
+
for error in errors:
|
|
62
|
+
status_code: int
|
|
63
|
+
description: Optional[str] = None
|
|
64
|
+
if isinstance(error, StatusCode):
|
|
65
|
+
status_code = error
|
|
66
|
+
elif isinstance(error, dict):
|
|
67
|
+
status_code = error["status_code"]
|
|
68
|
+
description = error["description"]
|
|
69
|
+
else:
|
|
70
|
+
assert_never(error)
|
|
71
|
+
if status_code not in output_responses:
|
|
72
|
+
output_responses[status_code] = {
|
|
73
|
+
"content": {"text/plain": {"schema": {"type": "string"}}}
|
|
74
|
+
}
|
|
75
|
+
if description:
|
|
76
|
+
output_responses[status_code]["description"] = description
|
|
77
|
+
return output_responses
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def add_text_csv_content_to_responses(
|
|
81
|
+
status_code: StatusCode, /, *, responses: Optional[Responses] = None
|
|
82
|
+
) -> Responses:
|
|
83
|
+
"""
|
|
84
|
+
Creates or updates a patch for an OpenAPI schema's `responses` section to
|
|
85
|
+
ensure that the response for the given status code is marked as text/csv in
|
|
86
|
+
the generated OpenAPI schema.
|
|
87
|
+
"""
|
|
88
|
+
output_responses: Responses = responses or {}
|
|
89
|
+
if status_code not in output_responses:
|
|
90
|
+
output_responses[status_code] = {}
|
|
91
|
+
output_responses[status_code]["content"] = {
|
|
92
|
+
"text/csv": {"schema": {"type": "string", "contentMediaType": "text/csv"}}
|
|
93
|
+
}
|
|
94
|
+
return output_responses
|