agenta 0.24.1a0__py3-none-any.whl → 0.24.2a1__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.

Files changed (132) hide show
  1. agenta/cli/variant_commands.py +15 -10
  2. agenta/client/Readme.md +72 -64
  3. agenta/client/api.py +1 -1
  4. agenta/client/backend/__init__.py +14 -9
  5. agenta/client/backend/apps/client.py +1669 -0
  6. agenta/client/backend/bases/client.py +190 -0
  7. agenta/client/backend/client.py +2102 -868
  8. agenta/client/backend/configs/client.py +598 -0
  9. agenta/client/backend/containers/client.py +638 -0
  10. agenta/client/backend/{resources/containers → containers}/types/container_templates_response.py +1 -2
  11. agenta/client/backend/core/__init__.py +29 -0
  12. agenta/client/backend/core/client_wrapper.py +42 -9
  13. agenta/client/backend/core/datetime_utils.py +1 -1
  14. agenta/client/backend/core/file.py +43 -0
  15. agenta/client/backend/core/http_client.py +553 -0
  16. agenta/client/backend/core/jsonable_encoder.py +33 -39
  17. agenta/client/backend/core/pydantic_utilities.py +212 -0
  18. agenta/client/backend/core/query_encoder.py +60 -0
  19. agenta/client/backend/core/remove_none_from_dict.py +2 -2
  20. agenta/client/backend/core/request_options.py +32 -0
  21. agenta/client/backend/core/serialization.py +179 -0
  22. agenta/client/backend/environments/client.py +190 -0
  23. agenta/client/backend/evaluations/client.py +1462 -0
  24. agenta/client/backend/evaluators/client.py +911 -0
  25. agenta/client/backend/observability/client.py +1271 -0
  26. agenta/client/backend/testsets/client.py +1132 -0
  27. agenta/client/backend/types/__init__.py +8 -6
  28. agenta/client/backend/types/aggregated_result.py +14 -29
  29. agenta/client/backend/types/aggregated_result_evaluator_config.py +1 -2
  30. agenta/client/backend/types/app.py +13 -28
  31. agenta/client/backend/types/app_variant_response.py +21 -37
  32. agenta/client/backend/types/app_variant_revision.py +17 -32
  33. agenta/client/backend/types/base_output.py +13 -28
  34. agenta/client/backend/types/body_import_testset.py +16 -31
  35. agenta/client/backend/types/config_db.py +16 -31
  36. agenta/client/backend/types/correct_answer.py +22 -0
  37. agenta/client/backend/types/create_app_output.py +13 -28
  38. agenta/client/backend/types/create_span.py +33 -50
  39. agenta/client/backend/types/create_trace_response.py +16 -31
  40. agenta/client/backend/types/docker_env_vars.py +13 -28
  41. agenta/client/backend/types/environment_output.py +21 -36
  42. agenta/client/backend/types/environment_output_extended.py +21 -36
  43. agenta/client/backend/types/environment_revision.py +18 -33
  44. agenta/client/backend/types/error.py +16 -31
  45. agenta/client/backend/types/evaluation.py +20 -34
  46. agenta/client/backend/types/evaluation_scenario.py +18 -33
  47. agenta/client/backend/types/evaluation_scenario_input.py +16 -31
  48. agenta/client/backend/types/evaluation_scenario_output.py +18 -33
  49. agenta/client/backend/types/evaluation_scenario_result.py +14 -29
  50. agenta/client/backend/types/evaluation_scenario_score_update.py +13 -28
  51. agenta/client/backend/types/evaluation_status_enum.py +11 -33
  52. agenta/client/backend/types/evaluation_type.py +3 -21
  53. agenta/client/backend/types/evaluator.py +18 -32
  54. agenta/client/backend/types/evaluator_config.py +20 -33
  55. agenta/client/backend/types/get_config_response.py +16 -31
  56. agenta/client/backend/types/http_validation_error.py +14 -29
  57. agenta/client/backend/types/human_evaluation.py +17 -32
  58. agenta/client/backend/types/human_evaluation_scenario.py +21 -37
  59. agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
  60. agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
  61. agenta/client/backend/types/human_evaluation_scenario_update.py +26 -41
  62. agenta/client/backend/types/human_evaluation_update.py +14 -29
  63. agenta/client/backend/types/image.py +18 -33
  64. agenta/client/backend/types/invite_request.py +13 -28
  65. agenta/client/backend/types/list_api_keys_response.py +18 -33
  66. agenta/client/backend/types/llm_run_rate_limit.py +13 -28
  67. agenta/client/backend/types/llm_tokens.py +16 -31
  68. agenta/client/backend/types/lm_providers_enum.py +21 -0
  69. agenta/client/backend/types/new_human_evaluation.py +13 -28
  70. agenta/client/backend/types/new_testset.py +16 -31
  71. agenta/client/backend/types/organization.py +22 -36
  72. agenta/client/backend/types/organization_output.py +13 -28
  73. agenta/client/backend/types/outputs.py +5 -0
  74. agenta/client/backend/types/permission.py +36 -137
  75. agenta/client/backend/types/result.py +17 -32
  76. agenta/client/backend/types/simple_evaluation_output.py +13 -28
  77. agenta/client/backend/types/span.py +23 -38
  78. agenta/client/backend/types/span_detail.py +26 -40
  79. agenta/client/backend/types/span_status_code.py +1 -25
  80. agenta/client/backend/types/span_variant.py +16 -31
  81. agenta/client/backend/types/template.py +14 -29
  82. agenta/client/backend/types/template_image_info.py +21 -35
  83. agenta/client/backend/types/test_set_output_response.py +16 -32
  84. agenta/client/backend/types/test_set_simple_response.py +13 -28
  85. agenta/client/backend/types/trace_detail.py +26 -40
  86. agenta/client/backend/types/update_app_output.py +22 -0
  87. agenta/client/backend/types/uri.py +13 -28
  88. agenta/client/backend/types/validation_error.py +13 -28
  89. agenta/client/backend/types/variant_action.py +14 -29
  90. agenta/client/backend/types/variant_action_enum.py +1 -19
  91. agenta/client/backend/types/with_pagination.py +14 -30
  92. agenta/client/backend/types/workspace_member_response.py +14 -29
  93. agenta/client/backend/types/workspace_permission.py +18 -33
  94. agenta/client/backend/types/workspace_response.py +20 -35
  95. agenta/client/backend/types/workspace_role.py +11 -37
  96. agenta/client/backend/types/workspace_role_response.py +17 -32
  97. agenta/client/backend/variants/client.py +1447 -0
  98. agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
  99. agenta/sdk/decorators/llm_entrypoint.py +8 -13
  100. agenta/sdk/tracing/llm_tracing.py +1 -1
  101. {agenta-0.24.1a0.dist-info → agenta-0.24.2a1.dist-info}/METADATA +1 -1
  102. agenta-0.24.2a1.dist-info/RECORD +175 -0
  103. agenta/client/backend/resources/__init__.py +0 -31
  104. agenta/client/backend/resources/apps/client.py +0 -977
  105. agenta/client/backend/resources/bases/client.py +0 -127
  106. agenta/client/backend/resources/configs/client.py +0 -377
  107. agenta/client/backend/resources/containers/client.py +0 -383
  108. agenta/client/backend/resources/environments/client.py +0 -131
  109. agenta/client/backend/resources/evaluations/client.py +0 -1008
  110. agenta/client/backend/resources/evaluators/client.py +0 -594
  111. agenta/client/backend/resources/observability/client.py +0 -1187
  112. agenta/client/backend/resources/testsets/client.py +0 -689
  113. agenta/client/backend/resources/variants/client.py +0 -796
  114. agenta/client/backend/resources/variants/types/add_variant_from_base_and_config_response.py +0 -7
  115. agenta/client/backend/types/evaluation_webhook.py +0 -36
  116. agenta/client/backend/types/feedback.py +0 -40
  117. agenta/client/backend/types/span_kind.py +0 -49
  118. agenta-0.24.1a0.dist-info/RECORD +0 -169
  119. /agenta/client/backend/{resources/apps → apps}/__init__.py +0 -0
  120. /agenta/client/backend/{resources/bases → bases}/__init__.py +0 -0
  121. /agenta/client/backend/{resources/configs → configs}/__init__.py +0 -0
  122. /agenta/client/backend/{resources/containers → containers}/__init__.py +0 -0
  123. /agenta/client/backend/{resources/containers → containers}/types/__init__.py +0 -0
  124. /agenta/client/backend/{resources/environments → environments}/__init__.py +0 -0
  125. /agenta/client/backend/{resources/evaluations → evaluations}/__init__.py +0 -0
  126. /agenta/client/backend/{resources/evaluators → evaluators}/__init__.py +0 -0
  127. /agenta/client/backend/{resources/observability → observability}/__init__.py +0 -0
  128. /agenta/client/backend/{resources/testsets → testsets}/__init__.py +0 -0
  129. /agenta/client/backend/{resources/variants → variants}/__init__.py +0 -0
  130. /agenta/client/backend/{resources/variants → variants}/types/__init__.py +0 -0
  131. {agenta-0.24.1a0.dist-info → agenta-0.24.2a1.dist-info}/WHEEL +0 -0
  132. {agenta-0.24.1a0.dist-info → agenta-0.24.2a1.dist-info}/entry_points.txt +0 -0
