agenta 0.24.1a0__py3-none-any.whl → 0.24.2__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 agenta might be problematic. Click here for more details.
- agenta/cli/variant_commands.py +15 -10
- agenta/client/Readme.md +72 -64
- agenta/client/api.py +1 -1
- agenta/client/backend/__init__.py +14 -9
- agenta/client/backend/apps/client.py +1669 -0
- agenta/client/backend/bases/client.py +190 -0
- agenta/client/backend/client.py +2102 -868
- agenta/client/backend/configs/client.py +598 -0
- agenta/client/backend/containers/client.py +638 -0
- agenta/client/backend/{resources/containers → containers}/types/container_templates_response.py +1 -2
- agenta/client/backend/core/__init__.py +29 -0
- agenta/client/backend/core/client_wrapper.py +42 -9
- agenta/client/backend/core/datetime_utils.py +1 -1
- agenta/client/backend/core/file.py +43 -0
- agenta/client/backend/core/http_client.py +553 -0
- agenta/client/backend/core/jsonable_encoder.py +33 -39
- agenta/client/backend/core/pydantic_utilities.py +212 -0
- agenta/client/backend/core/query_encoder.py +60 -0
- agenta/client/backend/core/remove_none_from_dict.py +2 -2
- agenta/client/backend/core/request_options.py +32 -0
- agenta/client/backend/core/serialization.py +179 -0
- agenta/client/backend/environments/client.py +190 -0
- agenta/client/backend/evaluations/client.py +1462 -0
- agenta/client/backend/evaluators/client.py +911 -0
- agenta/client/backend/observability/client.py +1271 -0
- agenta/client/backend/testsets/client.py +1132 -0
- agenta/client/backend/types/__init__.py +8 -6
- agenta/client/backend/types/aggregated_result.py +14 -29
- agenta/client/backend/types/aggregated_result_evaluator_config.py +1 -2
- agenta/client/backend/types/app.py +13 -28
- agenta/client/backend/types/app_variant_response.py +21 -37
- agenta/client/backend/types/app_variant_revision.py +17 -32
- agenta/client/backend/types/base_output.py +13 -28
- agenta/client/backend/types/body_import_testset.py +16 -31
- agenta/client/backend/types/config_db.py +16 -31
- agenta/client/backend/types/correct_answer.py +22 -0
- agenta/client/backend/types/create_app_output.py +13 -28
- agenta/client/backend/types/create_span.py +33 -50
- agenta/client/backend/types/create_trace_response.py +16 -31
- agenta/client/backend/types/docker_env_vars.py +13 -28
- agenta/client/backend/types/environment_output.py +21 -36
- agenta/client/backend/types/environment_output_extended.py +21 -36
- agenta/client/backend/types/environment_revision.py +18 -33
- agenta/client/backend/types/error.py +16 -31
- agenta/client/backend/types/evaluation.py +20 -34
- agenta/client/backend/types/evaluation_scenario.py +18 -33
- agenta/client/backend/types/evaluation_scenario_input.py +16 -31
- agenta/client/backend/types/evaluation_scenario_output.py +18 -33
- agenta/client/backend/types/evaluation_scenario_result.py +14 -29
- agenta/client/backend/types/evaluation_scenario_score_update.py +13 -28
- agenta/client/backend/types/evaluation_status_enum.py +11 -33
- agenta/client/backend/types/evaluation_type.py +3 -21
- agenta/client/backend/types/evaluator.py +18 -32
- agenta/client/backend/types/evaluator_config.py +20 -33
- agenta/client/backend/types/get_config_response.py +16 -31
- agenta/client/backend/types/http_validation_error.py +14 -29
- agenta/client/backend/types/human_evaluation.py +17 -32
- agenta/client/backend/types/human_evaluation_scenario.py +21 -37
- agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
- agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
- agenta/client/backend/types/human_evaluation_scenario_update.py +26 -41
- agenta/client/backend/types/human_evaluation_update.py +14 -29
- agenta/client/backend/types/image.py +18 -33
- agenta/client/backend/types/invite_request.py +13 -28
- agenta/client/backend/types/list_api_keys_response.py +18 -33
- agenta/client/backend/types/llm_run_rate_limit.py +13 -28
- agenta/client/backend/types/llm_tokens.py +16 -31
- agenta/client/backend/types/lm_providers_enum.py +21 -0
- agenta/client/backend/types/new_human_evaluation.py +13 -28
- agenta/client/backend/types/new_testset.py +16 -31
- agenta/client/backend/types/organization.py +22 -36
- agenta/client/backend/types/organization_output.py +13 -28
- agenta/client/backend/types/outputs.py +5 -0
- agenta/client/backend/types/permission.py +36 -137
- agenta/client/backend/types/result.py +17 -32
- agenta/client/backend/types/simple_evaluation_output.py +13 -28
- agenta/client/backend/types/span.py +23 -38
- agenta/client/backend/types/span_detail.py +26 -40
- agenta/client/backend/types/span_status_code.py +1 -25
- agenta/client/backend/types/span_variant.py +16 -31
- agenta/client/backend/types/template.py +14 -29
- agenta/client/backend/types/template_image_info.py +21 -35
- agenta/client/backend/types/test_set_output_response.py +16 -32
- agenta/client/backend/types/test_set_simple_response.py +13 -28
- agenta/client/backend/types/trace_detail.py +26 -40
- agenta/client/backend/types/update_app_output.py +22 -0
- agenta/client/backend/types/uri.py +13 -28
- agenta/client/backend/types/validation_error.py +13 -28
- agenta/client/backend/types/variant_action.py +14 -29
- agenta/client/backend/types/variant_action_enum.py +1 -19
- agenta/client/backend/types/with_pagination.py +14 -30
- agenta/client/backend/types/workspace_member_response.py +14 -29
- agenta/client/backend/types/workspace_permission.py +18 -33
- agenta/client/backend/types/workspace_response.py +20 -35
- agenta/client/backend/types/workspace_role.py +11 -37
- agenta/client/backend/types/workspace_role_response.py +17 -32
- agenta/client/backend/variants/client.py +1447 -0
- agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
- agenta/sdk/decorators/llm_entrypoint.py +8 -13
- agenta/sdk/tracing/llm_tracing.py +10 -12
- {agenta-0.24.1a0.dist-info → agenta-0.24.2.dist-info}/METADATA +1 -1
- agenta-0.24.2.dist-info/RECORD +175 -0
- agenta/client/backend/resources/__init__.py +0 -31
- agenta/client/backend/resources/apps/client.py +0 -977
- agenta/client/backend/resources/bases/client.py +0 -127
- agenta/client/backend/resources/configs/client.py +0 -377
- agenta/client/backend/resources/containers/client.py +0 -383
- agenta/client/backend/resources/environments/client.py +0 -131
- agenta/client/backend/resources/evaluations/client.py +0 -1008
- agenta/client/backend/resources/evaluators/client.py +0 -594
- agenta/client/backend/resources/observability/client.py +0 -1187
- agenta/client/backend/resources/testsets/client.py +0 -689
- agenta/client/backend/resources/variants/client.py +0 -796
- agenta/client/backend/resources/variants/types/add_variant_from_base_and_config_response.py +0 -7
- agenta/client/backend/types/evaluation_webhook.py +0 -36
- agenta/client/backend/types/feedback.py +0 -40
- agenta/client/backend/types/span_kind.py +0 -49
- agenta-0.24.1a0.dist-info/RECORD +0 -169
- /agenta/client/backend/{resources/apps → apps}/__init__.py +0 -0
- /agenta/client/backend/{resources/bases → bases}/__init__.py +0 -0
- /agenta/client/backend/{resources/configs → configs}/__init__.py +0 -0
- /agenta/client/backend/{resources/containers → containers}/__init__.py +0 -0
- /agenta/client/backend/{resources/containers → containers}/types/__init__.py +0 -0
- /agenta/client/backend/{resources/environments → environments}/__init__.py +0 -0
- /agenta/client/backend/{resources/evaluations → evaluations}/__init__.py +0 -0
- /agenta/client/backend/{resources/evaluators → evaluators}/__init__.py +0 -0
- /agenta/client/backend/{resources/observability → observability}/__init__.py +0 -0
- /agenta/client/backend/{resources/testsets → testsets}/__init__.py +0 -0
- /agenta/client/backend/{resources/variants → variants}/__init__.py +0 -0
- /agenta/client/backend/{resources/variants → variants}/types/__init__.py +0 -0
- {agenta-0.24.1a0.dist-info → agenta-0.24.2.dist-info}/WHEEL +0 -0
- {agenta-0.24.1a0.dist-info → agenta-0.24.2.dist-info}/entry_points.txt +0 -0
|
@@ -1,1187 +0,0 @@
|
|
|
1
|
-
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
-
|
|
3
|
-
import typing
|
|
4
|
-
import urllib.parse
|
|
5
|
-
from json.decoder import JSONDecodeError
|
|
6
|
-
|
|
7
|
-
from ...core.api_error import ApiError
|
|
8
|
-
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
|
|
9
|
-
from ...core.jsonable_encoder import jsonable_encoder
|
|
10
|
-
from ...core.remove_none_from_dict import remove_none_from_dict
|
|
11
|
-
from ...errors.unprocessable_entity_error import UnprocessableEntityError
|
|
12
|
-
from ...types.create_span import CreateSpan
|
|
13
|
-
from ...types.create_trace_response import CreateTraceResponse
|
|
14
|
-
from ...types.feedback import Feedback
|
|
15
|
-
from ...types.http_validation_error import HttpValidationError
|
|
16
|
-
from ...types.span_detail import SpanDetail
|
|
17
|
-
from ...types.trace_detail import TraceDetail
|
|
18
|
-
from ...types.with_pagination import WithPagination
|
|
19
|
-
|
|
20
|
-
from agenta.sdk.tracing.logger import llm_logger as logging
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
try:
|
|
24
|
-
import pydantic.v1 as pydantic # type: ignore
|
|
25
|
-
except ImportError:
|
|
26
|
-
import pydantic # type: ignore
|
|
27
|
-
|
|
28
|
-
# this is used as the default value for optional parameters
|
|
29
|
-
OMIT = typing.cast(typing.Any, ...)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class ObservabilityClient:
|
|
33
|
-
def __init__(self, *, client_wrapper: SyncClientWrapper):
|
|
34
|
-
self._client_wrapper = client_wrapper
|
|
35
|
-
|
|
36
|
-
def dashboard(
|
|
37
|
-
self,
|
|
38
|
-
*,
|
|
39
|
-
app_id: str,
|
|
40
|
-
time_range: typing.Optional[str] = None,
|
|
41
|
-
environment: typing.Optional[str] = None,
|
|
42
|
-
variant: typing.Optional[str] = None,
|
|
43
|
-
) -> typing.Any:
|
|
44
|
-
"""
|
|
45
|
-
Parameters:
|
|
46
|
-
- app_id: str.
|
|
47
|
-
|
|
48
|
-
- time_range: typing.Optional[str].
|
|
49
|
-
|
|
50
|
-
- environment: typing.Optional[str].
|
|
51
|
-
|
|
52
|
-
- variant: typing.Optional[str].
|
|
53
|
-
---
|
|
54
|
-
from agenta.client import AgentaApi
|
|
55
|
-
|
|
56
|
-
client = AgentaApi(
|
|
57
|
-
api_key="YOUR_API_KEY",
|
|
58
|
-
base_url="https://yourhost.com/path/to/api",
|
|
59
|
-
)
|
|
60
|
-
client.observability.dashboard(
|
|
61
|
-
app_id="app_id",
|
|
62
|
-
)
|
|
63
|
-
"""
|
|
64
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
65
|
-
"GET",
|
|
66
|
-
urllib.parse.urljoin(
|
|
67
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/dashboard"
|
|
68
|
-
),
|
|
69
|
-
params=remove_none_from_dict(
|
|
70
|
-
{
|
|
71
|
-
"app_id": app_id,
|
|
72
|
-
"timeRange": time_range,
|
|
73
|
-
"environment": environment,
|
|
74
|
-
"variant": variant,
|
|
75
|
-
}
|
|
76
|
-
),
|
|
77
|
-
headers=self._client_wrapper.get_headers(),
|
|
78
|
-
timeout=60,
|
|
79
|
-
)
|
|
80
|
-
if 200 <= _response.status_code < 300:
|
|
81
|
-
return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
|
82
|
-
if _response.status_code == 422:
|
|
83
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
84
|
-
try:
|
|
85
|
-
_response_json = _response.json()
|
|
86
|
-
except JSONDecodeError:
|
|
87
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
88
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
89
|
-
|
|
90
|
-
def get_traces(
|
|
91
|
-
self,
|
|
92
|
-
*,
|
|
93
|
-
app_id: str,
|
|
94
|
-
page: typing.Optional[int] = None,
|
|
95
|
-
page_size: typing.Optional[int] = None,
|
|
96
|
-
type: typing.Optional[str] = None,
|
|
97
|
-
trace_id: typing.Optional[str] = None,
|
|
98
|
-
environment: typing.Optional[str] = None,
|
|
99
|
-
variant: typing.Optional[str] = None,
|
|
100
|
-
created_at: typing.Optional[str] = None,
|
|
101
|
-
) -> WithPagination:
|
|
102
|
-
"""
|
|
103
|
-
Parameters:
|
|
104
|
-
- app_id: str.
|
|
105
|
-
|
|
106
|
-
- page: typing.Optional[int].
|
|
107
|
-
|
|
108
|
-
- page_size: typing.Optional[int].
|
|
109
|
-
|
|
110
|
-
- type: typing.Optional[str].
|
|
111
|
-
|
|
112
|
-
- trace_id: typing.Optional[str].
|
|
113
|
-
|
|
114
|
-
- environment: typing.Optional[str].
|
|
115
|
-
|
|
116
|
-
- variant: typing.Optional[str].
|
|
117
|
-
|
|
118
|
-
- created_at: typing.Optional[str].
|
|
119
|
-
---
|
|
120
|
-
from agenta.client import AgentaApi
|
|
121
|
-
|
|
122
|
-
client = AgentaApi(
|
|
123
|
-
api_key="YOUR_API_KEY",
|
|
124
|
-
base_url="https://yourhost.com/path/to/api",
|
|
125
|
-
)
|
|
126
|
-
client.observability.get_traces(
|
|
127
|
-
app_id="app_id",
|
|
128
|
-
)
|
|
129
|
-
"""
|
|
130
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
131
|
-
"GET",
|
|
132
|
-
urllib.parse.urljoin(
|
|
133
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/traces"
|
|
134
|
-
),
|
|
135
|
-
params=remove_none_from_dict(
|
|
136
|
-
{
|
|
137
|
-
"app_id": app_id,
|
|
138
|
-
"page": page,
|
|
139
|
-
"pageSize": page_size,
|
|
140
|
-
"type": type,
|
|
141
|
-
"trace_id": trace_id,
|
|
142
|
-
"environment": environment,
|
|
143
|
-
"variant": variant,
|
|
144
|
-
"created_at": created_at,
|
|
145
|
-
}
|
|
146
|
-
),
|
|
147
|
-
headers=self._client_wrapper.get_headers(),
|
|
148
|
-
timeout=60,
|
|
149
|
-
)
|
|
150
|
-
if 200 <= _response.status_code < 300:
|
|
151
|
-
return pydantic.parse_obj_as(WithPagination, _response.json()) # type: ignore
|
|
152
|
-
if _response.status_code == 422:
|
|
153
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
154
|
-
try:
|
|
155
|
-
_response_json = _response.json()
|
|
156
|
-
except JSONDecodeError:
|
|
157
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
158
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
159
|
-
|
|
160
|
-
def create_traces(
|
|
161
|
-
self, *, trace: str, spans: typing.List[CreateSpan]
|
|
162
|
-
) -> CreateTraceResponse:
|
|
163
|
-
"""
|
|
164
|
-
Parameters:
|
|
165
|
-
- trace: str.
|
|
166
|
-
|
|
167
|
-
- spans: typing.List[CreateSpan].
|
|
168
|
-
---
|
|
169
|
-
import datetime
|
|
170
|
-
|
|
171
|
-
from agenta import CreateSpan, SpanKind, SpanStatusCode
|
|
172
|
-
from agenta.client import AgentaApi
|
|
173
|
-
|
|
174
|
-
client = AgentaApi(
|
|
175
|
-
api_key="YOUR_API_KEY",
|
|
176
|
-
base_url="https://yourhost.com/path/to/api",
|
|
177
|
-
)
|
|
178
|
-
client.observability.create_traces(
|
|
179
|
-
trace="trace",
|
|
180
|
-
spans=[
|
|
181
|
-
CreateSpan(
|
|
182
|
-
id="id",
|
|
183
|
-
name="name",
|
|
184
|
-
spankind=SpanKind.TOOL,
|
|
185
|
-
status=SpanStatusCode.UNSET,
|
|
186
|
-
start_time=datetime.datetime.fromisoformat(
|
|
187
|
-
"2024-01-15 09:30:00+00:00",
|
|
188
|
-
),
|
|
189
|
-
end_time=datetime.datetime.fromisoformat(
|
|
190
|
-
"2024-01-15 09:30:00+00:00",
|
|
191
|
-
),
|
|
192
|
-
)
|
|
193
|
-
],
|
|
194
|
-
)
|
|
195
|
-
"""
|
|
196
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
197
|
-
"POST",
|
|
198
|
-
urllib.parse.urljoin(
|
|
199
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/trace/"
|
|
200
|
-
),
|
|
201
|
-
json=jsonable_encoder({"trace": trace, "spans": spans}),
|
|
202
|
-
headers=self._client_wrapper.get_headers(),
|
|
203
|
-
timeout=60,
|
|
204
|
-
)
|
|
205
|
-
if 200 <= _response.status_code < 300:
|
|
206
|
-
return pydantic.parse_obj_as(CreateTraceResponse, _response.json()) # type: ignore
|
|
207
|
-
if _response.status_code == 422:
|
|
208
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
209
|
-
try:
|
|
210
|
-
_response_json = _response.json()
|
|
211
|
-
except JSONDecodeError:
|
|
212
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
213
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
214
|
-
|
|
215
|
-
def delete_traces(self, *, request: typing.List[str]) -> bool:
|
|
216
|
-
"""
|
|
217
|
-
Parameters:
|
|
218
|
-
- request: typing.List[str].
|
|
219
|
-
---
|
|
220
|
-
from agenta.client import AgentaApi
|
|
221
|
-
|
|
222
|
-
client = AgentaApi(
|
|
223
|
-
api_key="YOUR_API_KEY",
|
|
224
|
-
base_url="https://yourhost.com/path/to/api",
|
|
225
|
-
)
|
|
226
|
-
client.observability.delete_traces(
|
|
227
|
-
request=["string"],
|
|
228
|
-
)
|
|
229
|
-
"""
|
|
230
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
231
|
-
"DELETE",
|
|
232
|
-
urllib.parse.urljoin(
|
|
233
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/traces"
|
|
234
|
-
),
|
|
235
|
-
json=jsonable_encoder(request),
|
|
236
|
-
headers=self._client_wrapper.get_headers(),
|
|
237
|
-
timeout=60,
|
|
238
|
-
)
|
|
239
|
-
if 200 <= _response.status_code < 300:
|
|
240
|
-
return pydantic.parse_obj_as(bool, _response.json()) # type: ignore
|
|
241
|
-
if _response.status_code == 422:
|
|
242
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
243
|
-
try:
|
|
244
|
-
_response_json = _response.json()
|
|
245
|
-
except JSONDecodeError:
|
|
246
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
247
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
248
|
-
|
|
249
|
-
def get_trace_detail(self, trace_id: str) -> TraceDetail:
|
|
250
|
-
"""
|
|
251
|
-
Parameters:
|
|
252
|
-
- trace_id: str.
|
|
253
|
-
---
|
|
254
|
-
from agenta.client import AgentaApi
|
|
255
|
-
|
|
256
|
-
client = AgentaApi(
|
|
257
|
-
api_key="YOUR_API_KEY",
|
|
258
|
-
base_url="https://yourhost.com/path/to/api",
|
|
259
|
-
)
|
|
260
|
-
client.observability.get_trace_detail(
|
|
261
|
-
trace_id="trace_id",
|
|
262
|
-
)
|
|
263
|
-
"""
|
|
264
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
265
|
-
"GET",
|
|
266
|
-
urllib.parse.urljoin(
|
|
267
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
268
|
-
f"observability/traces/{trace_id}",
|
|
269
|
-
),
|
|
270
|
-
headers=self._client_wrapper.get_headers(),
|
|
271
|
-
timeout=60,
|
|
272
|
-
)
|
|
273
|
-
if 200 <= _response.status_code < 300:
|
|
274
|
-
return pydantic.parse_obj_as(TraceDetail, _response.json()) # type: ignore
|
|
275
|
-
if _response.status_code == 422:
|
|
276
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
277
|
-
try:
|
|
278
|
-
_response_json = _response.json()
|
|
279
|
-
except JSONDecodeError:
|
|
280
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
281
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
282
|
-
|
|
283
|
-
def get_spans_of_generation(
|
|
284
|
-
self,
|
|
285
|
-
*,
|
|
286
|
-
app_id: str,
|
|
287
|
-
page: typing.Optional[int] = None,
|
|
288
|
-
page_size: typing.Optional[int] = None,
|
|
289
|
-
type: typing.Optional[str] = None,
|
|
290
|
-
trace_id: typing.Optional[str] = None,
|
|
291
|
-
environment: typing.Optional[str] = None,
|
|
292
|
-
variant: typing.Optional[str] = None,
|
|
293
|
-
created_at: typing.Optional[str] = None,
|
|
294
|
-
) -> typing.Any:
|
|
295
|
-
"""
|
|
296
|
-
Parameters:
|
|
297
|
-
- app_id: str.
|
|
298
|
-
|
|
299
|
-
- page: typing.Optional[int].
|
|
300
|
-
|
|
301
|
-
- page_size: typing.Optional[int].
|
|
302
|
-
|
|
303
|
-
- type: typing.Optional[str].
|
|
304
|
-
|
|
305
|
-
- trace_id: typing.Optional[str].
|
|
306
|
-
|
|
307
|
-
- environment: typing.Optional[str].
|
|
308
|
-
|
|
309
|
-
- variant: typing.Optional[str].
|
|
310
|
-
|
|
311
|
-
- created_at: typing.Optional[str].
|
|
312
|
-
---
|
|
313
|
-
from agenta.client import AgentaApi
|
|
314
|
-
|
|
315
|
-
client = AgentaApi(
|
|
316
|
-
api_key="YOUR_API_KEY",
|
|
317
|
-
base_url="https://yourhost.com/path/to/api",
|
|
318
|
-
)
|
|
319
|
-
client.observability.get_spans_of_generation(
|
|
320
|
-
app_id="app_id",
|
|
321
|
-
)
|
|
322
|
-
"""
|
|
323
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
324
|
-
"GET",
|
|
325
|
-
urllib.parse.urljoin(
|
|
326
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/spans"
|
|
327
|
-
),
|
|
328
|
-
params=remove_none_from_dict(
|
|
329
|
-
{
|
|
330
|
-
"app_id": app_id,
|
|
331
|
-
"page": page,
|
|
332
|
-
"pageSize": page_size,
|
|
333
|
-
"type": type,
|
|
334
|
-
"trace_id": trace_id,
|
|
335
|
-
"environment": environment,
|
|
336
|
-
"variant": variant,
|
|
337
|
-
"created_at": created_at,
|
|
338
|
-
}
|
|
339
|
-
),
|
|
340
|
-
headers=self._client_wrapper.get_headers(),
|
|
341
|
-
timeout=60,
|
|
342
|
-
)
|
|
343
|
-
if 200 <= _response.status_code < 300:
|
|
344
|
-
return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
|
345
|
-
if _response.status_code == 422:
|
|
346
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
347
|
-
try:
|
|
348
|
-
_response_json = _response.json()
|
|
349
|
-
except JSONDecodeError:
|
|
350
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
351
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
352
|
-
|
|
353
|
-
def delete_spans_of_trace(self, *, request: typing.List[str]) -> bool:
|
|
354
|
-
"""
|
|
355
|
-
Parameters:
|
|
356
|
-
- request: typing.List[str].
|
|
357
|
-
---
|
|
358
|
-
from agenta.client import AgentaApi
|
|
359
|
-
|
|
360
|
-
client = AgentaApi(
|
|
361
|
-
api_key="YOUR_API_KEY",
|
|
362
|
-
base_url="https://yourhost.com/path/to/api",
|
|
363
|
-
)
|
|
364
|
-
client.observability.delete_spans_of_trace(
|
|
365
|
-
request=["string"],
|
|
366
|
-
)
|
|
367
|
-
"""
|
|
368
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
369
|
-
"DELETE",
|
|
370
|
-
urllib.parse.urljoin(
|
|
371
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/spans"
|
|
372
|
-
),
|
|
373
|
-
json=jsonable_encoder(request),
|
|
374
|
-
headers=self._client_wrapper.get_headers(),
|
|
375
|
-
timeout=60,
|
|
376
|
-
)
|
|
377
|
-
if 200 <= _response.status_code < 300:
|
|
378
|
-
return pydantic.parse_obj_as(bool, _response.json()) # type: ignore
|
|
379
|
-
if _response.status_code == 422:
|
|
380
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
381
|
-
try:
|
|
382
|
-
_response_json = _response.json()
|
|
383
|
-
except JSONDecodeError:
|
|
384
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
385
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
386
|
-
|
|
387
|
-
def get_span_of_generation(
|
|
388
|
-
self, span_id: str, *, type: typing.Optional[str] = None
|
|
389
|
-
) -> SpanDetail:
|
|
390
|
-
"""
|
|
391
|
-
Parameters:
|
|
392
|
-
- span_id: str.
|
|
393
|
-
|
|
394
|
-
- type: typing.Optional[str].
|
|
395
|
-
---
|
|
396
|
-
from agenta.client import AgentaApi
|
|
397
|
-
|
|
398
|
-
client = AgentaApi(
|
|
399
|
-
api_key="YOUR_API_KEY",
|
|
400
|
-
base_url="https://yourhost.com/path/to/api",
|
|
401
|
-
)
|
|
402
|
-
client.observability.get_span_of_generation(
|
|
403
|
-
span_id="span_id",
|
|
404
|
-
)
|
|
405
|
-
"""
|
|
406
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
407
|
-
"GET",
|
|
408
|
-
urllib.parse.urljoin(
|
|
409
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
410
|
-
f"observability/spans/{span_id}",
|
|
411
|
-
),
|
|
412
|
-
params=remove_none_from_dict({"type": type}),
|
|
413
|
-
headers=self._client_wrapper.get_headers(),
|
|
414
|
-
timeout=60,
|
|
415
|
-
)
|
|
416
|
-
if 200 <= _response.status_code < 300:
|
|
417
|
-
return pydantic.parse_obj_as(SpanDetail, _response.json()) # type: ignore
|
|
418
|
-
if _response.status_code == 422:
|
|
419
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
420
|
-
try:
|
|
421
|
-
_response_json = _response.json()
|
|
422
|
-
except JSONDecodeError:
|
|
423
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
424
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
425
|
-
|
|
426
|
-
def get_feedbacks(self, trace_id: str) -> typing.List[Feedback]:
|
|
427
|
-
"""
|
|
428
|
-
Parameters:
|
|
429
|
-
- trace_id: str.
|
|
430
|
-
---
|
|
431
|
-
from agenta.client import AgentaApi
|
|
432
|
-
|
|
433
|
-
client = AgentaApi(
|
|
434
|
-
api_key="YOUR_API_KEY",
|
|
435
|
-
base_url="https://yourhost.com/path/to/api",
|
|
436
|
-
)
|
|
437
|
-
client.observability.get_feedbacks(
|
|
438
|
-
trace_id="trace_id",
|
|
439
|
-
)
|
|
440
|
-
"""
|
|
441
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
442
|
-
"GET",
|
|
443
|
-
urllib.parse.urljoin(
|
|
444
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
445
|
-
f"observability/feedbacks/{trace_id}",
|
|
446
|
-
),
|
|
447
|
-
headers=self._client_wrapper.get_headers(),
|
|
448
|
-
timeout=60,
|
|
449
|
-
)
|
|
450
|
-
if 200 <= _response.status_code < 300:
|
|
451
|
-
return pydantic.parse_obj_as(typing.List[Feedback], _response.json()) # type: ignore
|
|
452
|
-
if _response.status_code == 422:
|
|
453
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
454
|
-
try:
|
|
455
|
-
_response_json = _response.json()
|
|
456
|
-
except JSONDecodeError:
|
|
457
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
458
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
459
|
-
|
|
460
|
-
def create_feedback(
|
|
461
|
-
self,
|
|
462
|
-
trace_id: str,
|
|
463
|
-
*,
|
|
464
|
-
feedback: typing.Optional[str] = OMIT,
|
|
465
|
-
score: typing.Optional[float] = OMIT,
|
|
466
|
-
meta: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
|
467
|
-
) -> str:
|
|
468
|
-
"""
|
|
469
|
-
Parameters:
|
|
470
|
-
- trace_id: str.
|
|
471
|
-
|
|
472
|
-
- feedback: typing.Optional[str].
|
|
473
|
-
|
|
474
|
-
- score: typing.Optional[float].
|
|
475
|
-
|
|
476
|
-
- meta: typing.Optional[typing.Dict[str, typing.Any]].
|
|
477
|
-
---
|
|
478
|
-
from agenta.client import AgentaApi
|
|
479
|
-
|
|
480
|
-
client = AgentaApi(
|
|
481
|
-
api_key="YOUR_API_KEY",
|
|
482
|
-
base_url="https://yourhost.com/path/to/api",
|
|
483
|
-
)
|
|
484
|
-
client.observability.create_feedback(
|
|
485
|
-
trace_id="trace_id",
|
|
486
|
-
)
|
|
487
|
-
"""
|
|
488
|
-
_request: typing.Dict[str, typing.Any] = {}
|
|
489
|
-
if feedback is not OMIT:
|
|
490
|
-
_request["feedback"] = feedback
|
|
491
|
-
if score is not OMIT:
|
|
492
|
-
_request["score"] = score
|
|
493
|
-
if meta is not OMIT:
|
|
494
|
-
_request["meta"] = meta
|
|
495
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
496
|
-
"POST",
|
|
497
|
-
urllib.parse.urljoin(
|
|
498
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
499
|
-
f"observability/feedbacks/{trace_id}",
|
|
500
|
-
),
|
|
501
|
-
json=jsonable_encoder(_request),
|
|
502
|
-
headers=self._client_wrapper.get_headers(),
|
|
503
|
-
timeout=60,
|
|
504
|
-
)
|
|
505
|
-
if 200 <= _response.status_code < 300:
|
|
506
|
-
return pydantic.parse_obj_as(str, _response.json()) # type: ignore
|
|
507
|
-
if _response.status_code == 422:
|
|
508
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
509
|
-
try:
|
|
510
|
-
_response_json = _response.json()
|
|
511
|
-
except JSONDecodeError:
|
|
512
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
513
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
514
|
-
|
|
515
|
-
def get_feedback(self, trace_id: str, feedback_id: str) -> Feedback:
|
|
516
|
-
"""
|
|
517
|
-
Parameters:
|
|
518
|
-
- trace_id: str.
|
|
519
|
-
|
|
520
|
-
- feedback_id: str.
|
|
521
|
-
---
|
|
522
|
-
from agenta.client import AgentaApi
|
|
523
|
-
|
|
524
|
-
client = AgentaApi(
|
|
525
|
-
api_key="YOUR_API_KEY",
|
|
526
|
-
base_url="https://yourhost.com/path/to/api",
|
|
527
|
-
)
|
|
528
|
-
client.observability.get_feedback(
|
|
529
|
-
trace_id="trace_id",
|
|
530
|
-
feedback_id="feedback_id",
|
|
531
|
-
)
|
|
532
|
-
"""
|
|
533
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
534
|
-
"GET",
|
|
535
|
-
urllib.parse.urljoin(
|
|
536
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
537
|
-
f"observability/feedbacks/{trace_id}/{feedback_id}",
|
|
538
|
-
),
|
|
539
|
-
headers=self._client_wrapper.get_headers(),
|
|
540
|
-
timeout=60,
|
|
541
|
-
)
|
|
542
|
-
if 200 <= _response.status_code < 300:
|
|
543
|
-
return pydantic.parse_obj_as(Feedback, _response.json()) # type: ignore
|
|
544
|
-
if _response.status_code == 422:
|
|
545
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
546
|
-
try:
|
|
547
|
-
_response_json = _response.json()
|
|
548
|
-
except JSONDecodeError:
|
|
549
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
550
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
551
|
-
|
|
552
|
-
def update_feedback(
|
|
553
|
-
self,
|
|
554
|
-
trace_id: str,
|
|
555
|
-
feedback_id: str,
|
|
556
|
-
*,
|
|
557
|
-
feedback: str,
|
|
558
|
-
score: typing.Optional[float] = OMIT,
|
|
559
|
-
meta: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
|
560
|
-
) -> Feedback:
|
|
561
|
-
"""
|
|
562
|
-
Parameters:
|
|
563
|
-
- trace_id: str.
|
|
564
|
-
|
|
565
|
-
- feedback_id: str.
|
|
566
|
-
|
|
567
|
-
- feedback: str.
|
|
568
|
-
|
|
569
|
-
- score: typing.Optional[float].
|
|
570
|
-
|
|
571
|
-
- meta: typing.Optional[typing.Dict[str, typing.Any]].
|
|
572
|
-
---
|
|
573
|
-
from agenta.client import AgentaApi
|
|
574
|
-
|
|
575
|
-
client = AgentaApi(
|
|
576
|
-
api_key="YOUR_API_KEY",
|
|
577
|
-
base_url="https://yourhost.com/path/to/api",
|
|
578
|
-
)
|
|
579
|
-
client.observability.update_feedback(
|
|
580
|
-
trace_id="trace_id",
|
|
581
|
-
feedback_id="feedback_id",
|
|
582
|
-
feedback="feedback",
|
|
583
|
-
)
|
|
584
|
-
"""
|
|
585
|
-
_request: typing.Dict[str, typing.Any] = {"feedback": feedback}
|
|
586
|
-
if score is not OMIT:
|
|
587
|
-
_request["score"] = score
|
|
588
|
-
if meta is not OMIT:
|
|
589
|
-
_request["meta"] = meta
|
|
590
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
591
|
-
"PUT",
|
|
592
|
-
urllib.parse.urljoin(
|
|
593
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
594
|
-
f"observability/feedbacks/{trace_id}/{feedback_id}",
|
|
595
|
-
),
|
|
596
|
-
json=jsonable_encoder(_request),
|
|
597
|
-
headers=self._client_wrapper.get_headers(),
|
|
598
|
-
timeout=60,
|
|
599
|
-
)
|
|
600
|
-
if 200 <= _response.status_code < 300:
|
|
601
|
-
return pydantic.parse_obj_as(Feedback, _response.json()) # type: ignore
|
|
602
|
-
if _response.status_code == 422:
|
|
603
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
604
|
-
try:
|
|
605
|
-
_response_json = _response.json()
|
|
606
|
-
except JSONDecodeError:
|
|
607
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
608
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
class AsyncObservabilityClient:
|
|
612
|
-
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
613
|
-
self._client_wrapper = client_wrapper
|
|
614
|
-
|
|
615
|
-
async def dashboard(
|
|
616
|
-
self,
|
|
617
|
-
*,
|
|
618
|
-
app_id: str,
|
|
619
|
-
time_range: typing.Optional[str] = None,
|
|
620
|
-
environment: typing.Optional[str] = None,
|
|
621
|
-
variant: typing.Optional[str] = None,
|
|
622
|
-
) -> typing.Any:
|
|
623
|
-
"""
|
|
624
|
-
Parameters:
|
|
625
|
-
- app_id: str.
|
|
626
|
-
|
|
627
|
-
- time_range: typing.Optional[str].
|
|
628
|
-
|
|
629
|
-
- environment: typing.Optional[str].
|
|
630
|
-
|
|
631
|
-
- variant: typing.Optional[str].
|
|
632
|
-
---
|
|
633
|
-
from agenta.client import AsyncAgentaApi
|
|
634
|
-
|
|
635
|
-
client = AsyncAgentaApi(
|
|
636
|
-
api_key="YOUR_API_KEY",
|
|
637
|
-
base_url="https://yourhost.com/path/to/api",
|
|
638
|
-
)
|
|
639
|
-
await client.observability.dashboard(
|
|
640
|
-
app_id="app_id",
|
|
641
|
-
)
|
|
642
|
-
"""
|
|
643
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
644
|
-
"GET",
|
|
645
|
-
urllib.parse.urljoin(
|
|
646
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/dashboard"
|
|
647
|
-
),
|
|
648
|
-
params=remove_none_from_dict(
|
|
649
|
-
{
|
|
650
|
-
"app_id": app_id,
|
|
651
|
-
"timeRange": time_range,
|
|
652
|
-
"environment": environment,
|
|
653
|
-
"variant": variant,
|
|
654
|
-
}
|
|
655
|
-
),
|
|
656
|
-
headers=self._client_wrapper.get_headers(),
|
|
657
|
-
timeout=60,
|
|
658
|
-
)
|
|
659
|
-
if 200 <= _response.status_code < 300:
|
|
660
|
-
return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
|
661
|
-
if _response.status_code == 422:
|
|
662
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
663
|
-
try:
|
|
664
|
-
_response_json = _response.json()
|
|
665
|
-
except JSONDecodeError:
|
|
666
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
667
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
668
|
-
|
|
669
|
-
async def get_traces(
|
|
670
|
-
self,
|
|
671
|
-
*,
|
|
672
|
-
app_id: str,
|
|
673
|
-
page: typing.Optional[int] = None,
|
|
674
|
-
page_size: typing.Optional[int] = None,
|
|
675
|
-
type: typing.Optional[str] = None,
|
|
676
|
-
trace_id: typing.Optional[str] = None,
|
|
677
|
-
environment: typing.Optional[str] = None,
|
|
678
|
-
variant: typing.Optional[str] = None,
|
|
679
|
-
created_at: typing.Optional[str] = None,
|
|
680
|
-
) -> WithPagination:
|
|
681
|
-
"""
|
|
682
|
-
Parameters:
|
|
683
|
-
- app_id: str.
|
|
684
|
-
|
|
685
|
-
- page: typing.Optional[int].
|
|
686
|
-
|
|
687
|
-
- page_size: typing.Optional[int].
|
|
688
|
-
|
|
689
|
-
- type: typing.Optional[str].
|
|
690
|
-
|
|
691
|
-
- trace_id: typing.Optional[str].
|
|
692
|
-
|
|
693
|
-
- environment: typing.Optional[str].
|
|
694
|
-
|
|
695
|
-
- variant: typing.Optional[str].
|
|
696
|
-
|
|
697
|
-
- created_at: typing.Optional[str].
|
|
698
|
-
---
|
|
699
|
-
from agenta.client import AsyncAgentaApi
|
|
700
|
-
|
|
701
|
-
client = AsyncAgentaApi(
|
|
702
|
-
api_key="YOUR_API_KEY",
|
|
703
|
-
base_url="https://yourhost.com/path/to/api",
|
|
704
|
-
)
|
|
705
|
-
await client.observability.get_traces(
|
|
706
|
-
app_id="app_id",
|
|
707
|
-
)
|
|
708
|
-
"""
|
|
709
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
710
|
-
"GET",
|
|
711
|
-
urllib.parse.urljoin(
|
|
712
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/traces"
|
|
713
|
-
),
|
|
714
|
-
params=remove_none_from_dict(
|
|
715
|
-
{
|
|
716
|
-
"app_id": app_id,
|
|
717
|
-
"page": page,
|
|
718
|
-
"pageSize": page_size,
|
|
719
|
-
"type": type,
|
|
720
|
-
"trace_id": trace_id,
|
|
721
|
-
"environment": environment,
|
|
722
|
-
"variant": variant,
|
|
723
|
-
"created_at": created_at,
|
|
724
|
-
}
|
|
725
|
-
),
|
|
726
|
-
headers=self._client_wrapper.get_headers(),
|
|
727
|
-
timeout=60,
|
|
728
|
-
)
|
|
729
|
-
if 200 <= _response.status_code < 300:
|
|
730
|
-
return pydantic.parse_obj_as(WithPagination, _response.json()) # type: ignore
|
|
731
|
-
if _response.status_code == 422:
|
|
732
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
733
|
-
try:
|
|
734
|
-
_response_json = _response.json()
|
|
735
|
-
except JSONDecodeError:
|
|
736
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
737
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
738
|
-
|
|
739
|
-
async def create_traces(
|
|
740
|
-
self, *, trace: str, spans: typing.List[CreateSpan]
|
|
741
|
-
) -> CreateTraceResponse:
|
|
742
|
-
"""
|
|
743
|
-
Parameters:
|
|
744
|
-
- trace: str.
|
|
745
|
-
|
|
746
|
-
- spans: typing.List[CreateSpan].
|
|
747
|
-
---
|
|
748
|
-
import datetime
|
|
749
|
-
|
|
750
|
-
from agenta import CreateSpan, SpanKind, SpanStatusCode
|
|
751
|
-
from agenta.client import AsyncAgentaApi
|
|
752
|
-
|
|
753
|
-
client = AsyncAgentaApi(
|
|
754
|
-
api_key="YOUR_API_KEY",
|
|
755
|
-
base_url="https://yourhost.com/path/to/api",
|
|
756
|
-
)
|
|
757
|
-
await client.observability.create_traces(
|
|
758
|
-
trace="trace",
|
|
759
|
-
spans=[
|
|
760
|
-
CreateSpan(
|
|
761
|
-
id="id",
|
|
762
|
-
name="name",
|
|
763
|
-
spankind=SpanKind.TOOL,
|
|
764
|
-
status=SpanStatusCode.UNSET,
|
|
765
|
-
start_time=datetime.datetime.fromisoformat(
|
|
766
|
-
"2024-01-15 09:30:00+00:00",
|
|
767
|
-
),
|
|
768
|
-
end_time=datetime.datetime.fromisoformat(
|
|
769
|
-
"2024-01-15 09:30:00+00:00",
|
|
770
|
-
),
|
|
771
|
-
)
|
|
772
|
-
],
|
|
773
|
-
)
|
|
774
|
-
"""
|
|
775
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
776
|
-
"POST",
|
|
777
|
-
urllib.parse.urljoin(
|
|
778
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/trace/"
|
|
779
|
-
),
|
|
780
|
-
json=jsonable_encoder({"trace": trace, "spans": spans}),
|
|
781
|
-
headers=self._client_wrapper.get_headers(),
|
|
782
|
-
timeout=60,
|
|
783
|
-
)
|
|
784
|
-
if 200 <= _response.status_code < 300:
|
|
785
|
-
return pydantic.parse_obj_as(CreateTraceResponse, _response.json()) # type: ignore
|
|
786
|
-
if _response.status_code == 422:
|
|
787
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
788
|
-
try:
|
|
789
|
-
_response_json = _response.json()
|
|
790
|
-
except JSONDecodeError:
|
|
791
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
792
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
793
|
-
|
|
794
|
-
async def delete_traces(self, *, request: typing.List[str]) -> bool:
|
|
795
|
-
"""
|
|
796
|
-
Parameters:
|
|
797
|
-
- request: typing.List[str].
|
|
798
|
-
---
|
|
799
|
-
from agenta.client import AsyncAgentaApi
|
|
800
|
-
|
|
801
|
-
client = AsyncAgentaApi(
|
|
802
|
-
api_key="YOUR_API_KEY",
|
|
803
|
-
base_url="https://yourhost.com/path/to/api",
|
|
804
|
-
)
|
|
805
|
-
await client.observability.delete_traces(
|
|
806
|
-
request=["string"],
|
|
807
|
-
)
|
|
808
|
-
"""
|
|
809
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
810
|
-
"DELETE",
|
|
811
|
-
urllib.parse.urljoin(
|
|
812
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/traces"
|
|
813
|
-
),
|
|
814
|
-
json=jsonable_encoder(request),
|
|
815
|
-
headers=self._client_wrapper.get_headers(),
|
|
816
|
-
timeout=60,
|
|
817
|
-
)
|
|
818
|
-
if 200 <= _response.status_code < 300:
|
|
819
|
-
return pydantic.parse_obj_as(bool, _response.json()) # type: ignore
|
|
820
|
-
if _response.status_code == 422:
|
|
821
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
822
|
-
try:
|
|
823
|
-
_response_json = _response.json()
|
|
824
|
-
except JSONDecodeError:
|
|
825
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
826
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
827
|
-
|
|
828
|
-
async def get_trace_detail(self, trace_id: str) -> TraceDetail:
|
|
829
|
-
"""
|
|
830
|
-
Parameters:
|
|
831
|
-
- trace_id: str.
|
|
832
|
-
---
|
|
833
|
-
from agenta.client import AsyncAgentaApi
|
|
834
|
-
|
|
835
|
-
client = AsyncAgentaApi(
|
|
836
|
-
api_key="YOUR_API_KEY",
|
|
837
|
-
base_url="https://yourhost.com/path/to/api",
|
|
838
|
-
)
|
|
839
|
-
await client.observability.get_trace_detail(
|
|
840
|
-
trace_id="trace_id",
|
|
841
|
-
)
|
|
842
|
-
"""
|
|
843
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
844
|
-
"GET",
|
|
845
|
-
urllib.parse.urljoin(
|
|
846
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
847
|
-
f"observability/traces/{trace_id}",
|
|
848
|
-
),
|
|
849
|
-
headers=self._client_wrapper.get_headers(),
|
|
850
|
-
timeout=60,
|
|
851
|
-
)
|
|
852
|
-
if 200 <= _response.status_code < 300:
|
|
853
|
-
return pydantic.parse_obj_as(TraceDetail, _response.json()) # type: ignore
|
|
854
|
-
if _response.status_code == 422:
|
|
855
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
856
|
-
try:
|
|
857
|
-
_response_json = _response.json()
|
|
858
|
-
except JSONDecodeError:
|
|
859
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
860
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
861
|
-
|
|
862
|
-
async def get_spans_of_generation(
|
|
863
|
-
self,
|
|
864
|
-
*,
|
|
865
|
-
app_id: str,
|
|
866
|
-
page: typing.Optional[int] = None,
|
|
867
|
-
page_size: typing.Optional[int] = None,
|
|
868
|
-
type: typing.Optional[str] = None,
|
|
869
|
-
trace_id: typing.Optional[str] = None,
|
|
870
|
-
environment: typing.Optional[str] = None,
|
|
871
|
-
variant: typing.Optional[str] = None,
|
|
872
|
-
created_at: typing.Optional[str] = None,
|
|
873
|
-
) -> typing.Any:
|
|
874
|
-
"""
|
|
875
|
-
Parameters:
|
|
876
|
-
- app_id: str.
|
|
877
|
-
|
|
878
|
-
- page: typing.Optional[int].
|
|
879
|
-
|
|
880
|
-
- page_size: typing.Optional[int].
|
|
881
|
-
|
|
882
|
-
- type: typing.Optional[str].
|
|
883
|
-
|
|
884
|
-
- trace_id: typing.Optional[str].
|
|
885
|
-
|
|
886
|
-
- environment: typing.Optional[str].
|
|
887
|
-
|
|
888
|
-
- variant: typing.Optional[str].
|
|
889
|
-
|
|
890
|
-
- created_at: typing.Optional[str].
|
|
891
|
-
---
|
|
892
|
-
from agenta.client import AsyncAgentaApi
|
|
893
|
-
|
|
894
|
-
client = AsyncAgentaApi(
|
|
895
|
-
api_key="YOUR_API_KEY",
|
|
896
|
-
base_url="https://yourhost.com/path/to/api",
|
|
897
|
-
)
|
|
898
|
-
await client.observability.get_spans_of_generation(
|
|
899
|
-
app_id="app_id",
|
|
900
|
-
)
|
|
901
|
-
"""
|
|
902
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
903
|
-
"GET",
|
|
904
|
-
urllib.parse.urljoin(
|
|
905
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/spans"
|
|
906
|
-
),
|
|
907
|
-
params=remove_none_from_dict(
|
|
908
|
-
{
|
|
909
|
-
"app_id": app_id,
|
|
910
|
-
"page": page,
|
|
911
|
-
"pageSize": page_size,
|
|
912
|
-
"type": type,
|
|
913
|
-
"trace_id": trace_id,
|
|
914
|
-
"environment": environment,
|
|
915
|
-
"variant": variant,
|
|
916
|
-
"created_at": created_at,
|
|
917
|
-
}
|
|
918
|
-
),
|
|
919
|
-
headers=self._client_wrapper.get_headers(),
|
|
920
|
-
timeout=60,
|
|
921
|
-
)
|
|
922
|
-
if 200 <= _response.status_code < 300:
|
|
923
|
-
return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
|
|
924
|
-
if _response.status_code == 422:
|
|
925
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
926
|
-
try:
|
|
927
|
-
_response_json = _response.json()
|
|
928
|
-
except JSONDecodeError:
|
|
929
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
930
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
931
|
-
|
|
932
|
-
async def delete_spans_of_trace(self, *, request: typing.List[str]) -> bool:
|
|
933
|
-
"""
|
|
934
|
-
Parameters:
|
|
935
|
-
- request: typing.List[str].
|
|
936
|
-
---
|
|
937
|
-
from agenta.client import AsyncAgentaApi
|
|
938
|
-
|
|
939
|
-
client = AsyncAgentaApi(
|
|
940
|
-
api_key="YOUR_API_KEY",
|
|
941
|
-
base_url="https://yourhost.com/path/to/api",
|
|
942
|
-
)
|
|
943
|
-
await client.observability.delete_spans_of_trace(
|
|
944
|
-
request=["string"],
|
|
945
|
-
)
|
|
946
|
-
"""
|
|
947
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
948
|
-
"DELETE",
|
|
949
|
-
urllib.parse.urljoin(
|
|
950
|
-
f"{self._client_wrapper.get_base_url()}/", "observability/spans"
|
|
951
|
-
),
|
|
952
|
-
json=jsonable_encoder(request),
|
|
953
|
-
headers=self._client_wrapper.get_headers(),
|
|
954
|
-
timeout=60,
|
|
955
|
-
)
|
|
956
|
-
if 200 <= _response.status_code < 300:
|
|
957
|
-
return pydantic.parse_obj_as(bool, _response.json()) # type: ignore
|
|
958
|
-
if _response.status_code == 422:
|
|
959
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
960
|
-
try:
|
|
961
|
-
_response_json = _response.json()
|
|
962
|
-
except JSONDecodeError:
|
|
963
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
964
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
965
|
-
|
|
966
|
-
async def get_span_of_generation(
|
|
967
|
-
self, span_id: str, *, type: typing.Optional[str] = None
|
|
968
|
-
) -> SpanDetail:
|
|
969
|
-
"""
|
|
970
|
-
Parameters:
|
|
971
|
-
- span_id: str.
|
|
972
|
-
|
|
973
|
-
- type: typing.Optional[str].
|
|
974
|
-
---
|
|
975
|
-
from agenta.client import AsyncAgentaApi
|
|
976
|
-
|
|
977
|
-
client = AsyncAgentaApi(
|
|
978
|
-
api_key="YOUR_API_KEY",
|
|
979
|
-
base_url="https://yourhost.com/path/to/api",
|
|
980
|
-
)
|
|
981
|
-
await client.observability.get_span_of_generation(
|
|
982
|
-
span_id="span_id",
|
|
983
|
-
)
|
|
984
|
-
"""
|
|
985
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
986
|
-
"GET",
|
|
987
|
-
urllib.parse.urljoin(
|
|
988
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
989
|
-
f"observability/spans/{span_id}",
|
|
990
|
-
),
|
|
991
|
-
params=remove_none_from_dict({"type": type}),
|
|
992
|
-
headers=self._client_wrapper.get_headers(),
|
|
993
|
-
timeout=60,
|
|
994
|
-
)
|
|
995
|
-
if 200 <= _response.status_code < 300:
|
|
996
|
-
return pydantic.parse_obj_as(SpanDetail, _response.json()) # type: ignore
|
|
997
|
-
if _response.status_code == 422:
|
|
998
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
999
|
-
try:
|
|
1000
|
-
_response_json = _response.json()
|
|
1001
|
-
except JSONDecodeError:
|
|
1002
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1003
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1004
|
-
|
|
1005
|
-
async def get_feedbacks(self, trace_id: str) -> typing.List[Feedback]:
|
|
1006
|
-
"""
|
|
1007
|
-
Parameters:
|
|
1008
|
-
- trace_id: str.
|
|
1009
|
-
---
|
|
1010
|
-
from agenta.client import AsyncAgentaApi
|
|
1011
|
-
|
|
1012
|
-
client = AsyncAgentaApi(
|
|
1013
|
-
api_key="YOUR_API_KEY",
|
|
1014
|
-
base_url="https://yourhost.com/path/to/api",
|
|
1015
|
-
)
|
|
1016
|
-
await client.observability.get_feedbacks(
|
|
1017
|
-
trace_id="trace_id",
|
|
1018
|
-
)
|
|
1019
|
-
"""
|
|
1020
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1021
|
-
"GET",
|
|
1022
|
-
urllib.parse.urljoin(
|
|
1023
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
1024
|
-
f"observability/feedbacks/{trace_id}",
|
|
1025
|
-
),
|
|
1026
|
-
headers=self._client_wrapper.get_headers(),
|
|
1027
|
-
timeout=60,
|
|
1028
|
-
)
|
|
1029
|
-
if 200 <= _response.status_code < 300:
|
|
1030
|
-
return pydantic.parse_obj_as(typing.List[Feedback], _response.json()) # type: ignore
|
|
1031
|
-
if _response.status_code == 422:
|
|
1032
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
1033
|
-
try:
|
|
1034
|
-
_response_json = _response.json()
|
|
1035
|
-
except JSONDecodeError:
|
|
1036
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1037
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1038
|
-
|
|
1039
|
-
async def create_feedback(
|
|
1040
|
-
self,
|
|
1041
|
-
trace_id: str,
|
|
1042
|
-
*,
|
|
1043
|
-
feedback: typing.Optional[str] = OMIT,
|
|
1044
|
-
score: typing.Optional[float] = OMIT,
|
|
1045
|
-
meta: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
|
1046
|
-
) -> str:
|
|
1047
|
-
"""
|
|
1048
|
-
Parameters:
|
|
1049
|
-
- trace_id: str.
|
|
1050
|
-
|
|
1051
|
-
- feedback: typing.Optional[str].
|
|
1052
|
-
|
|
1053
|
-
- score: typing.Optional[float].
|
|
1054
|
-
|
|
1055
|
-
- meta: typing.Optional[typing.Dict[str, typing.Any]].
|
|
1056
|
-
---
|
|
1057
|
-
from agenta.client import AsyncAgentaApi
|
|
1058
|
-
|
|
1059
|
-
client = AsyncAgentaApi(
|
|
1060
|
-
api_key="YOUR_API_KEY",
|
|
1061
|
-
base_url="https://yourhost.com/path/to/api",
|
|
1062
|
-
)
|
|
1063
|
-
await client.observability.create_feedback(
|
|
1064
|
-
trace_id="trace_id",
|
|
1065
|
-
)
|
|
1066
|
-
"""
|
|
1067
|
-
_request: typing.Dict[str, typing.Any] = {}
|
|
1068
|
-
if feedback is not OMIT:
|
|
1069
|
-
_request["feedback"] = feedback
|
|
1070
|
-
if score is not OMIT:
|
|
1071
|
-
_request["score"] = score
|
|
1072
|
-
if meta is not OMIT:
|
|
1073
|
-
_request["meta"] = meta
|
|
1074
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1075
|
-
"POST",
|
|
1076
|
-
urllib.parse.urljoin(
|
|
1077
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
1078
|
-
f"observability/feedbacks/{trace_id}",
|
|
1079
|
-
),
|
|
1080
|
-
json=jsonable_encoder(_request),
|
|
1081
|
-
headers=self._client_wrapper.get_headers(),
|
|
1082
|
-
timeout=60,
|
|
1083
|
-
)
|
|
1084
|
-
if 200 <= _response.status_code < 300:
|
|
1085
|
-
return pydantic.parse_obj_as(str, _response.json()) # type: ignore
|
|
1086
|
-
if _response.status_code == 422:
|
|
1087
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
1088
|
-
try:
|
|
1089
|
-
_response_json = _response.json()
|
|
1090
|
-
except JSONDecodeError:
|
|
1091
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1092
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1093
|
-
|
|
1094
|
-
async def get_feedback(self, trace_id: str, feedback_id: str) -> Feedback:
|
|
1095
|
-
"""
|
|
1096
|
-
Parameters:
|
|
1097
|
-
- trace_id: str.
|
|
1098
|
-
|
|
1099
|
-
- feedback_id: str.
|
|
1100
|
-
---
|
|
1101
|
-
from agenta.client import AsyncAgentaApi
|
|
1102
|
-
|
|
1103
|
-
client = AsyncAgentaApi(
|
|
1104
|
-
api_key="YOUR_API_KEY",
|
|
1105
|
-
base_url="https://yourhost.com/path/to/api",
|
|
1106
|
-
)
|
|
1107
|
-
await client.observability.get_feedback(
|
|
1108
|
-
trace_id="trace_id",
|
|
1109
|
-
feedback_id="feedback_id",
|
|
1110
|
-
)
|
|
1111
|
-
"""
|
|
1112
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1113
|
-
"GET",
|
|
1114
|
-
urllib.parse.urljoin(
|
|
1115
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
1116
|
-
f"observability/feedbacks/{trace_id}/{feedback_id}",
|
|
1117
|
-
),
|
|
1118
|
-
headers=self._client_wrapper.get_headers(),
|
|
1119
|
-
timeout=60,
|
|
1120
|
-
)
|
|
1121
|
-
if 200 <= _response.status_code < 300:
|
|
1122
|
-
return pydantic.parse_obj_as(Feedback, _response.json()) # type: ignore
|
|
1123
|
-
if _response.status_code == 422:
|
|
1124
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
1125
|
-
try:
|
|
1126
|
-
_response_json = _response.json()
|
|
1127
|
-
except JSONDecodeError:
|
|
1128
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1129
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1130
|
-
|
|
1131
|
-
async def update_feedback(
|
|
1132
|
-
self,
|
|
1133
|
-
trace_id: str,
|
|
1134
|
-
feedback_id: str,
|
|
1135
|
-
*,
|
|
1136
|
-
feedback: str,
|
|
1137
|
-
score: typing.Optional[float] = OMIT,
|
|
1138
|
-
meta: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
|
|
1139
|
-
) -> Feedback:
|
|
1140
|
-
"""
|
|
1141
|
-
Parameters:
|
|
1142
|
-
- trace_id: str.
|
|
1143
|
-
|
|
1144
|
-
- feedback_id: str.
|
|
1145
|
-
|
|
1146
|
-
- feedback: str.
|
|
1147
|
-
|
|
1148
|
-
- score: typing.Optional[float].
|
|
1149
|
-
|
|
1150
|
-
- meta: typing.Optional[typing.Dict[str, typing.Any]].
|
|
1151
|
-
---
|
|
1152
|
-
from agenta.client import AsyncAgentaApi
|
|
1153
|
-
|
|
1154
|
-
client = AsyncAgentaApi(
|
|
1155
|
-
api_key="YOUR_API_KEY",
|
|
1156
|
-
base_url="https://yourhost.com/path/to/api",
|
|
1157
|
-
)
|
|
1158
|
-
await client.observability.update_feedback(
|
|
1159
|
-
trace_id="trace_id",
|
|
1160
|
-
feedback_id="feedback_id",
|
|
1161
|
-
feedback="feedback",
|
|
1162
|
-
)
|
|
1163
|
-
"""
|
|
1164
|
-
_request: typing.Dict[str, typing.Any] = {"feedback": feedback}
|
|
1165
|
-
if score is not OMIT:
|
|
1166
|
-
_request["score"] = score
|
|
1167
|
-
if meta is not OMIT:
|
|
1168
|
-
_request["meta"] = meta
|
|
1169
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1170
|
-
"PUT",
|
|
1171
|
-
urllib.parse.urljoin(
|
|
1172
|
-
f"{self._client_wrapper.get_base_url()}/",
|
|
1173
|
-
f"observability/feedbacks/{trace_id}/{feedback_id}",
|
|
1174
|
-
),
|
|
1175
|
-
json=jsonable_encoder(_request),
|
|
1176
|
-
headers=self._client_wrapper.get_headers(),
|
|
1177
|
-
timeout=60,
|
|
1178
|
-
)
|
|
1179
|
-
if 200 <= _response.status_code < 300:
|
|
1180
|
-
return pydantic.parse_obj_as(Feedback, _response.json()) # type: ignore
|
|
1181
|
-
if _response.status_code == 422:
|
|
1182
|
-
raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
|
|
1183
|
-
try:
|
|
1184
|
-
_response_json = _response.json()
|
|
1185
|
-
except JSONDecodeError:
|
|
1186
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1187
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|