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