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,2 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
@@ -0,0 +1,649 @@
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.http_validation_error import HttpValidationError
13
+ from ...types.new_testset import NewTestset
14
+ from ...types.test_set_output_response import TestSetOutputResponse
15
+ from ...types.test_set_simple_response import TestSetSimpleResponse
16
+
17
+ try:
18
+ import pydantic.v1 as pydantic # type: ignore
19
+ except ImportError:
20
+ import pydantic # type: ignore
21
+
22
+ # this is used as the default value for optional parameters
23
+ OMIT = typing.cast(typing.Any, ...)
24
+
25
+
26
+ class TestsetsClient:
27
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
28
+ self._client_wrapper = client_wrapper
29
+
30
+ def upload_file(
31
+ self,
32
+ *,
33
+ upload_type: typing.Optional[str] = None,
34
+ file: typing.IO,
35
+ testset_name: typing.Optional[str] = None,
36
+ app_id: typing.Optional[str] = None,
37
+ ) -> TestSetSimpleResponse:
38
+ """
39
+ Uploads a CSV or JSON file and saves its data to MongoDB.
40
+
41
+ Args:
42
+ upload_type : Either a json or csv file.
43
+ file (UploadFile): The CSV or JSON file to upload.
44
+ testset_name (Optional): the name of the testset if provided.
45
+
46
+ Returns:
47
+ dict: The result of the upload process.
48
+
49
+ Parameters:
50
+ - upload_type: typing.Optional[str].
51
+
52
+ - file: typing.IO.
53
+
54
+ - testset_name: typing.Optional[str].
55
+
56
+ - app_id: typing.Optional[str].
57
+ ---
58
+ from agenta.client import AgentaApi
59
+
60
+ client = AgentaApi(
61
+ api_key="YOUR_API_KEY",
62
+ base_url="https://yourhost.com/path/to/api",
63
+ )
64
+ client.testsets.upload_file()
65
+ """
66
+ _response = self._client_wrapper.httpx_client.request(
67
+ "POST",
68
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets/upload"),
69
+ data=jsonable_encoder({"upload_type": upload_type, "testset_name": testset_name, "app_id": app_id}),
70
+ files={"file": file},
71
+ headers=self._client_wrapper.get_headers(),
72
+ timeout=60,
73
+ )
74
+ if 200 <= _response.status_code < 300:
75
+ return pydantic.parse_obj_as(TestSetSimpleResponse, _response.json()) # type: ignore
76
+ if _response.status_code == 422:
77
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
78
+ try:
79
+ _response_json = _response.json()
80
+ except JSONDecodeError:
81
+ raise ApiError(status_code=_response.status_code, body=_response.text)
82
+ raise ApiError(status_code=_response.status_code, body=_response_json)
83
+
84
+ def import_testset(self) -> TestSetSimpleResponse:
85
+ """
86
+ Import JSON testset data from an endpoint and save it to MongoDB.
87
+
88
+ Args:
89
+ endpoint (str): An endpoint URL to import data from.
90
+ testset_name (str): the name of the testset if provided.
91
+
92
+ Returns:
93
+ dict: The result of the import process.
94
+
95
+ ---
96
+ from agenta.client import AgentaApi
97
+
98
+ client = AgentaApi(
99
+ api_key="YOUR_API_KEY",
100
+ base_url="https://yourhost.com/path/to/api",
101
+ )
102
+ client.testsets.import_testset()
103
+ """
104
+ _response = self._client_wrapper.httpx_client.request(
105
+ "POST",
106
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets/endpoint"),
107
+ headers=self._client_wrapper.get_headers(),
108
+ timeout=60,
109
+ )
110
+ if 200 <= _response.status_code < 300:
111
+ return pydantic.parse_obj_as(TestSetSimpleResponse, _response.json()) # type: ignore
112
+ if _response.status_code == 422:
113
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
114
+ try:
115
+ _response_json = _response.json()
116
+ except JSONDecodeError:
117
+ raise ApiError(status_code=_response.status_code, body=_response.text)
118
+ raise ApiError(status_code=_response.status_code, body=_response_json)
119
+
120
+ def create_testset(self, app_id: str, *, request: NewTestset) -> TestSetSimpleResponse:
121
+ """
122
+ Create a testset with given name and app_name, save the testset to MongoDB.
123
+
124
+ Args:
125
+ name (str): name of the test set.
126
+ app_name (str): name of the application.
127
+ testset (Dict[str, str]): test set data.
128
+
129
+ Returns:
130
+ str: The id of the test set created.
131
+
132
+ Parameters:
133
+ - app_id: str.
134
+
135
+ - request: NewTestset.
136
+ ---
137
+ from agenta import NewTestset
138
+ from agenta.client import AgentaApi
139
+
140
+ client = AgentaApi(
141
+ api_key="YOUR_API_KEY",
142
+ base_url="https://yourhost.com/path/to/api",
143
+ )
144
+ client.testsets.create_testset(
145
+ app_id="app_id",
146
+ request=NewTestset(
147
+ name="name",
148
+ csvdata=[{"csvdata": "csvdata"}],
149
+ ),
150
+ )
151
+ """
152
+ _response = self._client_wrapper.httpx_client.request(
153
+ "POST",
154
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"testsets/{app_id}"),
155
+ json=jsonable_encoder(request),
156
+ headers=self._client_wrapper.get_headers(),
157
+ timeout=60,
158
+ )
159
+ if 200 <= _response.status_code < 300:
160
+ return pydantic.parse_obj_as(TestSetSimpleResponse, _response.json()) # type: ignore
161
+ if _response.status_code == 422:
162
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
163
+ try:
164
+ _response_json = _response.json()
165
+ except JSONDecodeError:
166
+ raise ApiError(status_code=_response.status_code, body=_response.text)
167
+ raise ApiError(status_code=_response.status_code, body=_response_json)
168
+
169
+ def get_single_testset(self, testset_id: str) -> typing.Any:
170
+ """
171
+ Fetch a specific testset in a MongoDB collection using its \_id.
172
+
173
+ Args:
174
+ testset_id (str): The \_id of the testset to fetch.
175
+
176
+ Returns:
177
+ The requested testset if found, else an HTTPException.
178
+
179
+ Parameters:
180
+ - testset_id: str.
181
+ ---
182
+ from agenta.client import AgentaApi
183
+
184
+ client = AgentaApi(
185
+ api_key="YOUR_API_KEY",
186
+ base_url="https://yourhost.com/path/to/api",
187
+ )
188
+ client.testsets.get_single_testset(
189
+ testset_id="testset_id",
190
+ )
191
+ """
192
+ _response = self._client_wrapper.httpx_client.request(
193
+ "GET",
194
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"testsets/{testset_id}"),
195
+ headers=self._client_wrapper.get_headers(),
196
+ timeout=60,
197
+ )
198
+ if 200 <= _response.status_code < 300:
199
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
200
+ if _response.status_code == 422:
201
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
202
+ try:
203
+ _response_json = _response.json()
204
+ except JSONDecodeError:
205
+ raise ApiError(status_code=_response.status_code, body=_response.text)
206
+ raise ApiError(status_code=_response.status_code, body=_response_json)
207
+
208
+ def update_testset(self, testset_id: str, *, request: NewTestset) -> typing.Any:
209
+ """
210
+ Update a testset with given id, update the testset in MongoDB.
211
+
212
+ Args:
213
+ testset_id (str): id of the test set to be updated.
214
+ csvdata (NewTestset): New data to replace the old testset.
215
+
216
+ Returns:
217
+ str: The id of the test set updated.
218
+
219
+ Parameters:
220
+ - testset_id: str.
221
+
222
+ - request: NewTestset.
223
+ ---
224
+ from agenta import NewTestset
225
+ from agenta.client import AgentaApi
226
+
227
+ client = AgentaApi(
228
+ api_key="YOUR_API_KEY",
229
+ base_url="https://yourhost.com/path/to/api",
230
+ )
231
+ client.testsets.update_testset(
232
+ testset_id="testset_id",
233
+ request=NewTestset(
234
+ name="name",
235
+ csvdata=[{"csvdata": "csvdata"}],
236
+ ),
237
+ )
238
+ """
239
+ _response = self._client_wrapper.httpx_client.request(
240
+ "PUT",
241
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"testsets/{testset_id}"),
242
+ json=jsonable_encoder(request),
243
+ headers=self._client_wrapper.get_headers(),
244
+ timeout=60,
245
+ )
246
+ if 200 <= _response.status_code < 300:
247
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
248
+ if _response.status_code == 422:
249
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
250
+ try:
251
+ _response_json = _response.json()
252
+ except JSONDecodeError:
253
+ raise ApiError(status_code=_response.status_code, body=_response.text)
254
+ raise ApiError(status_code=_response.status_code, body=_response_json)
255
+
256
+ def get_testsets(self, *, app_id: str) -> typing.List[TestSetOutputResponse]:
257
+ """
258
+ Get all testsets.
259
+
260
+ Returns:
261
+
262
+ - A list of testset objects.
263
+
264
+ Raises:
265
+
266
+ - `HTTPException` with status code 404 if no testsets are found.
267
+
268
+ Parameters:
269
+ - app_id: str.
270
+ ---
271
+ from agenta.client import AgentaApi
272
+
273
+ client = AgentaApi(
274
+ api_key="YOUR_API_KEY",
275
+ base_url="https://yourhost.com/path/to/api",
276
+ )
277
+ client.testsets.get_testsets(
278
+ app_id="app_id",
279
+ )
280
+ """
281
+ _response = self._client_wrapper.httpx_client.request(
282
+ "GET",
283
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets"),
284
+ params=remove_none_from_dict({"app_id": app_id}),
285
+ headers=self._client_wrapper.get_headers(),
286
+ timeout=60,
287
+ )
288
+ if 200 <= _response.status_code < 300:
289
+ return pydantic.parse_obj_as(typing.List[TestSetOutputResponse], _response.json()) # type: ignore
290
+ if _response.status_code == 422:
291
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
292
+ try:
293
+ _response_json = _response.json()
294
+ except JSONDecodeError:
295
+ raise ApiError(status_code=_response.status_code, body=_response.text)
296
+ raise ApiError(status_code=_response.status_code, body=_response_json)
297
+
298
+ def delete_testsets(self, *, testset_ids: typing.List[str]) -> typing.List[str]:
299
+ """
300
+ Delete specific testsets based on their unique IDs.
301
+
302
+ Args:
303
+ testset_ids (List[str]): The unique identifiers of the testsets to delete.
304
+
305
+ Returns:
306
+ A list of the deleted testsets' IDs.
307
+
308
+ Parameters:
309
+ - testset_ids: typing.List[str].
310
+ ---
311
+ from agenta.client import AgentaApi
312
+
313
+ client = AgentaApi(
314
+ api_key="YOUR_API_KEY",
315
+ base_url="https://yourhost.com/path/to/api",
316
+ )
317
+ client.testsets.delete_testsets(
318
+ testset_ids=["testset_ids"],
319
+ )
320
+ """
321
+ _response = self._client_wrapper.httpx_client.request(
322
+ "DELETE",
323
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets"),
324
+ json=jsonable_encoder({"testset_ids": testset_ids}),
325
+ headers=self._client_wrapper.get_headers(),
326
+ timeout=60,
327
+ )
328
+ if 200 <= _response.status_code < 300:
329
+ return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
330
+ if _response.status_code == 422:
331
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
332
+ try:
333
+ _response_json = _response.json()
334
+ except JSONDecodeError:
335
+ raise ApiError(status_code=_response.status_code, body=_response.text)
336
+ raise ApiError(status_code=_response.status_code, body=_response_json)
337
+
338
+
339
+ class AsyncTestsetsClient:
340
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
341
+ self._client_wrapper = client_wrapper
342
+
343
+ async def upload_file(
344
+ self,
345
+ *,
346
+ upload_type: typing.Optional[str] = None,
347
+ file: typing.IO,
348
+ testset_name: typing.Optional[str] = None,
349
+ app_id: typing.Optional[str] = None,
350
+ ) -> TestSetSimpleResponse:
351
+ """
352
+ Uploads a CSV or JSON file and saves its data to MongoDB.
353
+
354
+ Args:
355
+ upload_type : Either a json or csv file.
356
+ file (UploadFile): The CSV or JSON file to upload.
357
+ testset_name (Optional): the name of the testset if provided.
358
+
359
+ Returns:
360
+ dict: The result of the upload process.
361
+
362
+ Parameters:
363
+ - upload_type: typing.Optional[str].
364
+
365
+ - file: typing.IO.
366
+
367
+ - testset_name: typing.Optional[str].
368
+
369
+ - app_id: typing.Optional[str].
370
+ ---
371
+ from agenta.client import AsyncAgentaApi
372
+
373
+ client = AsyncAgentaApi(
374
+ api_key="YOUR_API_KEY",
375
+ base_url="https://yourhost.com/path/to/api",
376
+ )
377
+ await client.testsets.upload_file()
378
+ """
379
+ _response = await self._client_wrapper.httpx_client.request(
380
+ "POST",
381
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets/upload"),
382
+ data=jsonable_encoder({"upload_type": upload_type, "testset_name": testset_name, "app_id": app_id}),
383
+ files={"file": file},
384
+ headers=self._client_wrapper.get_headers(),
385
+ timeout=60,
386
+ )
387
+ if 200 <= _response.status_code < 300:
388
+ return pydantic.parse_obj_as(TestSetSimpleResponse, _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
+ async def import_testset(self) -> TestSetSimpleResponse:
398
+ """
399
+ Import JSON testset data from an endpoint and save it to MongoDB.
400
+
401
+ Args:
402
+ endpoint (str): An endpoint URL to import data from.
403
+ testset_name (str): the name of the testset if provided.
404
+
405
+ Returns:
406
+ dict: The result of the import process.
407
+
408
+ ---
409
+ from agenta.client import AsyncAgentaApi
410
+
411
+ client = AsyncAgentaApi(
412
+ api_key="YOUR_API_KEY",
413
+ base_url="https://yourhost.com/path/to/api",
414
+ )
415
+ await client.testsets.import_testset()
416
+ """
417
+ _response = await self._client_wrapper.httpx_client.request(
418
+ "POST",
419
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets/endpoint"),
420
+ headers=self._client_wrapper.get_headers(),
421
+ timeout=60,
422
+ )
423
+ if 200 <= _response.status_code < 300:
424
+ return pydantic.parse_obj_as(TestSetSimpleResponse, _response.json()) # type: ignore
425
+ if _response.status_code == 422:
426
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
427
+ try:
428
+ _response_json = _response.json()
429
+ except JSONDecodeError:
430
+ raise ApiError(status_code=_response.status_code, body=_response.text)
431
+ raise ApiError(status_code=_response.status_code, body=_response_json)
432
+
433
+ async def create_testset(self, app_id: str, *, request: NewTestset) -> TestSetSimpleResponse:
434
+ """
435
+ Create a testset with given name and app_name, save the testset to MongoDB.
436
+
437
+ Args:
438
+ name (str): name of the test set.
439
+ app_name (str): name of the application.
440
+ testset (Dict[str, str]): test set data.
441
+
442
+ Returns:
443
+ str: The id of the test set created.
444
+
445
+ Parameters:
446
+ - app_id: str.
447
+
448
+ - request: NewTestset.
449
+ ---
450
+ from agenta import NewTestset
451
+ from agenta.client import AsyncAgentaApi
452
+
453
+ client = AsyncAgentaApi(
454
+ api_key="YOUR_API_KEY",
455
+ base_url="https://yourhost.com/path/to/api",
456
+ )
457
+ await client.testsets.create_testset(
458
+ app_id="app_id",
459
+ request=NewTestset(
460
+ name="name",
461
+ csvdata=[{"csvdata": "csvdata"}],
462
+ ),
463
+ )
464
+ """
465
+ _response = await self._client_wrapper.httpx_client.request(
466
+ "POST",
467
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"testsets/{app_id}"),
468
+ json=jsonable_encoder(request),
469
+ headers=self._client_wrapper.get_headers(),
470
+ timeout=60,
471
+ )
472
+ if 200 <= _response.status_code < 300:
473
+ return pydantic.parse_obj_as(TestSetSimpleResponse, _response.json()) # type: ignore
474
+ if _response.status_code == 422:
475
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
476
+ try:
477
+ _response_json = _response.json()
478
+ except JSONDecodeError:
479
+ raise ApiError(status_code=_response.status_code, body=_response.text)
480
+ raise ApiError(status_code=_response.status_code, body=_response_json)
481
+
482
+ async def get_single_testset(self, testset_id: str) -> typing.Any:
483
+ """
484
+ Fetch a specific testset in a MongoDB collection using its \_id.
485
+
486
+ Args:
487
+ testset_id (str): The \_id of the testset to fetch.
488
+
489
+ Returns:
490
+ The requested testset if found, else an HTTPException.
491
+
492
+ Parameters:
493
+ - testset_id: str.
494
+ ---
495
+ from agenta.client import AsyncAgentaApi
496
+
497
+ client = AsyncAgentaApi(
498
+ api_key="YOUR_API_KEY",
499
+ base_url="https://yourhost.com/path/to/api",
500
+ )
501
+ await client.testsets.get_single_testset(
502
+ testset_id="testset_id",
503
+ )
504
+ """
505
+ _response = await self._client_wrapper.httpx_client.request(
506
+ "GET",
507
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"testsets/{testset_id}"),
508
+ headers=self._client_wrapper.get_headers(),
509
+ timeout=60,
510
+ )
511
+ if 200 <= _response.status_code < 300:
512
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
513
+ if _response.status_code == 422:
514
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
515
+ try:
516
+ _response_json = _response.json()
517
+ except JSONDecodeError:
518
+ raise ApiError(status_code=_response.status_code, body=_response.text)
519
+ raise ApiError(status_code=_response.status_code, body=_response_json)
520
+
521
+ async def update_testset(self, testset_id: str, *, request: NewTestset) -> typing.Any:
522
+ """
523
+ Update a testset with given id, update the testset in MongoDB.
524
+
525
+ Args:
526
+ testset_id (str): id of the test set to be updated.
527
+ csvdata (NewTestset): New data to replace the old testset.
528
+
529
+ Returns:
530
+ str: The id of the test set updated.
531
+
532
+ Parameters:
533
+ - testset_id: str.
534
+
535
+ - request: NewTestset.
536
+ ---
537
+ from agenta import NewTestset
538
+ from agenta.client import AsyncAgentaApi
539
+
540
+ client = AsyncAgentaApi(
541
+ api_key="YOUR_API_KEY",
542
+ base_url="https://yourhost.com/path/to/api",
543
+ )
544
+ await client.testsets.update_testset(
545
+ testset_id="testset_id",
546
+ request=NewTestset(
547
+ name="name",
548
+ csvdata=[{"csvdata": "csvdata"}],
549
+ ),
550
+ )
551
+ """
552
+ _response = await self._client_wrapper.httpx_client.request(
553
+ "PUT",
554
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"testsets/{testset_id}"),
555
+ json=jsonable_encoder(request),
556
+ headers=self._client_wrapper.get_headers(),
557
+ timeout=60,
558
+ )
559
+ if 200 <= _response.status_code < 300:
560
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
561
+ if _response.status_code == 422:
562
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
563
+ try:
564
+ _response_json = _response.json()
565
+ except JSONDecodeError:
566
+ raise ApiError(status_code=_response.status_code, body=_response.text)
567
+ raise ApiError(status_code=_response.status_code, body=_response_json)
568
+
569
+ async def get_testsets(self, *, app_id: str) -> typing.List[TestSetOutputResponse]:
570
+ """
571
+ Get all testsets.
572
+
573
+ Returns:
574
+
575
+ - A list of testset objects.
576
+
577
+ Raises:
578
+
579
+ - `HTTPException` with status code 404 if no testsets are found.
580
+
581
+ Parameters:
582
+ - app_id: str.
583
+ ---
584
+ from agenta.client import AsyncAgentaApi
585
+
586
+ client = AsyncAgentaApi(
587
+ api_key="YOUR_API_KEY",
588
+ base_url="https://yourhost.com/path/to/api",
589
+ )
590
+ await client.testsets.get_testsets(
591
+ app_id="app_id",
592
+ )
593
+ """
594
+ _response = await self._client_wrapper.httpx_client.request(
595
+ "GET",
596
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets"),
597
+ params=remove_none_from_dict({"app_id": app_id}),
598
+ headers=self._client_wrapper.get_headers(),
599
+ timeout=60,
600
+ )
601
+ if 200 <= _response.status_code < 300:
602
+ return pydantic.parse_obj_as(typing.List[TestSetOutputResponse], _response.json()) # type: ignore
603
+ if _response.status_code == 422:
604
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
605
+ try:
606
+ _response_json = _response.json()
607
+ except JSONDecodeError:
608
+ raise ApiError(status_code=_response.status_code, body=_response.text)
609
+ raise ApiError(status_code=_response.status_code, body=_response_json)
610
+
611
+ async def delete_testsets(self, *, testset_ids: typing.List[str]) -> typing.List[str]:
612
+ """
613
+ Delete specific testsets based on their unique IDs.
614
+
615
+ Args:
616
+ testset_ids (List[str]): The unique identifiers of the testsets to delete.
617
+
618
+ Returns:
619
+ A list of the deleted testsets' IDs.
620
+
621
+ Parameters:
622
+ - testset_ids: typing.List[str].
623
+ ---
624
+ from agenta.client import AsyncAgentaApi
625
+
626
+ client = AsyncAgentaApi(
627
+ api_key="YOUR_API_KEY",
628
+ base_url="https://yourhost.com/path/to/api",
629
+ )
630
+ await client.testsets.delete_testsets(
631
+ testset_ids=["testset_ids"],
632
+ )
633
+ """
634
+ _response = await self._client_wrapper.httpx_client.request(
635
+ "DELETE",
636
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "testsets"),
637
+ json=jsonable_encoder({"testset_ids": testset_ids}),
638
+ headers=self._client_wrapper.get_headers(),
639
+ timeout=60,
640
+ )
641
+ if 200 <= _response.status_code < 300:
642
+ return pydantic.parse_obj_as(typing.List[str], _response.json()) # type: ignore
643
+ if _response.status_code == 422:
644
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
645
+ try:
646
+ _response_json = _response.json()
647
+ except JSONDecodeError:
648
+ raise ApiError(status_code=_response.status_code, body=_response.text)
649
+ raise ApiError(status_code=_response.status_code, body=_response_json)
@@ -0,0 +1,5 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from .types import AddVariantFromBaseAndConfigResponse
4
+
5
+ __all__ = ["AddVariantFromBaseAndConfigResponse"]