@@ -1,1008 +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.evaluation import Evaluation
13
- from ...types.evaluation_scenario import EvaluationScenario
14
- from ...types.evaluation_webhook import EvaluationWebhook
15
- from ...types.http_validation_error import HttpValidationError
16
- from ...types.llm_run_rate_limit import LlmRunRateLimit
17
-
18
- try:
19
- import pydantic.v1 as pydantic # type: ignore
20
- except ImportError:
21
- import pydantic # type: ignore
22
-
23
- # this is used as the default value for optional parameters
24
- OMIT = typing.cast(typing.Any, ...)
25
-
26
-
27
- class EvaluationsClient:
28
- def __init__(self, *, client_wrapper: SyncClientWrapper):
29
- self._client_wrapper = client_wrapper
30
-
31
- def fetch_evaluation_ids(
32
- self,
33
- *,
34
- app_id: str,
35
- resource_type: str,
36
- resource_ids: typing.Optional[typing.Union[str, typing.List[str]]] = None,
37
- ) -> typing.List[str]:
38
- """
39
- Fetches evaluation ids for a given resource type and id.
40
-
41
- Arguments:
42
- app_id (str): The ID of the app for which to fetch evaluations.
43
- resource_type (str): The type of resource for which to fetch evaluations.
44
- resource_ids List[ObjectId]: The IDs of resource for which to fetch evaluations.
45
-
46
- Raises:
47
- HTTPException: If the resource_type is invalid or access is denied.
48
-
49
- Returns:
50
- List[str]: A list of evaluation ids.
51
-
52
- Parameters:
53
- - app_id: str.
54
-
55
- - resource_type: str.
56
-
57
- - resource_ids: typing.Optional[typing.Union[str, typing.List[str]]].
58
- ---
59
- from agenta.client import AgentaApi
60
-
61
- client = AgentaApi(
62
- api_key="YOUR_API_KEY",
63
- base_url="https://yourhost.com/path/to/api",
64
- )
65
- client.evaluations.fetch_evaluation_ids(
66
- app_id="app_id",
67
- resource_type="resource_type",
68
- )
69
- """
70
- _response = self._client_wrapper.httpx_client.request(
71
- "GET",
72
- urllib.parse.urljoin(
73
- f"{self._client_wrapper.get_base_url()}/", "evaluations/by_resource"
74
- ),
75
- params=remove_none_from_dict(
76
- {
77
- "app_id": app_id,
78
- "resource_type": resource_type,
79
- "resource_ids": resource_ids,
80
- }
81
- ),
82
- headers=self._client_wrapper.get_headers(),
83
- timeout=60,
84
- )
85
- if 200 <= _response.status_code < 300:
86
- return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
87
- if _response.status_code == 422:
88
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
89
- try:
90
- _response_json = _response.json()
91
- except JSONDecodeError:
92
- raise ApiError(status_code=_response.status_code, body=_response.text)
93
- raise ApiError(status_code=_response.status_code, body=_response_json)
94
-
95
- def fetch_list_evaluations(self, *, app_id: str) -> typing.List[Evaluation]:
96
- """
97
- Fetches a list of evaluations, optionally filtered by an app ID.
98
-
99
- Args:
100
- app_id (Optional[str]): An optional app ID to filter the evaluations.
101
-
102
- Returns:
103
- List[Evaluation]: A list of evaluations.
104
-
105
- Parameters:
106
- - app_id: str.
107
- ---
108
- from agenta.client import AgentaApi
109
-
110
- client = AgentaApi(
111
- api_key="YOUR_API_KEY",
112
- base_url="https://yourhost.com/path/to/api",
113
- )
114
- client.evaluations.fetch_list_evaluations(
115
- app_id="app_id",
116
- )
117
- """
118
- _response = self._client_wrapper.httpx_client.request(
119
- "GET",
120
- urllib.parse.urljoin(
121
- f"{self._client_wrapper.get_base_url()}/", "evaluations"
122
- ),
123
- params=remove_none_from_dict({"app_id": app_id}),
124
- headers=self._client_wrapper.get_headers(),
125
- timeout=60,
126
- )
127
- if 200 <= _response.status_code < 300:
128
- return pydantic.parse_obj_as(typing.List[Evaluation], _response.json()) # type: ignore
129
- if _response.status_code == 422:
130
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
131
- try:
132
- _response_json = _response.json()
133
- except JSONDecodeError:
134
- raise ApiError(status_code=_response.status_code, body=_response.text)
135
- raise ApiError(status_code=_response.status_code, body=_response_json)
136
-
137
- def create_evaluation(
138
- self,
139
- *,
140
- app_id: str,
141
- variant_ids: typing.List[str],
142
- evaluators_configs: typing.List[str],
143
- testset_id: str,
144
- rate_limit: LlmRunRateLimit,
145
- lm_providers_keys: typing.Optional[typing.Dict[str, str]] = OMIT,
146
- correct_answer_column: typing.Optional[str] = OMIT,
147
- ) -> typing.List[Evaluation]:
148
- """
149
- Creates a new comparison table document
150
- Raises:
151
- HTTPException: _description_
152
- Returns:
153
- _description_
154
-
155
- Parameters:
156
- - app_id: str.
157
-
158
- - variant_ids: typing.List[str].
159
-
160
- - evaluators_configs: typing.List[str].
161
-
162
- - testset_id: str.
163
-
164
- - rate_limit: LlmRunRateLimit.
165
-
166
- - lm_providers_keys: typing.Optional[typing.Dict[str, str]].
167
-
168
- - correct_answer_column: typing.Optional[str].
169
- ---
170
- from agenta import LlmRunRateLimit
171
- from agenta.client import AgentaApi
172
-
173
- client = AgentaApi(
174
- api_key="YOUR_API_KEY",
175
- base_url="https://yourhost.com/path/to/api",
176
- )
177
- client.evaluations.create_evaluation(
178
- app_id="app_id",
179
- variant_ids=["variant_ids"],
180
- evaluators_configs=["evaluators_configs"],
181
- testset_id="testset_id",
182
- rate_limit=LlmRunRateLimit(
183
- batch_size=1,
184
- max_retries=1,
185
- retry_delay=1,
186
- delay_between_batches=1,
187
- ),
188
- )
189
- """
190
- _request: typing.Dict[str, typing.Any] = {
191
- "app_id": app_id,
192
- "variant_ids": variant_ids,
193
- "evaluators_configs": evaluators_configs,
194
- "testset_id": testset_id,
195
- "rate_limit": rate_limit,
196
- }
197
- if lm_providers_keys is not OMIT:
198
- _request["lm_providers_keys"] = lm_providers_keys
199
- if correct_answer_column is not OMIT:
200
- _request["correct_answer_column"] = correct_answer_column
201
- _response = self._client_wrapper.httpx_client.request(
202
- "POST",
203
- urllib.parse.urljoin(
204
- f"{self._client_wrapper.get_base_url()}/", "evaluations"
205
- ),
206
- json=jsonable_encoder(_request),
207
- headers=self._client_wrapper.get_headers(),
208
- timeout=60,
209
- )
210
- if 200 <= _response.status_code < 300:
211
- return pydantic.parse_obj_as(typing.List[Evaluation], _response.json()) # type: ignore
212
- if _response.status_code == 422:
213
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
214
- try:
215
- _response_json = _response.json()
216
- except JSONDecodeError:
217
- raise ApiError(status_code=_response.status_code, body=_response.text)
218
- raise ApiError(status_code=_response.status_code, body=_response_json)
219
-
220
- def delete_evaluations(
221
- self, *, evaluations_ids: typing.List[str]
222
- ) -> typing.List[str]:
223
- """
224
- Delete specific comparison tables based on their unique IDs.
225
-
226
- Args:
227
- delete_evaluations (List[str]): The unique identifiers of the comparison tables to delete.
228
-
229
- Returns:
230
- A list of the deleted comparison tables' IDs.
231
-
232
- Parameters:
233
- - evaluations_ids: typing.List[str].
234
- ---
235
- from agenta.client import AgentaApi
236
-
237
- client = AgentaApi(
238
- api_key="YOUR_API_KEY",
239
- base_url="https://yourhost.com/path/to/api",
240
- )
241
- client.evaluations.delete_evaluations(
242
- evaluations_ids=["evaluations_ids"],
243
- )
244
- """
245
- _response = self._client_wrapper.httpx_client.request(
246
- "DELETE",
247
- urllib.parse.urljoin(
248
- f"{self._client_wrapper.get_base_url()}/", "evaluations"
249
- ),
250
- json=jsonable_encoder({"evaluations_ids": evaluations_ids}),
251
- headers=self._client_wrapper.get_headers(),
252
- timeout=60,
253
- )
254
- if 200 <= _response.status_code < 300:
255
- return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
256
- if _response.status_code == 422:
257
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
258
- try:
259
- _response_json = _response.json()
260
- except JSONDecodeError:
261
- raise ApiError(status_code=_response.status_code, body=_response.text)
262
- raise ApiError(status_code=_response.status_code, body=_response_json)
263
-
264
- def fetch_evaluation_status(self, evaluation_id: str) -> typing.Any:
265
- """
266
- Fetches the status of the evaluation.
267
-
268
- Args:
269
- evaluation_id (str): the evaluation id
270
- request (Request): the request object
271
-
272
- Returns:
273
- (str): the evaluation status
274
-
275
- Parameters:
276
- - evaluation_id: str.
277
- ---
278
- from agenta.client import AgentaApi
279
-
280
- client = AgentaApi(
281
- api_key="YOUR_API_KEY",
282
- base_url="https://yourhost.com/path/to/api",
283
- )
284
- client.evaluations.fetch_evaluation_status(
285
- evaluation_id="evaluation_id",
286
- )
287
- """
288
- _response = self._client_wrapper.httpx_client.request(
289
- "GET",
290
- urllib.parse.urljoin(
291
- f"{self._client_wrapper.get_base_url()}/",
292
- f"evaluations/{evaluation_id}/status",
293
- ),
294
- headers=self._client_wrapper.get_headers(),
295
- timeout=60,
296
- )
297
- if 200 <= _response.status_code < 300:
298
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
299
- if _response.status_code == 422:
300
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
301
- try:
302
- _response_json = _response.json()
303
- except JSONDecodeError:
304
- raise ApiError(status_code=_response.status_code, body=_response.text)
305
- raise ApiError(status_code=_response.status_code, body=_response_json)
306
-
307
- def fetch_evaluation_results(self, evaluation_id: str) -> typing.Any:
308
- """
309
- Fetches the results of the evaluation
310
-
311
- Args:
312
- evaluation_id (str): the evaluation id
313
- request (Request): the request object
314
-
315
- Returns:
316
- _type_: _description_
317
-
318
- Parameters:
319
- - evaluation_id: str.
320
- ---
321
- from agenta.client import AgentaApi
322
-
323
- client = AgentaApi(
324
- api_key="YOUR_API_KEY",
325
- base_url="https://yourhost.com/path/to/api",
326
- )
327
- client.evaluations.fetch_evaluation_results(
328
- evaluation_id="evaluation_id",
329
- )
330
- """
331
- _response = self._client_wrapper.httpx_client.request(
332
- "GET",
333
- urllib.parse.urljoin(
334
- f"{self._client_wrapper.get_base_url()}/",
335
- f"evaluations/{evaluation_id}/results",
336
- ),
337
- headers=self._client_wrapper.get_headers(),
338
- timeout=60,
339
- )
340
- if 200 <= _response.status_code < 300:
341
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
342
- if _response.status_code == 422:
343
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
344
- try:
345
- _response_json = _response.json()
346
- except JSONDecodeError:
347
- raise ApiError(status_code=_response.status_code, body=_response.text)
348
- raise ApiError(status_code=_response.status_code, body=_response_json)
349
-
350
- def fetch_evaluation_scenarios(
351
- self, evaluation_id: str
352
- ) -> typing.List[EvaluationScenario]:
353
- """
354
- Fetches evaluation scenarios for a given evaluation ID.
355
-
356
- Arguments:
357
- evaluation_id (str): The ID of the evaluation for which to fetch scenarios.
358
-
359
- Raises:
360
- HTTPException: If the evaluation is not found or access is denied.
361
-
362
- Returns:
363
- List[EvaluationScenario]: A list of evaluation scenarios.
364
-
365
- Parameters:
366
- - evaluation_id: str.
367
- ---
368
- from agenta.client import AgentaApi
369
-
370
- client = AgentaApi(
371
- api_key="YOUR_API_KEY",
372
- base_url="https://yourhost.com/path/to/api",
373
- )
374
- client.evaluations.fetch_evaluation_scenarios(
375
- evaluation_id="evaluation_id",
376
- )
377
- """
378
- _response = self._client_wrapper.httpx_client.request(
379
- "GET",
380
- urllib.parse.urljoin(
381
- f"{self._client_wrapper.get_base_url()}/",
382
- f"evaluations/{evaluation_id}/evaluation_scenarios",
383
- ),
384
- headers=self._client_wrapper.get_headers(),
385
- timeout=60,
386
- )
387
- if 200 <= _response.status_code < 300:
388
- return pydantic.parse_obj_as(typing.List[EvaluationScenario], _response.json()) # type: ignore
389
- if _response.status_code == 422:
390
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
391
- try:
392
- _response_json = _response.json()
393
- except JSONDecodeError:
394
- raise ApiError(status_code=_response.status_code, body=_response.text)
395
- raise ApiError(status_code=_response.status_code, body=_response_json)
396
-
397
- def fetch_evaluation(self, evaluation_id: str) -> Evaluation:
398
- """
399
- Fetches a single evaluation based on its ID.
400
-
401
- Args:
402
- evaluation_id (str): The ID of the evaluation to fetch.
403
-
404
- Returns:
405
- Evaluation: The fetched evaluation.
406
-
407
- Parameters:
408
- - evaluation_id: str.
409
- ---
410
- from agenta.client import AgentaApi
411
-
412
- client = AgentaApi(
413
- api_key="YOUR_API_KEY",
414
- base_url="https://yourhost.com/path/to/api",
415
- )
416
- client.evaluations.fetch_evaluation(
417
- evaluation_id="evaluation_id",
418
- )
419
- """
420
- _response = self._client_wrapper.httpx_client.request(
421
- "GET",
422
- urllib.parse.urljoin(
423
- f"{self._client_wrapper.get_base_url()}/",
424
- f"evaluations/{evaluation_id}",
425
- ),
426
- headers=self._client_wrapper.get_headers(),
427
- timeout=60,
428
- )
429
- if 200 <= _response.status_code < 300:
430
- return pydantic.parse_obj_as(Evaluation, _response.json()) # type: ignore
431
- if _response.status_code == 422:
432
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
433
- try:
434
- _response_json = _response.json()
435
- except JSONDecodeError:
436
- raise ApiError(status_code=_response.status_code, body=_response.text)
437
- raise ApiError(status_code=_response.status_code, body=_response_json)
438
-
439
- def webhook_example_fake(self) -> EvaluationWebhook:
440
- """
441
- Returns a fake score response for example webhook evaluation
442
-
443
- Returns:
444
- _description_
445
-
446
- ---
447
- from agenta.client import AgentaApi
448
-
449
- client = AgentaApi(
450
- api_key="YOUR_API_KEY",
451
- base_url="https://yourhost.com/path/to/api",
452
- )
453
- client.evaluations.webhook_example_fake()
454
- """
455
- _response = self._client_wrapper.httpx_client.request(
456
- "POST",
457
- urllib.parse.urljoin(
458
- f"{self._client_wrapper.get_base_url()}/",
459
- "evaluations/webhook_example_fake",
460
- ),
461
- headers=self._client_wrapper.get_headers(),
462
- timeout=60,
463
- )
464
- if 200 <= _response.status_code < 300:
465
- return pydantic.parse_obj_as(EvaluationWebhook, _response.json()) # type: ignore
466
- try:
467
- _response_json = _response.json()
468
- except JSONDecodeError:
469
- raise ApiError(status_code=_response.status_code, body=_response.text)
470
- raise ApiError(status_code=_response.status_code, body=_response_json)
471
-
472
- def fetch_evaluation_scenarios(self, *, evaluations_ids: str) -> typing.Any:
473
- """
474
- Fetches evaluation scenarios for a given evaluation ID.
475
-
476
- Arguments:
477
- evaluation_id (str): The ID of the evaluation for which to fetch scenarios.
478
-
479
- Raises:
480
- HTTPException: If the evaluation is not found or access is denied.
481
-
482
- Returns:
483
- List[EvaluationScenario]: A list of evaluation scenarios.
484
-
485
- Parameters:
486
- - evaluations_ids: str.
487
- ---
488
- from agenta.client import AgentaApi
489
-
490
- client = AgentaApi(
491
- api_key="YOUR_API_KEY",
492
- base_url="https://yourhost.com/path/to/api",
493
- )
494
- client.evaluations.fetch_evaluation_scenarios(
495
- evaluations_ids="evaluations_ids",
496
- )
497
- """
498
- _response = self._client_wrapper.httpx_client.request(
499
- "GET",
500
- urllib.parse.urljoin(
501
- f"{self._client_wrapper.get_base_url()}/",
502
- "evaluations/evaluation_scenarios/comparison-results",
503
- ),
504
- params=remove_none_from_dict({"evaluations_ids": evaluations_ids}),
505
- headers=self._client_wrapper.get_headers(),
506
- timeout=60,
507
- )
508
- if 200 <= _response.status_code < 300:
509
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
510
- if _response.status_code == 422:
511
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
512
- try:
513
- _response_json = _response.json()
514
- except JSONDecodeError:
515
- raise ApiError(status_code=_response.status_code, body=_response.text)
516
- raise ApiError(status_code=_response.status_code, body=_response_json)
517
-
518
-
519
- class AsyncEvaluationsClient:
520
- def __init__(self, *, client_wrapper: AsyncClientWrapper):
521
- self._client_wrapper = client_wrapper
522
-
523
- async def fetch_evaluation_ids(
524
- self,
525
- *,
526
- app_id: str,
527
- resource_type: str,
528
- resource_ids: typing.Optional[typing.Union[str, typing.List[str]]] = None,
529
- ) -> typing.List[str]:
530
- """
531
- Fetches evaluation ids for a given resource type and id.
532
-
533
- Arguments:
534
- app_id (str): The ID of the app for which to fetch evaluations.
535
- resource_type (str): The type of resource for which to fetch evaluations.
536
- resource_ids List[ObjectId]: The IDs of resource for which to fetch evaluations.
537
-
538
- Raises:
539
- HTTPException: If the resource_type is invalid or access is denied.
540
-
541
- Returns:
542
- List[str]: A list of evaluation ids.
543
-
544
- Parameters:
545
- - app_id: str.
546
-
547
- - resource_type: str.
548
-
549
- - resource_ids: typing.Optional[typing.Union[str, typing.List[str]]].
550
- ---
551
- from agenta.client import AsyncAgentaApi
552
-
553
- client = AsyncAgentaApi(
554
- api_key="YOUR_API_KEY",
555
- base_url="https://yourhost.com/path/to/api",
556
- )
557
- await client.evaluations.fetch_evaluation_ids(
558
- app_id="app_id",
559
- resource_type="resource_type",
560
- )
561
- """
562
- _response = await self._client_wrapper.httpx_client.request(
563
- "GET",
564
- urllib.parse.urljoin(
565
- f"{self._client_wrapper.get_base_url()}/", "evaluations/by_resource"
566
- ),
567
- params=remove_none_from_dict(
568
- {
569
- "app_id": app_id,
570
- "resource_type": resource_type,
571
- "resource_ids": resource_ids,
572
- }
573
- ),
574
- headers=self._client_wrapper.get_headers(),
575
- timeout=60,
576
- )
577
- if 200 <= _response.status_code < 300:
578
- return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
579
- if _response.status_code == 422:
580
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
581
- try:
582
- _response_json = _response.json()
583
- except JSONDecodeError:
584
- raise ApiError(status_code=_response.status_code, body=_response.text)
585
- raise ApiError(status_code=_response.status_code, body=_response_json)
586
-
587
- async def fetch_list_evaluations(self, *, app_id: str) -> typing.List[Evaluation]:
588
- """
589
- Fetches a list of evaluations, optionally filtered by an app ID.
590
-
591
- Args:
592
- app_id (Optional[str]): An optional app ID to filter the evaluations.
593
-
594
- Returns:
595
- List[Evaluation]: A list of evaluations.
596
-
597
- Parameters:
598
- - app_id: str.
599
- ---
600
- from agenta.client import AsyncAgentaApi
601
-
602
- client = AsyncAgentaApi(
603
- api_key="YOUR_API_KEY",
604
- base_url="https://yourhost.com/path/to/api",
605
- )
606
- await client.evaluations.fetch_list_evaluations(
607
- app_id="app_id",
608
- )
609
- """
610
- _response = await self._client_wrapper.httpx_client.request(
611
- "GET",
612
- urllib.parse.urljoin(
613
- f"{self._client_wrapper.get_base_url()}/", "evaluations"
614
- ),
615
- params=remove_none_from_dict({"app_id": app_id}),
616
- headers=self._client_wrapper.get_headers(),
617
- timeout=60,
618
- )
619
- if 200 <= _response.status_code < 300:
620
- return pydantic.parse_obj_as(typing.List[Evaluation], _response.json()) # type: ignore
621
- if _response.status_code == 422:
622
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
623
- try:
624
- _response_json = _response.json()
625
- except JSONDecodeError:
626
- raise ApiError(status_code=_response.status_code, body=_response.text)
627
- raise ApiError(status_code=_response.status_code, body=_response_json)
628
-
629
- async def create_evaluation(
630
- self,
631
- *,
632
- app_id: str,
633
- variant_ids: typing.List[str],
634
- evaluators_configs: typing.List[str],
635
- testset_id: str,
636
- rate_limit: LlmRunRateLimit,
637
- lm_providers_keys: typing.Optional[typing.Dict[str, str]] = OMIT,
638
- correct_answer_column: typing.Optional[str] = OMIT,
639
- ) -> typing.List[Evaluation]:
640
- """
641
- Creates a new comparison table document
642
- Raises:
643
- HTTPException: _description_
644
- Returns:
645
- _description_
646
-
647
- Parameters:
648
- - app_id: str.
649
-
650
- - variant_ids: typing.List[str].
651
-
652
- - evaluators_configs: typing.List[str].
653
-
654
- - testset_id: str.
655
-
656
- - rate_limit: LlmRunRateLimit.
657
-
658
- - lm_providers_keys: typing.Optional[typing.Dict[str, str]].
659
-
660
- - correct_answer_column: typing.Optional[str].
661
- ---
662
- from agenta import LlmRunRateLimit
663
- from agenta.client import AsyncAgentaApi
664
-
665
- client = AsyncAgentaApi(
666
- api_key="YOUR_API_KEY",
667
- base_url="https://yourhost.com/path/to/api",
668
- )
669
- await client.evaluations.create_evaluation(
670
- app_id="app_id",
671
- variant_ids=["variant_ids"],
672
- evaluators_configs=["evaluators_configs"],
673
- testset_id="testset_id",
674
- rate_limit=LlmRunRateLimit(
675
- batch_size=1,
676
- max_retries=1,
677
- retry_delay=1,
678
- delay_between_batches=1,
679
- ),
680
- )
681
- """
682
- _request: typing.Dict[str, typing.Any] = {
683
- "app_id": app_id,
684
- "variant_ids": variant_ids,
685
- "evaluators_configs": evaluators_configs,
686
- "testset_id": testset_id,
687
- "rate_limit": rate_limit,
688
- }
689
- if lm_providers_keys is not OMIT:
690
- _request["lm_providers_keys"] = lm_providers_keys
691
- if correct_answer_column is not OMIT:
692
- _request["correct_answer_column"] = correct_answer_column
693
- _response = await self._client_wrapper.httpx_client.request(
694
- "POST",
695
- urllib.parse.urljoin(
696
- f"{self._client_wrapper.get_base_url()}/", "evaluations"
697
- ),
698
- json=jsonable_encoder(_request),
699
- headers=self._client_wrapper.get_headers(),
700
- timeout=60,
701
- )
702
- if 200 <= _response.status_code < 300:
703
- return pydantic.parse_obj_as(typing.List[Evaluation], _response.json()) # type: ignore
704
- if _response.status_code == 422:
705
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
706
- try:
707
- _response_json = _response.json()
708
- except JSONDecodeError:
709
- raise ApiError(status_code=_response.status_code, body=_response.text)
710
- raise ApiError(status_code=_response.status_code, body=_response_json)
711
-
712
- async def delete_evaluations(
713
- self, *, evaluations_ids: typing.List[str]
714
- ) -> typing.List[str]:
715
- """
716
- Delete specific comparison tables based on their unique IDs.
717
-
718
- Args:
719
- delete_evaluations (List[str]): The unique identifiers of the comparison tables to delete.
720
-
721
- Returns:
722
- A list of the deleted comparison tables' IDs.
723
-
724
- Parameters:
725
- - evaluations_ids: typing.List[str].
726
- ---
727
- from agenta.client import AsyncAgentaApi
728
-
729
- client = AsyncAgentaApi(
730
- api_key="YOUR_API_KEY",
731
- base_url="https://yourhost.com/path/to/api",
732
- )
733
- await client.evaluations.delete_evaluations(
734
- evaluations_ids=["evaluations_ids"],
735
- )
736
- """
737
- _response = await self._client_wrapper.httpx_client.request(
738
- "DELETE",
739
- urllib.parse.urljoin(
740
- f"{self._client_wrapper.get_base_url()}/", "evaluations"
741
- ),
742
- json=jsonable_encoder({"evaluations_ids": evaluations_ids}),
743
- headers=self._client_wrapper.get_headers(),
744
- timeout=60,
745
- )
746
- if 200 <= _response.status_code < 300:
747
- return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
748
- if _response.status_code == 422:
749
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
750
- try:
751
- _response_json = _response.json()
752
- except JSONDecodeError:
753
- raise ApiError(status_code=_response.status_code, body=_response.text)
754
- raise ApiError(status_code=_response.status_code, body=_response_json)
755
-
756
- async def fetch_evaluation_status(self, evaluation_id: str) -> typing.Any:
757
- """
758
- Fetches the status of the evaluation.
759
-
760
- Args:
761
- evaluation_id (str): the evaluation id
762
- request (Request): the request object
763
-
764
- Returns:
765
- (str): the evaluation status
766
-
767
- Parameters:
768
- - evaluation_id: str.
769
- ---
770
- from agenta.client import AsyncAgentaApi
771
-
772
- client = AsyncAgentaApi(
773
- api_key="YOUR_API_KEY",
774
- base_url="https://yourhost.com/path/to/api",
775
- )
776
- await client.evaluations.fetch_evaluation_status(
777
- evaluation_id="evaluation_id",
778
- )
779
- """
780
- _response = await self._client_wrapper.httpx_client.request(
781
- "GET",
782
- urllib.parse.urljoin(
783
- f"{self._client_wrapper.get_base_url()}/",
784
- f"evaluations/{evaluation_id}/status",
785
- ),
786
- headers=self._client_wrapper.get_headers(),
787
- timeout=60,
788
- )
789
- if 200 <= _response.status_code < 300:
790
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
791
- if _response.status_code == 422:
792
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
793
- try:
794
- _response_json = _response.json()
795
- except JSONDecodeError:
796
- raise ApiError(status_code=_response.status_code, body=_response.text)
797
- raise ApiError(status_code=_response.status_code, body=_response_json)
798
-
799
- async def fetch_evaluation_results(self, evaluation_id: str) -> typing.Any:
800
- """
801
- Fetches the results of the evaluation
802
-
803
- Args:
804
- evaluation_id (str): the evaluation id
805
- request (Request): the request object
806
-
807
- Returns:
808
- _type_: _description_
809
-
810
- Parameters:
811
- - evaluation_id: str.
812
- ---
813
- from agenta.client import AsyncAgentaApi
814
-
815
- client = AsyncAgentaApi(
816
- api_key="YOUR_API_KEY",
817
- base_url="https://yourhost.com/path/to/api",
818
- )
819
- await client.evaluations.fetch_evaluation_results(
820
- evaluation_id="evaluation_id",
821
- )
822
- """
823
- _response = await self._client_wrapper.httpx_client.request(
824
- "GET",
825
- urllib.parse.urljoin(
826
- f"{self._client_wrapper.get_base_url()}/",
827
- f"evaluations/{evaluation_id}/results",
828
- ),
829
- headers=self._client_wrapper.get_headers(),
830
- timeout=60,
831
- )
832
- if 200 <= _response.status_code < 300:
833
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
834
- if _response.status_code == 422:
835
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
836
- try:
837
- _response_json = _response.json()
838
- except JSONDecodeError:
839
- raise ApiError(status_code=_response.status_code, body=_response.text)
840
- raise ApiError(status_code=_response.status_code, body=_response_json)
841
-
842
- async def fetch_evaluation_scenarios(
843
- self, evaluation_id: str
844
- ) -> typing.List[EvaluationScenario]:
845
- """
846
- Fetches evaluation scenarios for a given evaluation ID.
847
-
848
- Arguments:
849
- evaluation_id (str): The ID of the evaluation for which to fetch scenarios.
850
-
851
- Raises:
852
- HTTPException: If the evaluation is not found or access is denied.
853
-
854
- Returns:
855
- List[EvaluationScenario]: A list of evaluation scenarios.
856
-
857
- Parameters:
858
- - evaluation_id: str.
859
- ---
860
- from agenta.client import AsyncAgentaApi
861
-
862
- client = AsyncAgentaApi(
863
- api_key="YOUR_API_KEY",
864
- base_url="https://yourhost.com/path/to/api",
865
- )
866
- await client.evaluations.fetch_evaluation_scenarios(
867
- evaluation_id="evaluation_id",
868
- )
869
- """
870
- _response = await self._client_wrapper.httpx_client.request(
871
- "GET",
872
- urllib.parse.urljoin(
873
- f"{self._client_wrapper.get_base_url()}/",
874
- f"evaluations/{evaluation_id}/evaluation_scenarios",
875
- ),
876
- headers=self._client_wrapper.get_headers(),
877
- timeout=60,
878
- )
879
- if 200 <= _response.status_code < 300:
880
- return pydantic.parse_obj_as(typing.List[EvaluationScenario], _response.json()) # type: ignore
881
- if _response.status_code == 422:
882
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
883
- try:
884
- _response_json = _response.json()
885
- except JSONDecodeError:
886
- raise ApiError(status_code=_response.status_code, body=_response.text)
887
- raise ApiError(status_code=_response.status_code, body=_response_json)
888
-
889
- async def fetch_evaluation(self, evaluation_id: str) -> Evaluation:
890
- """
891
- Fetches a single evaluation based on its ID.
892
-
893
- Args:
894
- evaluation_id (str): The ID of the evaluation to fetch.
895
-
896
- Returns:
897
- Evaluation: The fetched evaluation.
898
-
899
- Parameters:
900
- - evaluation_id: str.
901
- ---
902
- from agenta.client import AsyncAgentaApi
903
-
904
- client = AsyncAgentaApi(
905
- api_key="YOUR_API_KEY",
906
- base_url="https://yourhost.com/path/to/api",
907
- )
908
- await client.evaluations.fetch_evaluation(
909
- evaluation_id="evaluation_id",
910
- )
911
- """
912
- _response = await self._client_wrapper.httpx_client.request(
913
- "GET",
914
- urllib.parse.urljoin(
915
- f"{self._client_wrapper.get_base_url()}/",
916
- f"evaluations/{evaluation_id}",
917
- ),
918
- headers=self._client_wrapper.get_headers(),
919
- timeout=60,
920
- )
921
- if 200 <= _response.status_code < 300:
922
- return pydantic.parse_obj_as(Evaluation, _response.json()) # type: ignore
923
- if _response.status_code == 422:
924
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
925
- try:
926
- _response_json = _response.json()
927
- except JSONDecodeError:
928
- raise ApiError(status_code=_response.status_code, body=_response.text)
929
- raise ApiError(status_code=_response.status_code, body=_response_json)
930
-
931
- async def webhook_example_fake(self) -> EvaluationWebhook:
932
- """
933
- Returns a fake score response for example webhook evaluation
934
-
935
- Returns:
936
- _description_
937
-
938
- ---
939
- from agenta.client import AsyncAgentaApi
940
-
941
- client = AsyncAgentaApi(
942
- api_key="YOUR_API_KEY",
943
- base_url="https://yourhost.com/path/to/api",
944
- )
945
- await client.evaluations.webhook_example_fake()
946
- """
947
- _response = await self._client_wrapper.httpx_client.request(
948
- "POST",
949
- urllib.parse.urljoin(
950
- f"{self._client_wrapper.get_base_url()}/",
951
- "evaluations/webhook_example_fake",
952
- ),
953
- headers=self._client_wrapper.get_headers(),
954
- timeout=60,
955
- )
956
- if 200 <= _response.status_code < 300:
957
- return pydantic.parse_obj_as(EvaluationWebhook, _response.json()) # type: ignore
958
- try:
959
- _response_json = _response.json()
960
- except JSONDecodeError:
961
- raise ApiError(status_code=_response.status_code, body=_response.text)
962
- raise ApiError(status_code=_response.status_code, body=_response_json)
963
-
964
- async def fetch_evaluation_scenarios(self, *, evaluations_ids: str) -> typing.Any:
965
- """
966
- Fetches evaluation scenarios for a given evaluation ID.
967
-
968
- Arguments:
969
- evaluation_id (str): The ID of the evaluation for which to fetch scenarios.
970
-
971
- Raises:
972
- HTTPException: If the evaluation is not found or access is denied.
973
-
974
- Returns:
975
- List[EvaluationScenario]: A list of evaluation scenarios.
976
-
977
- Parameters:
978
- - evaluations_ids: str.
979
- ---
980
- from agenta.client import AsyncAgentaApi
981
-
982
- client = AsyncAgentaApi(
983
- api_key="YOUR_API_KEY",
984
- base_url="https://yourhost.com/path/to/api",
985
- )
986
- await client.evaluations.fetch_evaluation_scenarios(
987
- evaluations_ids="evaluations_ids",
988
- )
989
- """
990
- _response = await self._client_wrapper.httpx_client.request(
991
- "GET",
992
- urllib.parse.urljoin(
993
- f"{self._client_wrapper.get_base_url()}/",
994
- "evaluations/evaluation_scenarios/comparison-results",
995
- ),
996
- params=remove_none_from_dict({"evaluations_ids": evaluations_ids}),
997
- headers=self._client_wrapper.get_headers(),
998
- timeout=60,
999
- )
1000
- if 200 <= _response.status_code < 300:
1001
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
1002
- if _response.status_code == 422:
1003
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
1004
- try:
1005
- _response_json = _response.json()
1006
- except JSONDecodeError:
1007
- raise ApiError(status_code=_response.status_code, body=_response.text)
1008
- raise ApiError(status_code=_response.status_code, body=_response_json)