agenta 0.24.1a0__py3-none-any.whl → 0.24.2a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of agenta might be problematic. Click here for more details.

Files changed (132) hide show
  1. agenta/cli/variant_commands.py +15 -10
  2. agenta/client/Readme.md +72 -64
  3. agenta/client/api.py +1 -1
  4. agenta/client/backend/__init__.py +14 -9
  5. agenta/client/backend/apps/client.py +1669 -0
  6. agenta/client/backend/bases/client.py +190 -0
  7. agenta/client/backend/client.py +2102 -868
  8. agenta/client/backend/configs/client.py +598 -0
  9. agenta/client/backend/containers/client.py +638 -0
  10. agenta/client/backend/{resources/containers → containers}/types/container_templates_response.py +1 -2
  11. agenta/client/backend/core/__init__.py +29 -0
  12. agenta/client/backend/core/client_wrapper.py +42 -9
  13. agenta/client/backend/core/datetime_utils.py +1 -1
  14. agenta/client/backend/core/file.py +43 -0
  15. agenta/client/backend/core/http_client.py +553 -0
  16. agenta/client/backend/core/jsonable_encoder.py +33 -39
  17. agenta/client/backend/core/pydantic_utilities.py +212 -0
  18. agenta/client/backend/core/query_encoder.py +60 -0
  19. agenta/client/backend/core/remove_none_from_dict.py +2 -2
  20. agenta/client/backend/core/request_options.py +32 -0
  21. agenta/client/backend/core/serialization.py +179 -0
  22. agenta/client/backend/environments/client.py +190 -0
  23. agenta/client/backend/evaluations/client.py +1462 -0
  24. agenta/client/backend/evaluators/client.py +911 -0
  25. agenta/client/backend/observability/client.py +1271 -0
  26. agenta/client/backend/testsets/client.py +1132 -0
  27. agenta/client/backend/types/__init__.py +8 -6
  28. agenta/client/backend/types/aggregated_result.py +14 -29
  29. agenta/client/backend/types/aggregated_result_evaluator_config.py +1 -2
  30. agenta/client/backend/types/app.py +13 -28
  31. agenta/client/backend/types/app_variant_response.py +21 -37
  32. agenta/client/backend/types/app_variant_revision.py +17 -32
  33. agenta/client/backend/types/base_output.py +13 -28
  34. agenta/client/backend/types/body_import_testset.py +16 -31
  35. agenta/client/backend/types/config_db.py +16 -31
  36. agenta/client/backend/types/correct_answer.py +22 -0
  37. agenta/client/backend/types/create_app_output.py +13 -28
  38. agenta/client/backend/types/create_span.py +33 -50
  39. agenta/client/backend/types/create_trace_response.py +16 -31
  40. agenta/client/backend/types/docker_env_vars.py +13 -28
  41. agenta/client/backend/types/environment_output.py +21 -36
  42. agenta/client/backend/types/environment_output_extended.py +21 -36
  43. agenta/client/backend/types/environment_revision.py +18 -33
  44. agenta/client/backend/types/error.py +16 -31
  45. agenta/client/backend/types/evaluation.py +20 -34
  46. agenta/client/backend/types/evaluation_scenario.py +18 -33
  47. agenta/client/backend/types/evaluation_scenario_input.py +16 -31
  48. agenta/client/backend/types/evaluation_scenario_output.py +18 -33
  49. agenta/client/backend/types/evaluation_scenario_result.py +14 -29
  50. agenta/client/backend/types/evaluation_scenario_score_update.py +13 -28
  51. agenta/client/backend/types/evaluation_status_enum.py +11 -33
  52. agenta/client/backend/types/evaluation_type.py +3 -21
  53. agenta/client/backend/types/evaluator.py +18 -32
  54. agenta/client/backend/types/evaluator_config.py +20 -33
  55. agenta/client/backend/types/get_config_response.py +16 -31
  56. agenta/client/backend/types/http_validation_error.py +14 -29
  57. agenta/client/backend/types/human_evaluation.py +17 -32
  58. agenta/client/backend/types/human_evaluation_scenario.py +21 -37
  59. agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
  60. agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
  61. agenta/client/backend/types/human_evaluation_scenario_update.py +26 -41
  62. agenta/client/backend/types/human_evaluation_update.py +14 -29
  63. agenta/client/backend/types/image.py +18 -33
  64. agenta/client/backend/types/invite_request.py +13 -28
  65. agenta/client/backend/types/list_api_keys_response.py +18 -33
  66. agenta/client/backend/types/llm_run_rate_limit.py +13 -28
  67. agenta/client/backend/types/llm_tokens.py +16 -31
  68. agenta/client/backend/types/lm_providers_enum.py +21 -0
  69. agenta/client/backend/types/new_human_evaluation.py +13 -28
  70. agenta/client/backend/types/new_testset.py +16 -31
  71. agenta/client/backend/types/organization.py +22 -36
  72. agenta/client/backend/types/organization_output.py +13 -28
  73. agenta/client/backend/types/outputs.py +5 -0
  74. agenta/client/backend/types/permission.py +36 -137
  75. agenta/client/backend/types/result.py +17 -32
  76. agenta/client/backend/types/simple_evaluation_output.py +13 -28
  77. agenta/client/backend/types/span.py +23 -38
  78. agenta/client/backend/types/span_detail.py +26 -40
  79. agenta/client/backend/types/span_status_code.py +1 -25
  80. agenta/client/backend/types/span_variant.py +16 -31
  81. agenta/client/backend/types/template.py +14 -29
  82. agenta/client/backend/types/template_image_info.py +21 -35
  83. agenta/client/backend/types/test_set_output_response.py +16 -32
  84. agenta/client/backend/types/test_set_simple_response.py +13 -28
  85. agenta/client/backend/types/trace_detail.py +26 -40
  86. agenta/client/backend/types/update_app_output.py +22 -0
  87. agenta/client/backend/types/uri.py +13 -28
  88. agenta/client/backend/types/validation_error.py +13 -28
  89. agenta/client/backend/types/variant_action.py +14 -29
  90. agenta/client/backend/types/variant_action_enum.py +1 -19
  91. agenta/client/backend/types/with_pagination.py +14 -30
  92. agenta/client/backend/types/workspace_member_response.py +14 -29
  93. agenta/client/backend/types/workspace_permission.py +18 -33
  94. agenta/client/backend/types/workspace_response.py +20 -35
  95. agenta/client/backend/types/workspace_role.py +11 -37
  96. agenta/client/backend/types/workspace_role_response.py +17 -32
  97. agenta/client/backend/variants/client.py +1447 -0
  98. agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
  99. agenta/sdk/decorators/llm_entrypoint.py +8 -13
  100. agenta/sdk/tracing/llm_tracing.py +1 -1
  101. {agenta-0.24.1a0.dist-info → agenta-0.24.2a1.dist-info}/METADATA +1 -1
  102. agenta-0.24.2a1.dist-info/RECORD +175 -0
  103. agenta/client/backend/resources/__init__.py +0 -31
  104. agenta/client/backend/resources/apps/client.py +0 -977
  105. agenta/client/backend/resources/bases/client.py +0 -127
  106. agenta/client/backend/resources/configs/client.py +0 -377
  107. agenta/client/backend/resources/containers/client.py +0 -383
  108. agenta/client/backend/resources/environments/client.py +0 -131
  109. agenta/client/backend/resources/evaluations/client.py +0 -1008
  110. agenta/client/backend/resources/evaluators/client.py +0 -594
  111. agenta/client/backend/resources/observability/client.py +0 -1187
  112. agenta/client/backend/resources/testsets/client.py +0 -689
  113. agenta/client/backend/resources/variants/client.py +0 -796
  114. agenta/client/backend/resources/variants/types/add_variant_from_base_and_config_response.py +0 -7
  115. agenta/client/backend/types/evaluation_webhook.py +0 -36
  116. agenta/client/backend/types/feedback.py +0 -40
  117. agenta/client/backend/types/span_kind.py +0 -49
  118. agenta-0.24.1a0.dist-info/RECORD +0 -169
  119. /agenta/client/backend/{resources/apps → apps}/__init__.py +0 -0
  120. /agenta/client/backend/{resources/bases → bases}/__init__.py +0 -0
  121. /agenta/client/backend/{resources/configs → configs}/__init__.py +0 -0
  122. /agenta/client/backend/{resources/containers → containers}/__init__.py +0 -0
  123. /agenta/client/backend/{resources/containers → containers}/types/__init__.py +0 -0
  124. /agenta/client/backend/{resources/environments → environments}/__init__.py +0 -0
  125. /agenta/client/backend/{resources/evaluations → evaluations}/__init__.py +0 -0
  126. /agenta/client/backend/{resources/evaluators → evaluators}/__init__.py +0 -0
  127. /agenta/client/backend/{resources/observability → observability}/__init__.py +0 -0
  128. /agenta/client/backend/{resources/testsets → testsets}/__init__.py +0 -0
  129. /agenta/client/backend/{resources/variants → variants}/__init__.py +0 -0
  130. /agenta/client/backend/{resources/variants → variants}/types/__init__.py +0 -0
  131. {agenta-0.24.1a0.dist-info → agenta-0.24.2a1.dist-info}/WHEEL +0 -0
  132. {agenta-0.24.1a0.dist-info → agenta-0.24.2a1.dist-info}/entry_points.txt +0 -0
