arize-phoenix 4.10.2rc1__py3-none-any.whl → 4.11.0__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.2rc1.dist-info → arize_phoenix-4.11.0.dist-info}/METADATA +3 -4
- {arize_phoenix-4.10.2rc1.dist-info → arize_phoenix-4.11.0.dist-info}/RECORD +26 -26
- phoenix/server/api/context.py +7 -3
- phoenix/server/api/openapi/main.py +2 -18
- phoenix/server/api/openapi/schema.py +12 -12
- phoenix/server/api/routers/v1/__init__.py +83 -36
- phoenix/server/api/routers/v1/dataset_examples.py +123 -102
- phoenix/server/api/routers/v1/datasets.py +507 -389
- phoenix/server/api/routers/v1/evaluations.py +64 -74
- phoenix/server/api/routers/v1/experiment_evaluations.py +91 -67
- phoenix/server/api/routers/v1/experiment_runs.py +155 -97
- phoenix/server/api/routers/v1/experiments.py +181 -131
- phoenix/server/api/routers/v1/spans.py +173 -141
- phoenix/server/api/routers/v1/traces.py +128 -113
- phoenix/server/api/types/Span.py +1 -0
- phoenix/server/app.py +176 -148
- phoenix/server/openapi/docs.py +221 -0
- phoenix/server/static/index.js +574 -573
- phoenix/server/thread_server.py +2 -2
- phoenix/trace/attributes.py +2 -1
- phoenix/trace/schemas.py +1 -0
- phoenix/trace/span_json_decoder.py +1 -1
- phoenix/version.py +1 -1
- phoenix/server/api/routers/v1/utils.py +0 -94
- {arize_phoenix-4.10.2rc1.dist-info → arize_phoenix-4.11.0.dist-info}/WHEEL +0 -0
- {arize_phoenix-4.10.2rc1.dist-info → arize_phoenix-4.11.0.dist-info}/licenses/IP_NOTICE +0 -0
- {arize_phoenix-4.10.2rc1.dist-info → arize_phoenix-4.11.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import gzip
|
|
2
2
|
from itertools import chain
|
|
3
|
-
from typing import AsyncContextManager, Callable, Iterator,
|
|
3
|
+
from typing import AsyncContextManager, Callable, Iterator, Tuple
|
|
4
4
|
|
|
5
5
|
import pandas as pd
|
|
6
6
|
import pyarrow as pa
|
|
7
|
-
from fastapi import APIRouter, Header, HTTPException, Query
|
|
8
7
|
from google.protobuf.message import DecodeError
|
|
9
8
|
from pandas import DataFrame
|
|
10
9
|
from sqlalchemy import select
|
|
@@ -17,7 +16,6 @@ from starlette.datastructures import State
|
|
|
17
16
|
from starlette.requests import Request
|
|
18
17
|
from starlette.responses import Response, StreamingResponse
|
|
19
18
|
from starlette.status import (
|
|
20
|
-
HTTP_204_NO_CONTENT,
|
|
21
19
|
HTTP_403_FORBIDDEN,
|
|
22
20
|
HTTP_404_NOT_FOUND,
|
|
23
21
|
HTTP_415_UNSUPPORTED_MEDIA_TYPE,
|
|
@@ -38,94 +36,86 @@ from phoenix.trace.span_evaluations import (
|
|
|
38
36
|
TraceEvaluations,
|
|
39
37
|
)
|
|
40
38
|
|
|
41
|
-
from .utils import add_errors_to_responses
|
|
42
|
-
|
|
43
39
|
EvaluationName: TypeAlias = str
|
|
44
40
|
|
|
45
|
-
router = APIRouter(tags=["traces"], include_in_schema=False)
|
|
46
|
-
|
|
47
41
|
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
async def post_evaluations(
|
|
76
|
-
request: Request,
|
|
77
|
-
content_type: Optional[str] = Header(default=None),
|
|
78
|
-
content_encoding: Optional[str] = Header(default=None),
|
|
79
|
-
) -> Response:
|
|
42
|
+
async def post_evaluations(request: Request) -> Response:
|
|
43
|
+
"""
|
|
44
|
+
summary: Add evaluations to a span, trace, or document
|
|
45
|
+
operationId: addEvaluations
|
|
46
|
+
tags:
|
|
47
|
+
- private
|
|
48
|
+
requestBody:
|
|
49
|
+
required: true
|
|
50
|
+
content:
|
|
51
|
+
application/x-protobuf:
|
|
52
|
+
schema:
|
|
53
|
+
type: string
|
|
54
|
+
format: binary
|
|
55
|
+
application/x-pandas-arrow:
|
|
56
|
+
schema:
|
|
57
|
+
type: string
|
|
58
|
+
format: binary
|
|
59
|
+
responses:
|
|
60
|
+
200:
|
|
61
|
+
description: Success
|
|
62
|
+
403:
|
|
63
|
+
description: Forbidden
|
|
64
|
+
415:
|
|
65
|
+
description: Unsupported content type, only gzipped protobuf and pandas-arrow are supported
|
|
66
|
+
422:
|
|
67
|
+
description: Request body is invalid
|
|
68
|
+
"""
|
|
80
69
|
if request.app.state.read_only:
|
|
81
|
-
|
|
70
|
+
return Response(status_code=HTTP_403_FORBIDDEN)
|
|
71
|
+
content_type = request.headers.get("content-type")
|
|
82
72
|
if content_type == "application/x-pandas-arrow":
|
|
83
73
|
return await _process_pyarrow(request)
|
|
84
74
|
if content_type != "application/x-protobuf":
|
|
85
|
-
|
|
86
|
-
detail="Unsupported content type", status_code=HTTP_415_UNSUPPORTED_MEDIA_TYPE
|
|
87
|
-
)
|
|
75
|
+
return Response("Unsupported content type", status_code=HTTP_415_UNSUPPORTED_MEDIA_TYPE)
|
|
88
76
|
body = await request.body()
|
|
77
|
+
content_encoding = request.headers.get("content-encoding")
|
|
89
78
|
if content_encoding == "gzip":
|
|
90
79
|
body = gzip.decompress(body)
|
|
91
80
|
elif content_encoding:
|
|
92
|
-
|
|
93
|
-
detail="Unsupported content encoding", status_code=HTTP_415_UNSUPPORTED_MEDIA_TYPE
|
|
94
|
-
)
|
|
81
|
+
return Response("Unsupported content encoding", status_code=HTTP_415_UNSUPPORTED_MEDIA_TYPE)
|
|
95
82
|
evaluation = pb.Evaluation()
|
|
96
83
|
try:
|
|
97
84
|
evaluation.ParseFromString(body)
|
|
98
85
|
except DecodeError:
|
|
99
|
-
|
|
100
|
-
detail="Request body is invalid", status_code=HTTP_422_UNPROCESSABLE_ENTITY
|
|
101
|
-
)
|
|
86
|
+
return Response("Request body is invalid", status_code=HTTP_422_UNPROCESSABLE_ENTITY)
|
|
102
87
|
if not evaluation.name.strip():
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
return Response(
|
|
89
|
+
"Evaluation name must not be blank/empty",
|
|
105
90
|
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
|
|
106
91
|
)
|
|
107
92
|
await request.state.queue_evaluation_for_bulk_insert(evaluation)
|
|
108
93
|
return Response()
|
|
109
94
|
|
|
110
95
|
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
96
|
+
async def get_evaluations(request: Request) -> Response:
|
|
97
|
+
"""
|
|
98
|
+
summary: Get evaluations from Phoenix
|
|
99
|
+
operationId: getEvaluation
|
|
100
|
+
tags:
|
|
101
|
+
- private
|
|
102
|
+
parameters:
|
|
103
|
+
- name: project_name
|
|
104
|
+
in: query
|
|
105
|
+
schema:
|
|
106
|
+
type: string
|
|
107
|
+
default: default
|
|
108
|
+
description: The project name to get evaluations from
|
|
109
|
+
responses:
|
|
110
|
+
200:
|
|
111
|
+
description: Success
|
|
112
|
+
403:
|
|
113
|
+
description: Forbidden
|
|
114
|
+
404:
|
|
115
|
+
description: Not found
|
|
116
|
+
"""
|
|
127
117
|
project_name = (
|
|
128
|
-
project_name
|
|
118
|
+
request.query_params.get("project_name")
|
|
129
119
|
or request.query_params.get("project-name") # for backward compatibility
|
|
130
120
|
or request.headers.get("project-name") # read from headers for backwards compatibility
|
|
131
121
|
or DEFAULT_PROJECT_NAME
|
|
@@ -179,20 +169,20 @@ async def _process_pyarrow(request: Request) -> Response:
|
|
|
179
169
|
try:
|
|
180
170
|
reader = pa.ipc.open_stream(body)
|
|
181
171
|
except pa.ArrowInvalid:
|
|
182
|
-
|
|
183
|
-
|
|
172
|
+
return Response(
|
|
173
|
+
content="Request body is not valid pyarrow",
|
|
184
174
|
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
|
|
185
175
|
)
|
|
186
176
|
try:
|
|
187
177
|
evaluations = Evaluations.from_pyarrow_reader(reader)
|
|
188
178
|
except Exception as e:
|
|
189
179
|
if isinstance(e, PhoenixEvaluationNameIsMissing):
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
return Response(
|
|
181
|
+
"Evaluation name must not be blank/empty",
|
|
192
182
|
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
|
|
193
183
|
)
|
|
194
|
-
|
|
195
|
-
|
|
184
|
+
return Response(
|
|
185
|
+
content="Invalid data in request body",
|
|
196
186
|
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
|
|
197
187
|
)
|
|
198
188
|
return Response(background=BackgroundTask(_add_evaluations, request.state, evaluations))
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
-
from typing import Any, Dict, Literal, Optional
|
|
3
2
|
|
|
4
|
-
from fastapi import APIRouter, HTTPException
|
|
5
|
-
from pydantic import BaseModel, Field
|
|
6
3
|
from starlette.requests import Request
|
|
4
|
+
from starlette.responses import JSONResponse, Response
|
|
7
5
|
from starlette.status import HTTP_404_NOT_FOUND
|
|
8
6
|
from strawberry.relay import GlobalID
|
|
9
7
|
|
|
@@ -12,75 +10,103 @@ from phoenix.db.helpers import SupportedSQLDialect
|
|
|
12
10
|
from phoenix.db.insertion.helpers import insert_on_conflict
|
|
13
11
|
from phoenix.server.api.types.node import from_global_id_with_expected_type
|
|
14
12
|
|
|
15
|
-
from .utils import ResponseBody, add_errors_to_responses
|
|
16
13
|
|
|
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
|
-
|
|
14
|
+
async def upsert_experiment_evaluation(request: Request) -> Response:
|
|
15
|
+
"""
|
|
16
|
+
summary: Create an evaluation for a specific experiment run
|
|
17
|
+
operationId: upsertExperimentEvaluation
|
|
18
|
+
tags:
|
|
19
|
+
- private
|
|
20
|
+
requestBody:
|
|
21
|
+
description: Details of the experiment evaluation to be upserted
|
|
22
|
+
required: true
|
|
23
|
+
content:
|
|
24
|
+
application/json:
|
|
25
|
+
schema:
|
|
26
|
+
type: object
|
|
27
|
+
properties:
|
|
28
|
+
experiment_run_id:
|
|
29
|
+
type: string
|
|
30
|
+
description: The ID of the experiment run being evaluated
|
|
31
|
+
name:
|
|
32
|
+
type: string
|
|
33
|
+
description: The name of the evaluation
|
|
34
|
+
annotator_kind:
|
|
35
|
+
type: string
|
|
36
|
+
description: The kind of annotator used for the evaluation
|
|
37
|
+
result:
|
|
38
|
+
type: object
|
|
39
|
+
description: The result of the evaluation
|
|
40
|
+
properties:
|
|
41
|
+
label:
|
|
42
|
+
type: string
|
|
43
|
+
description: The label assigned by the evaluation
|
|
44
|
+
score:
|
|
45
|
+
type: number
|
|
46
|
+
format: float
|
|
47
|
+
description: The score assigned by the evaluation
|
|
48
|
+
explanation:
|
|
49
|
+
type: string
|
|
50
|
+
description: Explanation of the evaluation result
|
|
51
|
+
error:
|
|
52
|
+
type: string
|
|
53
|
+
description: Optional error message if the evaluation encountered an error
|
|
54
|
+
metadata:
|
|
55
|
+
type: object
|
|
56
|
+
description: Metadata for the evaluation
|
|
57
|
+
additionalProperties:
|
|
58
|
+
type: string
|
|
59
|
+
start_time:
|
|
60
|
+
type: string
|
|
61
|
+
format: date-time
|
|
62
|
+
description: The start time of the evaluation in ISO format
|
|
63
|
+
end_time:
|
|
64
|
+
type: string
|
|
65
|
+
format: date-time
|
|
66
|
+
description: The end time of the evaluation in ISO format
|
|
67
|
+
trace_id:
|
|
68
|
+
type: string
|
|
69
|
+
description: Optional trace ID for tracking
|
|
70
|
+
required:
|
|
71
|
+
- experiment_run_id
|
|
72
|
+
- name
|
|
73
|
+
- annotator_kind
|
|
74
|
+
- start_time
|
|
75
|
+
- end_time
|
|
76
|
+
responses:
|
|
77
|
+
200:
|
|
78
|
+
description: Experiment evaluation upserted successfully
|
|
79
|
+
content:
|
|
80
|
+
application/json:
|
|
81
|
+
schema:
|
|
82
|
+
type: object
|
|
83
|
+
properties:
|
|
84
|
+
data:
|
|
85
|
+
type: object
|
|
86
|
+
properties:
|
|
87
|
+
id:
|
|
88
|
+
type: string
|
|
89
|
+
description: The ID of the upserted experiment evaluation
|
|
90
|
+
404:
|
|
91
|
+
description: ExperimentRun not found
|
|
92
|
+
"""
|
|
67
93
|
payload = await request.json()
|
|
68
94
|
experiment_run_gid = GlobalID.from_id(payload["experiment_run_id"])
|
|
69
95
|
try:
|
|
70
96
|
experiment_run_id = from_global_id_with_expected_type(experiment_run_gid, "ExperimentRun")
|
|
71
97
|
except ValueError:
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
return Response(
|
|
99
|
+
content=f"ExperimentRun with ID {experiment_run_gid} does not exist",
|
|
74
100
|
status_code=HTTP_404_NOT_FOUND,
|
|
75
101
|
)
|
|
76
|
-
name =
|
|
77
|
-
annotator_kind =
|
|
78
|
-
result =
|
|
79
|
-
label = result.label if result else None
|
|
80
|
-
score = result.score if result else None
|
|
81
|
-
explanation = result.explanation if result else None
|
|
82
|
-
error =
|
|
83
|
-
metadata =
|
|
102
|
+
name = payload["name"]
|
|
103
|
+
annotator_kind = payload["annotator_kind"]
|
|
104
|
+
result = payload.get("result")
|
|
105
|
+
label = result.get("label") if result else None
|
|
106
|
+
score = result.get("score") if result else None
|
|
107
|
+
explanation = result.get("explanation") if result else None
|
|
108
|
+
error = payload.get("error")
|
|
109
|
+
metadata = payload.get("metadata") or {}
|
|
84
110
|
start_time = payload["start_time"]
|
|
85
111
|
end_time = payload["end_time"]
|
|
86
112
|
async with request.app.state.db() as session:
|
|
@@ -107,6 +133,4 @@ async def upsert_experiment_evaluation(
|
|
|
107
133
|
).returning(models.ExperimentRunAnnotation)
|
|
108
134
|
)
|
|
109
135
|
evaluation_gid = GlobalID("ExperimentEvaluation", str(exp_eval_run.id))
|
|
110
|
-
return
|
|
111
|
-
data=UpsertExperimentEvaluationResponseBodyData(id=str(evaluation_gid))
|
|
112
|
-
)
|
|
136
|
+
return JSONResponse(content={"data": {"id": str(evaluation_gid)}})
|