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,730 @@
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 ...errors.unprocessable_entity_error import UnprocessableEntityError
11
+ from ...types.app_variant_response import AppVariantResponse
12
+ from ...types.app_variant_revision import AppVariantRevision
13
+ from ...types.docker_env_vars import DockerEnvVars
14
+ from ...types.http_validation_error import HttpValidationError
15
+ from ...types.image import Image
16
+ from ...types.uri import Uri
17
+ from ...types.variant_action import VariantAction
18
+ from .types.add_variant_from_base_and_config_response import AddVariantFromBaseAndConfigResponse
19
+
20
+ try:
21
+ import pydantic.v1 as pydantic # type: ignore
22
+ except ImportError:
23
+ import pydantic # type: ignore
24
+
25
+ # this is used as the default value for optional parameters
26
+ OMIT = typing.cast(typing.Any, ...)
27
+
28
+
29
+ class VariantsClient:
30
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
31
+ self._client_wrapper = client_wrapper
32
+
33
+ def add_variant_from_base_and_config(
34
+ self, *, base_id: str, new_variant_name: str, new_config_name: str, parameters: typing.Dict[str, typing.Any]
35
+ ) -> AddVariantFromBaseAndConfigResponse:
36
+ """
37
+ Add a new variant based on an existing one.
38
+ Same as POST /config
39
+
40
+ Args:
41
+ payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
42
+ stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
43
+
44
+ Raises:
45
+ HTTPException: Raised if the variant could not be added or accessed.
46
+
47
+ Returns:
48
+ Union[AppVariantResponse, Any]: New variant details or exception.
49
+
50
+ Parameters:
51
+ - base_id: str.
52
+
53
+ - new_variant_name: str.
54
+
55
+ - new_config_name: str.
56
+
57
+ - parameters: typing.Dict[str, typing.Any].
58
+ """
59
+ _response = self._client_wrapper.httpx_client.request(
60
+ "POST",
61
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "variants/from-base"),
62
+ json=jsonable_encoder(
63
+ {
64
+ "base_id": base_id,
65
+ "new_variant_name": new_variant_name,
66
+ "new_config_name": new_config_name,
67
+ "parameters": parameters,
68
+ }
69
+ ),
70
+ headers=self._client_wrapper.get_headers(),
71
+ timeout=60,
72
+ )
73
+ if 200 <= _response.status_code < 300:
74
+ return pydantic.parse_obj_as(AddVariantFromBaseAndConfigResponse, _response.json()) # type: ignore
75
+ if _response.status_code == 422:
76
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
77
+ try:
78
+ _response_json = _response.json()
79
+ except JSONDecodeError:
80
+ raise ApiError(status_code=_response.status_code, body=_response.text)
81
+ raise ApiError(status_code=_response.status_code, body=_response_json)
82
+
83
+ def get_variant(self, variant_id: str) -> AppVariantResponse:
84
+ """
85
+ Parameters:
86
+ - variant_id: str.
87
+ ---
88
+ from agenta.client import AgentaApi
89
+
90
+ client = AgentaApi(
91
+ api_key="YOUR_API_KEY",
92
+ base_url="https://yourhost.com/path/to/api",
93
+ )
94
+ client.variants.get_variant(
95
+ variant_id="variant_id",
96
+ )
97
+ """
98
+ _response = self._client_wrapper.httpx_client.request(
99
+ "GET",
100
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"),
101
+ headers=self._client_wrapper.get_headers(),
102
+ timeout=60,
103
+ )
104
+ if 200 <= _response.status_code < 300:
105
+ return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
106
+ if _response.status_code == 422:
107
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
108
+ try:
109
+ _response_json = _response.json()
110
+ except JSONDecodeError:
111
+ raise ApiError(status_code=_response.status_code, body=_response.text)
112
+ raise ApiError(status_code=_response.status_code, body=_response_json)
113
+
114
+ def start_variant(
115
+ self, variant_id: str, *, action: VariantAction, env_vars: typing.Optional[DockerEnvVars] = OMIT
116
+ ) -> Uri:
117
+ """
118
+ Start a variant of an app.
119
+
120
+ Args:
121
+ variant_id (str): The ID of the variant to start.
122
+ action (VariantAction): The action to perform on the variant (start).
123
+ env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
124
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
125
+
126
+ Returns:
127
+ URI: The URL of the started variant.
128
+
129
+ Raises:
130
+ HTTPException: If the app container cannot be started.
131
+
132
+ Parameters:
133
+ - variant_id: str.
134
+
135
+ - action: VariantAction.
136
+
137
+ - env_vars: typing.Optional[DockerEnvVars].
138
+ ---
139
+ from agenta import VariantAction, VariantActionEnum
140
+ from agenta.client import AgentaApi
141
+
142
+ client = AgentaApi(
143
+ api_key="YOUR_API_KEY",
144
+ base_url="https://yourhost.com/path/to/api",
145
+ )
146
+ client.variants.start_variant(
147
+ variant_id="variant_id",
148
+ action=VariantAction(
149
+ action=VariantActionEnum.START,
150
+ ),
151
+ )
152
+ """
153
+ _request: typing.Dict[str, typing.Any] = {"action": action}
154
+ if env_vars is not OMIT:
155
+ _request["env_vars"] = env_vars
156
+ _response = self._client_wrapper.httpx_client.request(
157
+ "PUT",
158
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"),
159
+ json=jsonable_encoder(_request),
160
+ headers=self._client_wrapper.get_headers(),
161
+ timeout=60,
162
+ )
163
+ if 200 <= _response.status_code < 300:
164
+ return pydantic.parse_obj_as(Uri, _response.json()) # type: ignore
165
+ if _response.status_code == 422:
166
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
167
+ try:
168
+ _response_json = _response.json()
169
+ except JSONDecodeError:
170
+ raise ApiError(status_code=_response.status_code, body=_response.text)
171
+ raise ApiError(status_code=_response.status_code, body=_response_json)
172
+
173
+ def remove_variant(self, variant_id: str) -> typing.Any:
174
+ """
175
+ Remove a variant from the server.
176
+ In the case it's the last variant using the image, stop the container and remove the image.
177
+
178
+ Arguments:
179
+ app_variant -- AppVariant to remove
180
+
181
+ Raises:
182
+ HTTPException: If there is a problem removing the app variant
183
+
184
+ Parameters:
185
+ - variant_id: str.
186
+ ---
187
+ from agenta.client import AgentaApi
188
+
189
+ client = AgentaApi(
190
+ api_key="YOUR_API_KEY",
191
+ base_url="https://yourhost.com/path/to/api",
192
+ )
193
+ client.variants.remove_variant(
194
+ variant_id="variant_id",
195
+ )
196
+ """
197
+ _response = self._client_wrapper.httpx_client.request(
198
+ "DELETE",
199
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"),
200
+ headers=self._client_wrapper.get_headers(),
201
+ timeout=60,
202
+ )
203
+ if 200 <= _response.status_code < 300:
204
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
205
+ if _response.status_code == 422:
206
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
207
+ try:
208
+ _response_json = _response.json()
209
+ except JSONDecodeError:
210
+ raise ApiError(status_code=_response.status_code, body=_response.text)
211
+ raise ApiError(status_code=_response.status_code, body=_response_json)
212
+
213
+ def update_variant_parameters(self, variant_id: str, *, parameters: typing.Dict[str, typing.Any]) -> typing.Any:
214
+ """
215
+ Updates the parameters for an app variant.
216
+
217
+ Args:
218
+ variant_id (str): The ID of the app variant to update.
219
+ payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
220
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
221
+
222
+ Raises:
223
+ HTTPException: If there is an error while trying to update the app variant.
224
+
225
+ Returns:
226
+ JSONResponse: A JSON response containing the updated app variant parameters.
227
+
228
+ Parameters:
229
+ - variant_id: str.
230
+
231
+ - parameters: typing.Dict[str, typing.Any].
232
+ ---
233
+ from agenta.client import AgentaApi
234
+
235
+ client = AgentaApi(
236
+ api_key="YOUR_API_KEY",
237
+ base_url="https://yourhost.com/path/to/api",
238
+ )
239
+ client.variants.update_variant_parameters(
240
+ variant_id="variant_id",
241
+ parameters={},
242
+ )
243
+ """
244
+ _response = self._client_wrapper.httpx_client.request(
245
+ "PUT",
246
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/parameters"),
247
+ json=jsonable_encoder({"parameters": parameters}),
248
+ headers=self._client_wrapper.get_headers(),
249
+ timeout=60,
250
+ )
251
+ if 200 <= _response.status_code < 300:
252
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
253
+ if _response.status_code == 422:
254
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
255
+ try:
256
+ _response_json = _response.json()
257
+ except JSONDecodeError:
258
+ raise ApiError(status_code=_response.status_code, body=_response.text)
259
+ raise ApiError(status_code=_response.status_code, body=_response_json)
260
+
261
+ def update_variant_image(self, variant_id: str, *, request: Image) -> typing.Any:
262
+ """
263
+ Updates the image used in an app variant.
264
+
265
+ Args:
266
+ variant_id (str): The ID of the app variant to update.
267
+ image (Image): The image information to update.
268
+
269
+ Raises:
270
+ HTTPException: If an error occurs while trying to update the app variant.
271
+
272
+ Returns:
273
+ JSONResponse: A JSON response indicating whether the update was successful or not.
274
+
275
+ Parameters:
276
+ - variant_id: str.
277
+
278
+ - request: Image.
279
+ ---
280
+ from agenta import Image
281
+ from agenta.client import AgentaApi
282
+
283
+ client = AgentaApi(
284
+ api_key="YOUR_API_KEY",
285
+ base_url="https://yourhost.com/path/to/api",
286
+ )
287
+ client.variants.update_variant_image(
288
+ variant_id="variant_id",
289
+ request=Image(
290
+ docker_id="docker_id",
291
+ tags="tags",
292
+ ),
293
+ )
294
+ """
295
+ _response = self._client_wrapper.httpx_client.request(
296
+ "PUT",
297
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/image"),
298
+ json=jsonable_encoder(request),
299
+ headers=self._client_wrapper.get_headers(),
300
+ timeout=60,
301
+ )
302
+ if 200 <= _response.status_code < 300:
303
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
304
+ if _response.status_code == 422:
305
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
306
+ try:
307
+ _response_json = _response.json()
308
+ except JSONDecodeError:
309
+ raise ApiError(status_code=_response.status_code, body=_response.text)
310
+ raise ApiError(status_code=_response.status_code, body=_response_json)
311
+
312
+ def get_variant_revisions(self, variant_id: str) -> typing.List[AppVariantRevision]:
313
+ """
314
+ Parameters:
315
+ - variant_id: str.
316
+ ---
317
+ from agenta.client import AgentaApi
318
+
319
+ client = AgentaApi(
320
+ api_key="YOUR_API_KEY",
321
+ base_url="https://yourhost.com/path/to/api",
322
+ )
323
+ client.variants.get_variant_revisions(
324
+ variant_id="variant_id",
325
+ )
326
+ """
327
+ _response = self._client_wrapper.httpx_client.request(
328
+ "GET",
329
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/revisions"),
330
+ headers=self._client_wrapper.get_headers(),
331
+ timeout=60,
332
+ )
333
+ if 200 <= _response.status_code < 300:
334
+ return pydantic.parse_obj_as(typing.List[AppVariantRevision], _response.json()) # type: ignore
335
+ if _response.status_code == 422:
336
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
337
+ try:
338
+ _response_json = _response.json()
339
+ except JSONDecodeError:
340
+ raise ApiError(status_code=_response.status_code, body=_response.text)
341
+ raise ApiError(status_code=_response.status_code, body=_response_json)
342
+
343
+ def get_variant_revision(self, variant_id: str, revision_number: int) -> AppVariantRevision:
344
+ """
345
+ Parameters:
346
+ - variant_id: str.
347
+
348
+ - revision_number: int.
349
+ ---
350
+ from agenta.client import AgentaApi
351
+
352
+ client = AgentaApi(
353
+ api_key="YOUR_API_KEY",
354
+ base_url="https://yourhost.com/path/to/api",
355
+ )
356
+ client.variants.get_variant_revision(
357
+ variant_id="variant_id",
358
+ revision_number=1,
359
+ )
360
+ """
361
+ _response = self._client_wrapper.httpx_client.request(
362
+ "GET",
363
+ urllib.parse.urljoin(
364
+ f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/revisions/{revision_number}"
365
+ ),
366
+ headers=self._client_wrapper.get_headers(),
367
+ timeout=60,
368
+ )
369
+ if 200 <= _response.status_code < 300:
370
+ return pydantic.parse_obj_as(AppVariantRevision, _response.json()) # type: ignore
371
+ if _response.status_code == 422:
372
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
373
+ try:
374
+ _response_json = _response.json()
375
+ except JSONDecodeError:
376
+ raise ApiError(status_code=_response.status_code, body=_response.text)
377
+ raise ApiError(status_code=_response.status_code, body=_response_json)
378
+
379
+
380
+ class AsyncVariantsClient:
381
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
382
+ self._client_wrapper = client_wrapper
383
+
384
+ async def add_variant_from_base_and_config(
385
+ self, *, base_id: str, new_variant_name: str, new_config_name: str, parameters: typing.Dict[str, typing.Any]
386
+ ) -> AddVariantFromBaseAndConfigResponse:
387
+ """
388
+ Add a new variant based on an existing one.
389
+ Same as POST /config
390
+
391
+ Args:
392
+ payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
393
+ stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
394
+
395
+ Raises:
396
+ HTTPException: Raised if the variant could not be added or accessed.
397
+
398
+ Returns:
399
+ Union[AppVariantResponse, Any]: New variant details or exception.
400
+
401
+ Parameters:
402
+ - base_id: str.
403
+
404
+ - new_variant_name: str.
405
+
406
+ - new_config_name: str.
407
+
408
+ - parameters: typing.Dict[str, typing.Any].
409
+ """
410
+ _response = await self._client_wrapper.httpx_client.request(
411
+ "POST",
412
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "variants/from-base"),
413
+ json=jsonable_encoder(
414
+ {
415
+ "base_id": base_id,
416
+ "new_variant_name": new_variant_name,
417
+ "new_config_name": new_config_name,
418
+ "parameters": parameters,
419
+ }
420
+ ),
421
+ headers=self._client_wrapper.get_headers(),
422
+ timeout=60,
423
+ )
424
+ if 200 <= _response.status_code < 300:
425
+ return pydantic.parse_obj_as(AddVariantFromBaseAndConfigResponse, _response.json()) # type: ignore
426
+ if _response.status_code == 422:
427
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
428
+ try:
429
+ _response_json = _response.json()
430
+ except JSONDecodeError:
431
+ raise ApiError(status_code=_response.status_code, body=_response.text)
432
+ raise ApiError(status_code=_response.status_code, body=_response_json)
433
+
434
+ async def get_variant(self, variant_id: str) -> AppVariantResponse:
435
+ """
436
+ Parameters:
437
+ - variant_id: str.
438
+ ---
439
+ from agenta.client import AsyncAgentaApi
440
+
441
+ client = AsyncAgentaApi(
442
+ api_key="YOUR_API_KEY",
443
+ base_url="https://yourhost.com/path/to/api",
444
+ )
445
+ await client.variants.get_variant(
446
+ variant_id="variant_id",
447
+ )
448
+ """
449
+ _response = await self._client_wrapper.httpx_client.request(
450
+ "GET",
451
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"),
452
+ headers=self._client_wrapper.get_headers(),
453
+ timeout=60,
454
+ )
455
+ if 200 <= _response.status_code < 300:
456
+ return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
457
+ if _response.status_code == 422:
458
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
459
+ try:
460
+ _response_json = _response.json()
461
+ except JSONDecodeError:
462
+ raise ApiError(status_code=_response.status_code, body=_response.text)
463
+ raise ApiError(status_code=_response.status_code, body=_response_json)
464
+
465
+ async def start_variant(
466
+ self, variant_id: str, *, action: VariantAction, env_vars: typing.Optional[DockerEnvVars] = OMIT
467
+ ) -> Uri:
468
+ """
469
+ Start a variant of an app.
470
+
471
+ Args:
472
+ variant_id (str): The ID of the variant to start.
473
+ action (VariantAction): The action to perform on the variant (start).
474
+ env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
475
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
476
+
477
+ Returns:
478
+ URI: The URL of the started variant.
479
+
480
+ Raises:
481
+ HTTPException: If the app container cannot be started.
482
+
483
+ Parameters:
484
+ - variant_id: str.
485
+
486
+ - action: VariantAction.
487
+
488
+ - env_vars: typing.Optional[DockerEnvVars].
489
+ ---
490
+ from agenta import VariantAction, VariantActionEnum
491
+ from agenta.client import AsyncAgentaApi
492
+
493
+ client = AsyncAgentaApi(
494
+ api_key="YOUR_API_KEY",
495
+ base_url="https://yourhost.com/path/to/api",
496
+ )
497
+ await client.variants.start_variant(
498
+ variant_id="variant_id",
499
+ action=VariantAction(
500
+ action=VariantActionEnum.START,
501
+ ),
502
+ )
503
+ """
504
+ _request: typing.Dict[str, typing.Any] = {"action": action}
505
+ if env_vars is not OMIT:
506
+ _request["env_vars"] = env_vars
507
+ _response = await self._client_wrapper.httpx_client.request(
508
+ "PUT",
509
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"),
510
+ json=jsonable_encoder(_request),
511
+ headers=self._client_wrapper.get_headers(),
512
+ timeout=60,
513
+ )
514
+ if 200 <= _response.status_code < 300:
515
+ return pydantic.parse_obj_as(Uri, _response.json()) # type: ignore
516
+ if _response.status_code == 422:
517
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
518
+ try:
519
+ _response_json = _response.json()
520
+ except JSONDecodeError:
521
+ raise ApiError(status_code=_response.status_code, body=_response.text)
522
+ raise ApiError(status_code=_response.status_code, body=_response_json)
523
+
524
+ async def remove_variant(self, variant_id: str) -> typing.Any:
525
+ """
526
+ Remove a variant from the server.
527
+ In the case it's the last variant using the image, stop the container and remove the image.
528
+
529
+ Arguments:
530
+ app_variant -- AppVariant to remove
531
+
532
+ Raises:
533
+ HTTPException: If there is a problem removing the app variant
534
+
535
+ Parameters:
536
+ - variant_id: str.
537
+ ---
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.variants.remove_variant(
545
+ variant_id="variant_id",
546
+ )
547
+ """
548
+ _response = await self._client_wrapper.httpx_client.request(
549
+ "DELETE",
550
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"),
551
+ headers=self._client_wrapper.get_headers(),
552
+ timeout=60,
553
+ )
554
+ if 200 <= _response.status_code < 300:
555
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
556
+ if _response.status_code == 422:
557
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
558
+ try:
559
+ _response_json = _response.json()
560
+ except JSONDecodeError:
561
+ raise ApiError(status_code=_response.status_code, body=_response.text)
562
+ raise ApiError(status_code=_response.status_code, body=_response_json)
563
+
564
+ async def update_variant_parameters(
565
+ self, variant_id: str, *, parameters: typing.Dict[str, typing.Any]
566
+ ) -> typing.Any:
567
+ """
568
+ Updates the parameters for an app variant.
569
+
570
+ Args:
571
+ variant_id (str): The ID of the app variant to update.
572
+ payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
573
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
574
+
575
+ Raises:
576
+ HTTPException: If there is an error while trying to update the app variant.
577
+
578
+ Returns:
579
+ JSONResponse: A JSON response containing the updated app variant parameters.
580
+
581
+ Parameters:
582
+ - variant_id: str.
583
+
584
+ - parameters: typing.Dict[str, typing.Any].
585
+ ---
586
+ from agenta.client import AsyncAgentaApi
587
+
588
+ client = AsyncAgentaApi(
589
+ api_key="YOUR_API_KEY",
590
+ base_url="https://yourhost.com/path/to/api",
591
+ )
592
+ await client.variants.update_variant_parameters(
593
+ variant_id="variant_id",
594
+ parameters={},
595
+ )
596
+ """
597
+ _response = await self._client_wrapper.httpx_client.request(
598
+ "PUT",
599
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/parameters"),
600
+ json=jsonable_encoder({"parameters": parameters}),
601
+ headers=self._client_wrapper.get_headers(),
602
+ timeout=60,
603
+ )
604
+ if 200 <= _response.status_code < 300:
605
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
606
+ if _response.status_code == 422:
607
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
608
+ try:
609
+ _response_json = _response.json()
610
+ except JSONDecodeError:
611
+ raise ApiError(status_code=_response.status_code, body=_response.text)
612
+ raise ApiError(status_code=_response.status_code, body=_response_json)
613
+
614
+ async def update_variant_image(self, variant_id: str, *, request: Image) -> typing.Any:
615
+ """
616
+ Updates the image used in an app variant.
617
+
618
+ Args:
619
+ variant_id (str): The ID of the app variant to update.
620
+ image (Image): The image information to update.
621
+
622
+ Raises:
623
+ HTTPException: If an error occurs while trying to update the app variant.
624
+
625
+ Returns:
626
+ JSONResponse: A JSON response indicating whether the update was successful or not.
627
+
628
+ Parameters:
629
+ - variant_id: str.
630
+
631
+ - request: Image.
632
+ ---
633
+ from agenta import Image
634
+ from agenta.client import AsyncAgentaApi
635
+
636
+ client = AsyncAgentaApi(
637
+ api_key="YOUR_API_KEY",
638
+ base_url="https://yourhost.com/path/to/api",
639
+ )
640
+ await client.variants.update_variant_image(
641
+ variant_id="variant_id",
642
+ request=Image(
643
+ docker_id="docker_id",
644
+ tags="tags",
645
+ ),
646
+ )
647
+ """
648
+ _response = await self._client_wrapper.httpx_client.request(
649
+ "PUT",
650
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/image"),
651
+ json=jsonable_encoder(request),
652
+ headers=self._client_wrapper.get_headers(),
653
+ timeout=60,
654
+ )
655
+ if 200 <= _response.status_code < 300:
656
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
657
+ if _response.status_code == 422:
658
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
659
+ try:
660
+ _response_json = _response.json()
661
+ except JSONDecodeError:
662
+ raise ApiError(status_code=_response.status_code, body=_response.text)
663
+ raise ApiError(status_code=_response.status_code, body=_response_json)
664
+
665
+ async def get_variant_revisions(self, variant_id: str) -> typing.List[AppVariantRevision]:
666
+ """
667
+ Parameters:
668
+ - variant_id: str.
669
+ ---
670
+ from agenta.client import AsyncAgentaApi
671
+
672
+ client = AsyncAgentaApi(
673
+ api_key="YOUR_API_KEY",
674
+ base_url="https://yourhost.com/path/to/api",
675
+ )
676
+ await client.variants.get_variant_revisions(
677
+ variant_id="variant_id",
678
+ )
679
+ """
680
+ _response = await self._client_wrapper.httpx_client.request(
681
+ "GET",
682
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/revisions"),
683
+ headers=self._client_wrapper.get_headers(),
684
+ timeout=60,
685
+ )
686
+ if 200 <= _response.status_code < 300:
687
+ return pydantic.parse_obj_as(typing.List[AppVariantRevision], _response.json()) # type: ignore
688
+ if _response.status_code == 422:
689
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
690
+ try:
691
+ _response_json = _response.json()
692
+ except JSONDecodeError:
693
+ raise ApiError(status_code=_response.status_code, body=_response.text)
694
+ raise ApiError(status_code=_response.status_code, body=_response_json)
695
+
696
+ async def get_variant_revision(self, variant_id: str, revision_number: int) -> AppVariantRevision:
697
+ """
698
+ Parameters:
699
+ - variant_id: str.
700
+
701
+ - revision_number: int.
702
+ ---
703
+ from agenta.client import AsyncAgentaApi
704
+
705
+ client = AsyncAgentaApi(
706
+ api_key="YOUR_API_KEY",
707
+ base_url="https://yourhost.com/path/to/api",
708
+ )
709
+ await client.variants.get_variant_revision(
710
+ variant_id="variant_id",
711
+ revision_number=1,
712
+ )
713
+ """
714
+ _response = await self._client_wrapper.httpx_client.request(
715
+ "GET",
716
+ urllib.parse.urljoin(
717
+ f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}/revisions/{revision_number}"
718
+ ),
719
+ headers=self._client_wrapper.get_headers(),
720
+ timeout=60,
721
+ )
722
+ if 200 <= _response.status_code < 300:
723
+ return pydantic.parse_obj_as(AppVariantRevision, _response.json()) # type: ignore
724
+ if _response.status_code == 422:
725
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
726
+ try:
727
+ _response_json = _response.json()
728
+ except JSONDecodeError:
729
+ raise ApiError(status_code=_response.status_code, body=_response.text)
730
+ raise ApiError(status_code=_response.status_code, body=_response_json)