@@ -1,796 +0,0 @@
1
- # This file was auto-generated by Fern from our API Definition.
2
-
3
- import typing
4
- import urllib.parse
5
- from json.decoder import JSONDecodeError
6
-
7
- from ...core.api_error import ApiError
8
- from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9
- from ...core.jsonable_encoder import jsonable_encoder
10
- from ...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 (
19
- AddVariantFromBaseAndConfigResponse,
20
- )
21
-
22
- try:
23
- import pydantic.v1 as pydantic # type: ignore
24
- except ImportError:
25
- import pydantic # type: ignore
26
-
27
- # this is used as the default value for optional parameters
28
- OMIT = typing.cast(typing.Any, ...)
29
-
30
-
31
- class VariantsClient:
32
- def __init__(self, *, client_wrapper: SyncClientWrapper):
33
- self._client_wrapper = client_wrapper
34
-
35
- def add_variant_from_base_and_config(
36
- self,
37
- *,
38
- base_id: str,
39
- new_variant_name: str,
40
- new_config_name: str,
41
- parameters: typing.Dict[str, typing.Any],
42
- ) -> AddVariantFromBaseAndConfigResponse:
43
- """
44
- Add a new variant based on an existing one.
45
- Same as POST /config
46
-
47
- Args:
48
- payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
49
- stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
50
-
51
- Raises:
52
- HTTPException: Raised if the variant could not be added or accessed.
53
-
54
- Returns:
55
- Union[AppVariantResponse, Any]: New variant details or exception.
56
-
57
- Parameters:
58
- - base_id: str.
59
-
60
- - new_variant_name: str.
61
-
62
- - new_config_name: str.
63
-
64
- - parameters: typing.Dict[str, typing.Any].
65
- """
66
- _response = self._client_wrapper.httpx_client.request(
67
- "POST",
68
- urllib.parse.urljoin(
69
- f"{self._client_wrapper.get_base_url()}/", "variants/from-base"
70
- ),
71
- json=jsonable_encoder(
72
- {
73
- "base_id": base_id,
74
- "new_variant_name": new_variant_name,
75
- "new_config_name": new_config_name,
76
- "parameters": parameters,
77
- }
78
- ),
79
- headers=self._client_wrapper.get_headers(),
80
- timeout=60,
81
- )
82
- if 200 <= _response.status_code < 300:
83
- return pydantic.parse_obj_as(AddVariantFromBaseAndConfigResponse, _response.json()) # type: ignore
84
- if _response.status_code == 422:
85
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
86
- try:
87
- _response_json = _response.json()
88
- except JSONDecodeError:
89
- raise ApiError(status_code=_response.status_code, body=_response.text)
90
- raise ApiError(status_code=_response.status_code, body=_response_json)
91
-
92
- def get_variant(self, variant_id: str) -> AppVariantResponse:
93
- """
94
- Parameters:
95
- - variant_id: str.
96
- ---
97
- from agenta.client import AgentaApi
98
-
99
- client = AgentaApi(
100
- api_key="YOUR_API_KEY",
101
- base_url="https://yourhost.com/path/to/api",
102
- )
103
- client.variants.get_variant(
104
- variant_id="variant_id",
105
- )
106
- """
107
- _response = self._client_wrapper.httpx_client.request(
108
- "GET",
109
- urllib.parse.urljoin(
110
- f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"
111
- ),
112
- headers=self._client_wrapper.get_headers(),
113
- timeout=60,
114
- )
115
- if 200 <= _response.status_code < 300:
116
- return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
117
- if _response.status_code == 422:
118
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
119
- try:
120
- _response_json = _response.json()
121
- except JSONDecodeError:
122
- raise ApiError(status_code=_response.status_code, body=_response.text)
123
- raise ApiError(status_code=_response.status_code, body=_response_json)
124
-
125
- def start_variant(
126
- self,
127
- variant_id: str,
128
- *,
129
- action: VariantAction,
130
- env_vars: typing.Optional[DockerEnvVars] = OMIT,
131
- ) -> Uri:
132
- """
133
- Start a variant of an app.
134
-
135
- Args:
136
- variant_id (str): The ID of the variant to start.
137
- action (VariantAction): The action to perform on the variant (start).
138
- env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
139
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
140
-
141
- Returns:
142
- URI: The URL of the started variant.
143
-
144
- Raises:
145
- HTTPException: If the app container cannot be started.
146
-
147
- Parameters:
148
- - variant_id: str.
149
-
150
- - action: VariantAction.
151
-
152
- - env_vars: typing.Optional[DockerEnvVars].
153
- ---
154
- from agenta import VariantAction, VariantActionEnum
155
- from agenta.client import AgentaApi
156
-
157
- client = AgentaApi(
158
- api_key="YOUR_API_KEY",
159
- base_url="https://yourhost.com/path/to/api",
160
- )
161
- client.variants.start_variant(
162
- variant_id="variant_id",
163
- action=VariantAction(
164
- action=VariantActionEnum.START,
165
- ),
166
- )
167
- """
168
- _request: typing.Dict[str, typing.Any] = {"action": action}
169
- if env_vars is not OMIT:
170
- _request["env_vars"] = env_vars
171
- _response = self._client_wrapper.httpx_client.request(
172
- "PUT",
173
- urllib.parse.urljoin(
174
- f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"
175
- ),
176
- json=jsonable_encoder(_request),
177
- headers=self._client_wrapper.get_headers(),
178
- timeout=60,
179
- )
180
- if 200 <= _response.status_code < 300:
181
- return pydantic.parse_obj_as(Uri, _response.json()) # type: ignore
182
- if _response.status_code == 422:
183
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
184
- try:
185
- _response_json = _response.json()
186
- except JSONDecodeError:
187
- raise ApiError(status_code=_response.status_code, body=_response.text)
188
- raise ApiError(status_code=_response.status_code, body=_response_json)
189
-
190
- def remove_variant(self, variant_id: str) -> typing.Any:
191
- """
192
- Remove a variant from the server.
193
- In the case it's the last variant using the image, stop the container and remove the image.
194
-
195
- Arguments:
196
- app_variant -- AppVariant to remove
197
-
198
- Raises:
199
- HTTPException: If there is a problem removing the app variant
200
-
201
- Parameters:
202
- - variant_id: str.
203
- ---
204
- from agenta.client import AgentaApi
205
-
206
- client = AgentaApi(
207
- api_key="YOUR_API_KEY",
208
- base_url="https://yourhost.com/path/to/api",
209
- )
210
- client.variants.remove_variant(
211
- variant_id="variant_id",
212
- )
213
- """
214
- _response = self._client_wrapper.httpx_client.request(
215
- "DELETE",
216
- urllib.parse.urljoin(
217
- f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"
218
- ),
219
- headers=self._client_wrapper.get_headers(),
220
- timeout=60,
221
- )
222
- if 200 <= _response.status_code < 300:
223
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
224
- if _response.status_code == 422:
225
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
226
- try:
227
- _response_json = _response.json()
228
- except JSONDecodeError:
229
- raise ApiError(status_code=_response.status_code, body=_response.text)
230
- raise ApiError(status_code=_response.status_code, body=_response_json)
231
-
232
- def update_variant_parameters(
233
- self, variant_id: str, *, parameters: typing.Dict[str, typing.Any]
234
- ) -> typing.Any:
235
- """
236
- Updates the parameters for an app variant.
237
-
238
- Args:
239
- variant_id (str): The ID of the app variant to update.
240
- payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
241
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
242
-
243
- Raises:
244
- HTTPException: If there is an error while trying to update the app variant.
245
-
246
- Returns:
247
- JSONResponse: A JSON response containing the updated app variant parameters.
248
-
249
- Parameters:
250
- - variant_id: str.
251
-
252
- - parameters: typing.Dict[str, typing.Any].
253
- ---
254
- from agenta.client import AgentaApi
255
-
256
- client = AgentaApi(
257
- api_key="YOUR_API_KEY",
258
- base_url="https://yourhost.com/path/to/api",
259
- )
260
- client.variants.update_variant_parameters(
261
- variant_id="variant_id",
262
- parameters={},
263
- )
264
- """
265
- _response = self._client_wrapper.httpx_client.request(
266
- "PUT",
267
- urllib.parse.urljoin(
268
- f"{self._client_wrapper.get_base_url()}/",
269
- f"variants/{variant_id}/parameters",
270
- ),
271
- json=jsonable_encoder({"parameters": parameters}),
272
- headers=self._client_wrapper.get_headers(),
273
- timeout=60,
274
- )
275
- if 200 <= _response.status_code < 300:
276
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
277
- if _response.status_code == 422:
278
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
279
- try:
280
- _response_json = _response.json()
281
- except JSONDecodeError:
282
- raise ApiError(status_code=_response.status_code, body=_response.text)
283
- raise ApiError(status_code=_response.status_code, body=_response_json)
284
-
285
- def update_variant_image(self, variant_id: str, *, request: Image) -> typing.Any:
286
- """
287
- Updates the image used in an app variant.
288
-
289
- Args:
290
- variant_id (str): The ID of the app variant to update.
291
- image (Image): The image information to update.
292
-
293
- Raises:
294
- HTTPException: If an error occurs while trying to update the app variant.
295
-
296
- Returns:
297
- JSONResponse: A JSON response indicating whether the update was successful or not.
298
-
299
- Parameters:
300
- - variant_id: str.
301
-
302
- - request: Image.
303
- ---
304
- from agenta import Image
305
- from agenta.client import AgentaApi
306
-
307
- client = AgentaApi(
308
- api_key="YOUR_API_KEY",
309
- base_url="https://yourhost.com/path/to/api",
310
- )
311
- client.variants.update_variant_image(
312
- variant_id="variant_id",
313
- request=Image(
314
- docker_id="docker_id",
315
- tags="tags",
316
- ),
317
- )
318
- """
319
- _response = self._client_wrapper.httpx_client.request(
320
- "PUT",
321
- urllib.parse.urljoin(
322
- f"{self._client_wrapper.get_base_url()}/",
323
- f"variants/{variant_id}/image",
324
- ),
325
- json=jsonable_encoder(request),
326
- headers=self._client_wrapper.get_headers(),
327
- timeout=60,
328
- )
329
- if 200 <= _response.status_code < 300:
330
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
331
- if _response.status_code == 422:
332
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
333
- try:
334
- _response_json = _response.json()
335
- except JSONDecodeError:
336
- raise ApiError(status_code=_response.status_code, body=_response.text)
337
- raise ApiError(status_code=_response.status_code, body=_response_json)
338
-
339
- def get_variant_revisions(self, variant_id: str) -> typing.List[AppVariantRevision]:
340
- """
341
- Parameters:
342
- - variant_id: str.
343
- ---
344
- from agenta.client import AgentaApi
345
-
346
- client = AgentaApi(
347
- api_key="YOUR_API_KEY",
348
- base_url="https://yourhost.com/path/to/api",
349
- )
350
- client.variants.get_variant_revisions(
351
- variant_id="variant_id",
352
- )
353
- """
354
- _response = self._client_wrapper.httpx_client.request(
355
- "GET",
356
- urllib.parse.urljoin(
357
- f"{self._client_wrapper.get_base_url()}/",
358
- f"variants/{variant_id}/revisions",
359
- ),
360
- headers=self._client_wrapper.get_headers(),
361
- timeout=60,
362
- )
363
- if 200 <= _response.status_code < 300:
364
- return pydantic.parse_obj_as(typing.List[AppVariantRevision], _response.json()) # type: ignore
365
- if _response.status_code == 422:
366
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
367
- try:
368
- _response_json = _response.json()
369
- except JSONDecodeError:
370
- raise ApiError(status_code=_response.status_code, body=_response.text)
371
- raise ApiError(status_code=_response.status_code, body=_response_json)
372
-
373
- def get_variant_revision(
374
- self, variant_id: str, revision_number: int
375
- ) -> AppVariantRevision:
376
- """
377
- Parameters:
378
- - variant_id: str.
379
-
380
- - revision_number: int.
381
- ---
382
- from agenta.client import AgentaApi
383
-
384
- client = AgentaApi(
385
- api_key="YOUR_API_KEY",
386
- base_url="https://yourhost.com/path/to/api",
387
- )
388
- client.variants.get_variant_revision(
389
- variant_id="variant_id",
390
- revision_number=1,
391
- )
392
- """
393
- _response = self._client_wrapper.httpx_client.request(
394
- "GET",
395
- urllib.parse.urljoin(
396
- f"{self._client_wrapper.get_base_url()}/",
397
- f"variants/{variant_id}/revisions/{revision_number}",
398
- ),
399
- headers=self._client_wrapper.get_headers(),
400
- timeout=60,
401
- )
402
- if 200 <= _response.status_code < 300:
403
- return pydantic.parse_obj_as(AppVariantRevision, _response.json()) # type: ignore
404
- if _response.status_code == 422:
405
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
406
- try:
407
- _response_json = _response.json()
408
- except JSONDecodeError:
409
- raise ApiError(status_code=_response.status_code, body=_response.text)
410
- raise ApiError(status_code=_response.status_code, body=_response_json)
411
-
412
-
413
- class AsyncVariantsClient:
414
- def __init__(self, *, client_wrapper: AsyncClientWrapper):
415
- self._client_wrapper = client_wrapper
416
-
417
- async def add_variant_from_base_and_config(
418
- self,
419
- *,
420
- base_id: str,
421
- new_variant_name: str,
422
- new_config_name: str,
423
- parameters: typing.Dict[str, typing.Any],
424
- ) -> AddVariantFromBaseAndConfigResponse:
425
- """
426
- Add a new variant based on an existing one.
427
- Same as POST /config
428
-
429
- Args:
430
- payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.
431
- stoken_session (SessionContainer, optional): Session container. Defaults to result of verify_session().
432
-
433
- Raises:
434
- HTTPException: Raised if the variant could not be added or accessed.
435
-
436
- Returns:
437
- Union[AppVariantResponse, Any]: New variant details or exception.
438
-
439
- Parameters:
440
- - base_id: str.
441
-
442
- - new_variant_name: str.
443
-
444
- - new_config_name: str.
445
-
446
- - parameters: typing.Dict[str, typing.Any].
447
- """
448
- _response = await self._client_wrapper.httpx_client.request(
449
- "POST",
450
- urllib.parse.urljoin(
451
- f"{self._client_wrapper.get_base_url()}/", "variants/from-base"
452
- ),
453
- json=jsonable_encoder(
454
- {
455
- "base_id": base_id,
456
- "new_variant_name": new_variant_name,
457
- "new_config_name": new_config_name,
458
- "parameters": parameters,
459
- }
460
- ),
461
- headers=self._client_wrapper.get_headers(),
462
- timeout=60,
463
- )
464
- if 200 <= _response.status_code < 300:
465
- return pydantic.parse_obj_as(AddVariantFromBaseAndConfigResponse, _response.json()) # type: ignore
466
- if _response.status_code == 422:
467
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
468
- try:
469
- _response_json = _response.json()
470
- except JSONDecodeError:
471
- raise ApiError(status_code=_response.status_code, body=_response.text)
472
- raise ApiError(status_code=_response.status_code, body=_response_json)
473
-
474
- async def get_variant(self, variant_id: str) -> AppVariantResponse:
475
- """
476
- Parameters:
477
- - variant_id: str.
478
- ---
479
- from agenta.client import AsyncAgentaApi
480
-
481
- client = AsyncAgentaApi(
482
- api_key="YOUR_API_KEY",
483
- base_url="https://yourhost.com/path/to/api",
484
- )
485
- await client.variants.get_variant(
486
- variant_id="variant_id",
487
- )
488
- """
489
- _response = await self._client_wrapper.httpx_client.request(
490
- "GET",
491
- urllib.parse.urljoin(
492
- f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"
493
- ),
494
- headers=self._client_wrapper.get_headers(),
495
- timeout=60,
496
- )
497
- if 200 <= _response.status_code < 300:
498
- return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
499
- if _response.status_code == 422:
500
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
501
- try:
502
- _response_json = _response.json()
503
- except JSONDecodeError:
504
- raise ApiError(status_code=_response.status_code, body=_response.text)
505
- raise ApiError(status_code=_response.status_code, body=_response_json)
506
-
507
- async def start_variant(
508
- self,
509
- variant_id: str,
510
- *,
511
- action: VariantAction,
512
- env_vars: typing.Optional[DockerEnvVars] = OMIT,
513
- ) -> Uri:
514
- """
515
- Start a variant of an app.
516
-
517
- Args:
518
- variant_id (str): The ID of the variant to start.
519
- action (VariantAction): The action to perform on the variant (start).
520
- env_vars (Optional[DockerEnvVars], optional): The environment variables to inject to the Docker container. Defaults to None.
521
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
522
-
523
- Returns:
524
- URI: The URL of the started variant.
525
-
526
- Raises:
527
- HTTPException: If the app container cannot be started.
528
-
529
- Parameters:
530
- - variant_id: str.
531
-
532
- - action: VariantAction.
533
-
534
- - env_vars: typing.Optional[DockerEnvVars].
535
- ---
536
- from agenta import VariantAction, VariantActionEnum
537
- from agenta.client import AsyncAgentaApi
538
-
539
- client = AsyncAgentaApi(
540
- api_key="YOUR_API_KEY",
541
- base_url="https://yourhost.com/path/to/api",
542
- )
543
- await client.variants.start_variant(
544
- variant_id="variant_id",
545
- action=VariantAction(
546
- action=VariantActionEnum.START,
547
- ),
548
- )
549
- """
550
- _request: typing.Dict[str, typing.Any] = {"action": action}
551
- if env_vars is not OMIT:
552
- _request["env_vars"] = env_vars
553
- _response = await self._client_wrapper.httpx_client.request(
554
- "PUT",
555
- urllib.parse.urljoin(
556
- f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"
557
- ),
558
- json=jsonable_encoder(_request),
559
- headers=self._client_wrapper.get_headers(),
560
- timeout=60,
561
- )
562
- if 200 <= _response.status_code < 300:
563
- return pydantic.parse_obj_as(Uri, _response.json()) # type: ignore
564
- if _response.status_code == 422:
565
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
566
- try:
567
- _response_json = _response.json()
568
- except JSONDecodeError:
569
- raise ApiError(status_code=_response.status_code, body=_response.text)
570
- raise ApiError(status_code=_response.status_code, body=_response_json)
571
-
572
- async def remove_variant(self, variant_id: str) -> typing.Any:
573
- """
574
- Remove a variant from the server.
575
- In the case it's the last variant using the image, stop the container and remove the image.
576
-
577
- Arguments:
578
- app_variant -- AppVariant to remove
579
-
580
- Raises:
581
- HTTPException: If there is a problem removing the app variant
582
-
583
- Parameters:
584
- - variant_id: str.
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.remove_variant(
593
- variant_id="variant_id",
594
- )
595
- """
596
- _response = await self._client_wrapper.httpx_client.request(
597
- "DELETE",
598
- urllib.parse.urljoin(
599
- f"{self._client_wrapper.get_base_url()}/", f"variants/{variant_id}"
600
- ),
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_parameters(
615
- self, variant_id: str, *, parameters: typing.Dict[str, typing.Any]
616
- ) -> typing.Any:
617
- """
618
- Updates the parameters for an app variant.
619
-
620
- Args:
621
- variant_id (str): The ID of the app variant to update.
622
- payload (UpdateVariantParameterPayload): The payload containing the updated parameters.
623
- stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
624
-
625
- Raises:
626
- HTTPException: If there is an error while trying to update the app variant.
627
-
628
- Returns:
629
- JSONResponse: A JSON response containing the updated app variant parameters.
630
-
631
- Parameters:
632
- - variant_id: str.
633
-
634
- - parameters: typing.Dict[str, typing.Any].
635
- ---
636
- from agenta.client import AsyncAgentaApi
637
-
638
- client = AsyncAgentaApi(
639
- api_key="YOUR_API_KEY",
640
- base_url="https://yourhost.com/path/to/api",
641
- )
642
- await client.variants.update_variant_parameters(
643
- variant_id="variant_id",
644
- parameters={},
645
- )
646
- """
647
- _response = await self._client_wrapper.httpx_client.request(
648
- "PUT",
649
- urllib.parse.urljoin(
650
- f"{self._client_wrapper.get_base_url()}/",
651
- f"variants/{variant_id}/parameters",
652
- ),
653
- json=jsonable_encoder({"parameters": parameters}),
654
- headers=self._client_wrapper.get_headers(),
655
- timeout=60,
656
- )
657
- if 200 <= _response.status_code < 300:
658
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
659
- if _response.status_code == 422:
660
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
661
- try:
662
- _response_json = _response.json()
663
- except JSONDecodeError:
664
- raise ApiError(status_code=_response.status_code, body=_response.text)
665
- raise ApiError(status_code=_response.status_code, body=_response_json)
666
-
667
- async def update_variant_image(
668
- self, variant_id: str, *, request: Image
669
- ) -> typing.Any:
670
- """
671
- Updates the image used in an app variant.
672
-
673
- Args:
674
- variant_id (str): The ID of the app variant to update.
675
- image (Image): The image information to update.
676
-
677
- Raises:
678
- HTTPException: If an error occurs while trying to update the app variant.
679
-
680
- Returns:
681
- JSONResponse: A JSON response indicating whether the update was successful or not.
682
-
683
- Parameters:
684
- - variant_id: str.
685
-
686
- - request: Image.
687
- ---
688
- from agenta import Image
689
- from agenta.client import AsyncAgentaApi
690
-
691
- client = AsyncAgentaApi(
692
- api_key="YOUR_API_KEY",
693
- base_url="https://yourhost.com/path/to/api",
694
- )
695
- await client.variants.update_variant_image(
696
- variant_id="variant_id",
697
- request=Image(
698
- docker_id="docker_id",
699
- tags="tags",
700
- ),
701
- )
702
- """
703
- _response = await self._client_wrapper.httpx_client.request(
704
- "PUT",
705
- urllib.parse.urljoin(
706
- f"{self._client_wrapper.get_base_url()}/",
707
- f"variants/{variant_id}/image",
708
- ),
709
- json=jsonable_encoder(request),
710
- headers=self._client_wrapper.get_headers(),
711
- timeout=60,
712
- )
713
- if 200 <= _response.status_code < 300:
714
- return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
715
- if _response.status_code == 422:
716
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
717
- try:
718
- _response_json = _response.json()
719
- except JSONDecodeError:
720
- raise ApiError(status_code=_response.status_code, body=_response.text)
721
- raise ApiError(status_code=_response.status_code, body=_response_json)
722
-
723
- async def get_variant_revisions(
724
- self, variant_id: str
725
- ) -> typing.List[AppVariantRevision]:
726
- """
727
- Parameters:
728
- - variant_id: str.
729
- ---
730
- from agenta.client import AsyncAgentaApi
731
-
732
- client = AsyncAgentaApi(
733
- api_key="YOUR_API_KEY",
734
- base_url="https://yourhost.com/path/to/api",
735
- )
736
- await client.variants.get_variant_revisions(
737
- variant_id="variant_id",
738
- )
739
- """
740
- _response = await self._client_wrapper.httpx_client.request(
741
- "GET",
742
- urllib.parse.urljoin(
743
- f"{self._client_wrapper.get_base_url()}/",
744
- f"variants/{variant_id}/revisions",
745
- ),
746
- headers=self._client_wrapper.get_headers(),
747
- timeout=60,
748
- )
749
- if 200 <= _response.status_code < 300:
750
- return pydantic.parse_obj_as(typing.List[AppVariantRevision], _response.json()) # type: ignore
751
- if _response.status_code == 422:
752
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
753
- try:
754
- _response_json = _response.json()
755
- except JSONDecodeError:
756
- raise ApiError(status_code=_response.status_code, body=_response.text)
757
- raise ApiError(status_code=_response.status_code, body=_response_json)
758
-
759
- async def get_variant_revision(
760
- self, variant_id: str, revision_number: int
761
- ) -> AppVariantRevision:
762
- """
763
- Parameters:
764
- - variant_id: str.
765
-
766
- - revision_number: int.
767
- ---
768
- from agenta.client import AsyncAgentaApi
769
-
770
- client = AsyncAgentaApi(
771
- api_key="YOUR_API_KEY",
772
- base_url="https://yourhost.com/path/to/api",
773
- )
774
- await client.variants.get_variant_revision(
775
- variant_id="variant_id",
776
- revision_number=1,
777
- )
778
- """
779
- _response = await self._client_wrapper.httpx_client.request(
780
- "GET",
781
- urllib.parse.urljoin(
782
- f"{self._client_wrapper.get_base_url()}/",
783
- f"variants/{variant_id}/revisions/{revision_number}",
784
- ),
785
- headers=self._client_wrapper.get_headers(),
786
- timeout=60,
787
- )
788
- if 200 <= _response.status_code < 300:
789
- return pydantic.parse_obj_as(AppVariantRevision, _response.json()) # type: ignore
790
- if _response.status_code == 422:
791
- raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
792
- try:
793
- _response_json = _response.json()
794
- except JSONDecodeError:
795
- raise ApiError(status_code=_response.status_code, body=_response.text)
796
- raise ApiError(status_code=_response.status_code, body=_response_json)