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,915 @@
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.app import App
13
+ from ...types.app_variant_response import AppVariantResponse
14
+ from ...types.create_app_output import CreateAppOutput
15
+ from ...types.environment_output import EnvironmentOutput
16
+ from ...types.environment_output_extended import EnvironmentOutputExtended
17
+ from ...types.http_validation_error import HttpValidationError
18
+
19
+ try:
20
+ import pydantic.v1 as pydantic # type: ignore
21
+ except ImportError:
22
+ import pydantic # type: ignore
23
+
24
+ # this is used as the default value for optional parameters
25
+ OMIT = typing.cast(typing.Any, ...)
26
+
27
+
28
+ class AppsClient:
29
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
30
+ self._client_wrapper = client_wrapper
31
+
32
+ def list_app_variants(self, app_id: str) -> typing.List[AppVariantResponse]:
33
+ """
34
+ Retrieve a list of app variants for a given app ID.
35
+
36
+ Args:
37
+ app_id (str): The ID of the app to retrieve variants for.
38
+ stoken_session (SessionContainer, optional): The session container to verify the user's session. Defaults to Depends(verify_session()).
39
+
40
+ Returns:
41
+ List[AppVariantResponse]: A list of app variants for the given app ID.
42
+
43
+ Parameters:
44
+ - app_id: str.
45
+ ---
46
+ from agenta.client import AgentaApi
47
+
48
+ client = AgentaApi(
49
+ api_key="YOUR_API_KEY",
50
+ base_url="https://yourhost.com/path/to/api",
51
+ )
52
+ client.apps.list_app_variants(
53
+ app_id="app_id",
54
+ )
55
+ """
56
+ _response = self._client_wrapper.httpx_client.request(
57
+ "GET",
58
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/variants"),
59
+ headers=self._client_wrapper.get_headers(),
60
+ timeout=60,
61
+ )
62
+ if 200 <= _response.status_code < 300:
63
+ return pydantic.parse_obj_as(typing.List[AppVariantResponse], _response.json()) # type: ignore
64
+ if _response.status_code == 422:
65
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
66
+ try:
67
+ _response_json = _response.json()
68
+ except JSONDecodeError:
69
+ raise ApiError(status_code=_response.status_code, body=_response.text)
70
+ raise ApiError(status_code=_response.status_code, body=_response_json)
71
+
72
+ def get_variant_by_env(self, *, app_id: str, environment: str) -> AppVariantResponse:
73
+ """
74
+ Retrieve the app variant based on the provided app_id and environment.
75
+
76
+ Args:
77
+ app_id (str): The ID of the app to retrieve the variant for.
78
+ environment (str): The environment of the app variant to retrieve.
79
+ stoken_session (SessionContainer, optional): The session token container. Defaults to Depends(verify_session()).
80
+
81
+ Raises:
82
+ HTTPException: If the app variant is not found (status_code=500), or if a ValueError is raised (status_code=400), or if any other exception is raised (status_code=500).
83
+
84
+ Returns:
85
+ AppVariantResponse: The retrieved app variant.
86
+
87
+ Parameters:
88
+ - app_id: str.
89
+
90
+ - environment: str.
91
+ ---
92
+ from agenta.client import AgentaApi
93
+
94
+ client = AgentaApi(
95
+ api_key="YOUR_API_KEY",
96
+ base_url="https://yourhost.com/path/to/api",
97
+ )
98
+ client.apps.get_variant_by_env(
99
+ app_id="app_id",
100
+ environment="environment",
101
+ )
102
+ """
103
+ _response = self._client_wrapper.httpx_client.request(
104
+ "GET",
105
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps/get_variant_by_env"),
106
+ params=remove_none_from_dict({"app_id": app_id, "environment": environment}),
107
+ headers=self._client_wrapper.get_headers(),
108
+ timeout=60,
109
+ )
110
+ if 200 <= _response.status_code < 300:
111
+ return pydantic.parse_obj_as(AppVariantResponse, _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 list_apps(
121
+ self,
122
+ *,
123
+ app_name: typing.Optional[str] = None,
124
+ org_id: typing.Optional[str] = None,
125
+ workspace_id: typing.Optional[str] = None,
126
+ ) -> typing.List[App]:
127
+ """
128
+ Retrieve a list of apps filtered by app_name and org_id.
129
+
130
+ Args:
131
+ app_name (Optional[str]): The name of the app to filter by.
132
+ org_id (Optional[str]): The ID of the organization to filter by.
133
+ stoken_session (SessionContainer): The session container.
134
+
135
+ Returns:
136
+ List[App]: A list of apps filtered by app_name and org_id.
137
+
138
+ Raises:
139
+ HTTPException: If there was an error retrieving the list of apps.
140
+
141
+ Parameters:
142
+ - app_name: typing.Optional[str].
143
+
144
+ - org_id: typing.Optional[str].
145
+
146
+ - workspace_id: typing.Optional[str].
147
+ ---
148
+ from agenta.client import AgentaApi
149
+
150
+ client = AgentaApi(
151
+ api_key="YOUR_API_KEY",
152
+ base_url="https://yourhost.com/path/to/api",
153
+ )
154
+ client.apps.list_apps()
155
+ """
156
+ _response = self._client_wrapper.httpx_client.request(
157
+ "GET",
158
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps"),
159
+ params=remove_none_from_dict({"app_name": app_name, "org_id": org_id, "workspace_id": workspace_id}),
160
+ headers=self._client_wrapper.get_headers(),
161
+ timeout=60,
162
+ )
163
+ if 200 <= _response.status_code < 300:
164
+ return pydantic.parse_obj_as(typing.List[App], _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 create_app(
174
+ self, *, app_name: str, organization_id: typing.Optional[str] = OMIT, workspace_id: typing.Optional[str] = OMIT
175
+ ) -> CreateAppOutput:
176
+ """
177
+ Create a new app for a user or organization.
178
+
179
+ Args:
180
+ payload (CreateApp): The payload containing the app name and organization ID (optional).
181
+ stoken_session (SessionContainer): The session container containing the user's session token.
182
+
183
+ Returns:
184
+ CreateAppOutput: The output containing the newly created app's ID and name.
185
+
186
+ Raises:
187
+ HTTPException: If there is an error creating the app or the user does not have permission to access the app.
188
+
189
+ Parameters:
190
+ - app_name: str.
191
+
192
+ - organization_id: typing.Optional[str].
193
+
194
+ - workspace_id: typing.Optional[str].
195
+ ---
196
+ from agenta.client import AgentaApi
197
+
198
+ client = AgentaApi(
199
+ api_key="YOUR_API_KEY",
200
+ base_url="https://yourhost.com/path/to/api",
201
+ )
202
+ client.apps.create_app(
203
+ app_name="app_name",
204
+ )
205
+ """
206
+ _request: typing.Dict[str, typing.Any] = {"app_name": app_name}
207
+ if organization_id is not OMIT:
208
+ _request["organization_id"] = organization_id
209
+ if workspace_id is not OMIT:
210
+ _request["workspace_id"] = workspace_id
211
+ _response = self._client_wrapper.httpx_client.request(
212
+ "POST",
213
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps"),
214
+ json=jsonable_encoder(_request),
215
+ headers=self._client_wrapper.get_headers(),
216
+ timeout=60,
217
+ )
218
+ if 200 <= _response.status_code < 300:
219
+ return pydantic.parse_obj_as(CreateAppOutput, _response.json()) # type: ignore
220
+ if _response.status_code == 422:
221
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
222
+ try:
223
+ _response_json = _response.json()
224
+ except JSONDecodeError:
225
+ raise ApiError(status_code=_response.status_code, body=_response.text)
226
+ raise ApiError(status_code=_response.status_code, body=_response_json)
227
+
228
+ def add_variant_from_image(
229
+ self,
230
+ app_id: str,
231
+ *,
232
+ variant_name: str,
233
+ docker_id: str,
234
+ tags: str,
235
+ base_name: typing.Optional[str] = OMIT,
236
+ config_name: typing.Optional[str] = OMIT,
237
+ ) -> typing.Any:
238
+ """
239
+ Add a new variant to an app based on a Docker image.
240
+
241
+ Args:
242
+ app_id (str): The ID of the app to add the variant to.
243
+ payload (AddVariantFromImagePayload): The payload containing information about the variant to add.
244
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
245
+
246
+ Raises:
247
+ HTTPException: If the feature flag is set to "demo" or if the image does not have a tag starting with the registry name (agenta-server) or if the image is not found or if the user does not have access to the app.
248
+
249
+ Returns:
250
+ dict: The newly added variant.
251
+
252
+ Parameters:
253
+ - app_id: str.
254
+
255
+ - variant_name: str.
256
+
257
+ - docker_id: str.
258
+
259
+ - tags: str.
260
+
261
+ - base_name: typing.Optional[str].
262
+
263
+ - config_name: typing.Optional[str].
264
+ ---
265
+ from agenta.client import AgentaApi
266
+
267
+ client = AgentaApi(
268
+ api_key="YOUR_API_KEY",
269
+ base_url="https://yourhost.com/path/to/api",
270
+ )
271
+ client.apps.add_variant_from_image(
272
+ app_id="app_id",
273
+ variant_name="variant_name",
274
+ docker_id="docker_id",
275
+ tags="tags",
276
+ )
277
+ """
278
+ _request: typing.Dict[str, typing.Any] = {"variant_name": variant_name, "docker_id": docker_id, "tags": tags}
279
+ if base_name is not OMIT:
280
+ _request["base_name"] = base_name
281
+ if config_name is not OMIT:
282
+ _request["config_name"] = config_name
283
+ _response = self._client_wrapper.httpx_client.request(
284
+ "POST",
285
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/variant/from-image"),
286
+ json=jsonable_encoder(_request),
287
+ headers=self._client_wrapper.get_headers(),
288
+ timeout=60,
289
+ )
290
+ if 200 <= _response.status_code < 300:
291
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
292
+ if _response.status_code == 422:
293
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
294
+ try:
295
+ _response_json = _response.json()
296
+ except JSONDecodeError:
297
+ raise ApiError(status_code=_response.status_code, body=_response.text)
298
+ raise ApiError(status_code=_response.status_code, body=_response_json)
299
+
300
+ def remove_app(self, app_id: str) -> typing.Any:
301
+ """
302
+ Remove app, all its variant, containers and images
303
+
304
+ Arguments:
305
+ app -- App to remove
306
+
307
+ Parameters:
308
+ - app_id: str.
309
+ ---
310
+ from agenta.client import AgentaApi
311
+
312
+ client = AgentaApi(
313
+ api_key="YOUR_API_KEY",
314
+ base_url="https://yourhost.com/path/to/api",
315
+ )
316
+ client.apps.remove_app(
317
+ app_id="app_id",
318
+ )
319
+ """
320
+ _response = self._client_wrapper.httpx_client.request(
321
+ "DELETE",
322
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}"),
323
+ headers=self._client_wrapper.get_headers(),
324
+ timeout=60,
325
+ )
326
+ if 200 <= _response.status_code < 300:
327
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
328
+ if _response.status_code == 422:
329
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
330
+ try:
331
+ _response_json = _response.json()
332
+ except JSONDecodeError:
333
+ raise ApiError(status_code=_response.status_code, body=_response.text)
334
+ raise ApiError(status_code=_response.status_code, body=_response_json)
335
+
336
+ def create_app_and_variant_from_template(
337
+ self,
338
+ *,
339
+ app_name: str,
340
+ template_id: str,
341
+ env_vars: typing.Dict[str, str],
342
+ organization_id: typing.Optional[str] = OMIT,
343
+ workspace_id: typing.Optional[str] = OMIT,
344
+ ) -> AppVariantResponse:
345
+ """
346
+ Create an app and variant from a template.
347
+
348
+ Args:
349
+ payload (CreateAppVariant): The payload containing the app and variant information.
350
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
351
+
352
+ Raises:
353
+ HTTPException: If the user has reached the app limit or if an app with the same name already exists.
354
+
355
+ Returns:
356
+ AppVariantResponse: The output of the created app variant.
357
+
358
+ Parameters:
359
+ - app_name: str.
360
+
361
+ - template_id: str.
362
+
363
+ - env_vars: typing.Dict[str, str].
364
+
365
+ - organization_id: typing.Optional[str].
366
+
367
+ - workspace_id: typing.Optional[str].
368
+ ---
369
+ from agenta.client import AgentaApi
370
+
371
+ client = AgentaApi(
372
+ api_key="YOUR_API_KEY",
373
+ base_url="https://yourhost.com/path/to/api",
374
+ )
375
+ client.apps.create_app_and_variant_from_template(
376
+ app_name="app_name",
377
+ template_id="template_id",
378
+ env_vars={"env_vars": "env_vars"},
379
+ )
380
+ """
381
+ _request: typing.Dict[str, typing.Any] = {
382
+ "app_name": app_name,
383
+ "template_id": template_id,
384
+ "env_vars": env_vars,
385
+ }
386
+ if organization_id is not OMIT:
387
+ _request["organization_id"] = organization_id
388
+ if workspace_id is not OMIT:
389
+ _request["workspace_id"] = workspace_id
390
+ _response = self._client_wrapper.httpx_client.request(
391
+ "POST",
392
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps/app_and_variant_from_template"),
393
+ json=jsonable_encoder(_request),
394
+ headers=self._client_wrapper.get_headers(),
395
+ timeout=60,
396
+ )
397
+ if 200 <= _response.status_code < 300:
398
+ return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
399
+ if _response.status_code == 422:
400
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
401
+ try:
402
+ _response_json = _response.json()
403
+ except JSONDecodeError:
404
+ raise ApiError(status_code=_response.status_code, body=_response.text)
405
+ raise ApiError(status_code=_response.status_code, body=_response_json)
406
+
407
+ def list_environments(self, app_id: str) -> typing.List[EnvironmentOutput]:
408
+ """
409
+ Retrieve a list of environments for a given app ID.
410
+
411
+ Args:
412
+ app_id (str): The ID of the app to retrieve environments for.
413
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
414
+
415
+ Returns:
416
+ List[EnvironmentOutput]: A list of environment objects.
417
+
418
+ Parameters:
419
+ - app_id: str.
420
+ ---
421
+ from agenta.client import AgentaApi
422
+
423
+ client = AgentaApi(
424
+ api_key="YOUR_API_KEY",
425
+ base_url="https://yourhost.com/path/to/api",
426
+ )
427
+ client.apps.list_environments(
428
+ app_id="app_id",
429
+ )
430
+ """
431
+ _response = self._client_wrapper.httpx_client.request(
432
+ "GET",
433
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/environments"),
434
+ headers=self._client_wrapper.get_headers(),
435
+ timeout=60,
436
+ )
437
+ if 200 <= _response.status_code < 300:
438
+ return pydantic.parse_obj_as(typing.List[EnvironmentOutput], _response.json()) # type: ignore
439
+ if _response.status_code == 422:
440
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
441
+ try:
442
+ _response_json = _response.json()
443
+ except JSONDecodeError:
444
+ raise ApiError(status_code=_response.status_code, body=_response.text)
445
+ raise ApiError(status_code=_response.status_code, body=_response_json)
446
+
447
+ def environment_revisions(self, app_id: str, environment_name: typing.Any) -> EnvironmentOutputExtended:
448
+ """
449
+ Parameters:
450
+ - app_id: str.
451
+
452
+ - environment_name: typing.Any.
453
+ """
454
+ _response = self._client_wrapper.httpx_client.request(
455
+ "GET",
456
+ urllib.parse.urljoin(
457
+ f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/revisions/{environment_name}"
458
+ ),
459
+ headers=self._client_wrapper.get_headers(),
460
+ timeout=60,
461
+ )
462
+ if 200 <= _response.status_code < 300:
463
+ return pydantic.parse_obj_as(EnvironmentOutputExtended, _response.json()) # type: ignore
464
+ if _response.status_code == 422:
465
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
466
+ try:
467
+ _response_json = _response.json()
468
+ except JSONDecodeError:
469
+ raise ApiError(status_code=_response.status_code, body=_response.text)
470
+ raise ApiError(status_code=_response.status_code, body=_response_json)
471
+
472
+
473
+ class AsyncAppsClient:
474
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
475
+ self._client_wrapper = client_wrapper
476
+
477
+ async def list_app_variants(self, app_id: str) -> typing.List[AppVariantResponse]:
478
+ """
479
+ Retrieve a list of app variants for a given app ID.
480
+
481
+ Args:
482
+ app_id (str): The ID of the app to retrieve variants for.
483
+ stoken_session (SessionContainer, optional): The session container to verify the user's session. Defaults to Depends(verify_session()).
484
+
485
+ Returns:
486
+ List[AppVariantResponse]: A list of app variants for the given app ID.
487
+
488
+ Parameters:
489
+ - app_id: str.
490
+ ---
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.apps.list_app_variants(
498
+ app_id="app_id",
499
+ )
500
+ """
501
+ _response = await self._client_wrapper.httpx_client.request(
502
+ "GET",
503
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/variants"),
504
+ headers=self._client_wrapper.get_headers(),
505
+ timeout=60,
506
+ )
507
+ if 200 <= _response.status_code < 300:
508
+ return pydantic.parse_obj_as(typing.List[AppVariantResponse], _response.json()) # type: ignore
509
+ if _response.status_code == 422:
510
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
511
+ try:
512
+ _response_json = _response.json()
513
+ except JSONDecodeError:
514
+ raise ApiError(status_code=_response.status_code, body=_response.text)
515
+ raise ApiError(status_code=_response.status_code, body=_response_json)
516
+
517
+ async def get_variant_by_env(self, *, app_id: str, environment: str) -> AppVariantResponse:
518
+ """
519
+ Retrieve the app variant based on the provided app_id and environment.
520
+
521
+ Args:
522
+ app_id (str): The ID of the app to retrieve the variant for.
523
+ environment (str): The environment of the app variant to retrieve.
524
+ stoken_session (SessionContainer, optional): The session token container. Defaults to Depends(verify_session()).
525
+
526
+ Raises:
527
+ HTTPException: If the app variant is not found (status_code=500), or if a ValueError is raised (status_code=400), or if any other exception is raised (status_code=500).
528
+
529
+ Returns:
530
+ AppVariantResponse: The retrieved app variant.
531
+
532
+ Parameters:
533
+ - app_id: str.
534
+
535
+ - environment: str.
536
+ ---
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.apps.get_variant_by_env(
544
+ app_id="app_id",
545
+ environment="environment",
546
+ )
547
+ """
548
+ _response = await self._client_wrapper.httpx_client.request(
549
+ "GET",
550
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps/get_variant_by_env"),
551
+ params=remove_none_from_dict({"app_id": app_id, "environment": environment}),
552
+ headers=self._client_wrapper.get_headers(),
553
+ timeout=60,
554
+ )
555
+ if 200 <= _response.status_code < 300:
556
+ return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
557
+ if _response.status_code == 422:
558
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
559
+ try:
560
+ _response_json = _response.json()
561
+ except JSONDecodeError:
562
+ raise ApiError(status_code=_response.status_code, body=_response.text)
563
+ raise ApiError(status_code=_response.status_code, body=_response_json)
564
+
565
+ async def list_apps(
566
+ self,
567
+ *,
568
+ app_name: typing.Optional[str] = None,
569
+ org_id: typing.Optional[str] = None,
570
+ workspace_id: typing.Optional[str] = None,
571
+ ) -> typing.List[App]:
572
+ """
573
+ Retrieve a list of apps filtered by app_name and org_id.
574
+
575
+ Args:
576
+ app_name (Optional[str]): The name of the app to filter by.
577
+ org_id (Optional[str]): The ID of the organization to filter by.
578
+ stoken_session (SessionContainer): The session container.
579
+
580
+ Returns:
581
+ List[App]: A list of apps filtered by app_name and org_id.
582
+
583
+ Raises:
584
+ HTTPException: If there was an error retrieving the list of apps.
585
+
586
+ Parameters:
587
+ - app_name: typing.Optional[str].
588
+
589
+ - org_id: typing.Optional[str].
590
+
591
+ - workspace_id: typing.Optional[str].
592
+ ---
593
+ from agenta.client import AsyncAgentaApi
594
+
595
+ client = AsyncAgentaApi(
596
+ api_key="YOUR_API_KEY",
597
+ base_url="https://yourhost.com/path/to/api",
598
+ )
599
+ await client.apps.list_apps()
600
+ """
601
+ _response = await self._client_wrapper.httpx_client.request(
602
+ "GET",
603
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps"),
604
+ params=remove_none_from_dict({"app_name": app_name, "org_id": org_id, "workspace_id": workspace_id}),
605
+ headers=self._client_wrapper.get_headers(),
606
+ timeout=60,
607
+ )
608
+ if 200 <= _response.status_code < 300:
609
+ return pydantic.parse_obj_as(typing.List[App], _response.json()) # type: ignore
610
+ if _response.status_code == 422:
611
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
612
+ try:
613
+ _response_json = _response.json()
614
+ except JSONDecodeError:
615
+ raise ApiError(status_code=_response.status_code, body=_response.text)
616
+ raise ApiError(status_code=_response.status_code, body=_response_json)
617
+
618
+ async def create_app(
619
+ self, *, app_name: str, organization_id: typing.Optional[str] = OMIT, workspace_id: typing.Optional[str] = OMIT
620
+ ) -> CreateAppOutput:
621
+ """
622
+ Create a new app for a user or organization.
623
+
624
+ Args:
625
+ payload (CreateApp): The payload containing the app name and organization ID (optional).
626
+ stoken_session (SessionContainer): The session container containing the user's session token.
627
+
628
+ Returns:
629
+ CreateAppOutput: The output containing the newly created app's ID and name.
630
+
631
+ Raises:
632
+ HTTPException: If there is an error creating the app or the user does not have permission to access the app.
633
+
634
+ Parameters:
635
+ - app_name: str.
636
+
637
+ - organization_id: typing.Optional[str].
638
+
639
+ - workspace_id: typing.Optional[str].
640
+ ---
641
+ from agenta.client import AsyncAgentaApi
642
+
643
+ client = AsyncAgentaApi(
644
+ api_key="YOUR_API_KEY",
645
+ base_url="https://yourhost.com/path/to/api",
646
+ )
647
+ await client.apps.create_app(
648
+ app_name="app_name",
649
+ )
650
+ """
651
+ _request: typing.Dict[str, typing.Any] = {"app_name": app_name}
652
+ if organization_id is not OMIT:
653
+ _request["organization_id"] = organization_id
654
+ if workspace_id is not OMIT:
655
+ _request["workspace_id"] = workspace_id
656
+ _response = await self._client_wrapper.httpx_client.request(
657
+ "POST",
658
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps"),
659
+ json=jsonable_encoder(_request),
660
+ headers=self._client_wrapper.get_headers(),
661
+ timeout=60,
662
+ )
663
+ if 200 <= _response.status_code < 300:
664
+ return pydantic.parse_obj_as(CreateAppOutput, _response.json()) # type: ignore
665
+ if _response.status_code == 422:
666
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
667
+ try:
668
+ _response_json = _response.json()
669
+ except JSONDecodeError:
670
+ raise ApiError(status_code=_response.status_code, body=_response.text)
671
+ raise ApiError(status_code=_response.status_code, body=_response_json)
672
+
673
+ async def add_variant_from_image(
674
+ self,
675
+ app_id: str,
676
+ *,
677
+ variant_name: str,
678
+ docker_id: str,
679
+ tags: str,
680
+ base_name: typing.Optional[str] = OMIT,
681
+ config_name: typing.Optional[str] = OMIT,
682
+ ) -> typing.Any:
683
+ """
684
+ Add a new variant to an app based on a Docker image.
685
+
686
+ Args:
687
+ app_id (str): The ID of the app to add the variant to.
688
+ payload (AddVariantFromImagePayload): The payload containing information about the variant to add.
689
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
690
+
691
+ Raises:
692
+ HTTPException: If the feature flag is set to "demo" or if the image does not have a tag starting with the registry name (agenta-server) or if the image is not found or if the user does not have access to the app.
693
+
694
+ Returns:
695
+ dict: The newly added variant.
696
+
697
+ Parameters:
698
+ - app_id: str.
699
+
700
+ - variant_name: str.
701
+
702
+ - docker_id: str.
703
+
704
+ - tags: str.
705
+
706
+ - base_name: typing.Optional[str].
707
+
708
+ - config_name: typing.Optional[str].
709
+ ---
710
+ from agenta.client import AsyncAgentaApi
711
+
712
+ client = AsyncAgentaApi(
713
+ api_key="YOUR_API_KEY",
714
+ base_url="https://yourhost.com/path/to/api",
715
+ )
716
+ await client.apps.add_variant_from_image(
717
+ app_id="app_id",
718
+ variant_name="variant_name",
719
+ docker_id="docker_id",
720
+ tags="tags",
721
+ )
722
+ """
723
+ _request: typing.Dict[str, typing.Any] = {"variant_name": variant_name, "docker_id": docker_id, "tags": tags}
724
+ if base_name is not OMIT:
725
+ _request["base_name"] = base_name
726
+ if config_name is not OMIT:
727
+ _request["config_name"] = config_name
728
+ _response = await self._client_wrapper.httpx_client.request(
729
+ "POST",
730
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/variant/from-image"),
731
+ json=jsonable_encoder(_request),
732
+ headers=self._client_wrapper.get_headers(),
733
+ timeout=60,
734
+ )
735
+ if 200 <= _response.status_code < 300:
736
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
737
+ if _response.status_code == 422:
738
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
739
+ try:
740
+ _response_json = _response.json()
741
+ except JSONDecodeError:
742
+ raise ApiError(status_code=_response.status_code, body=_response.text)
743
+ raise ApiError(status_code=_response.status_code, body=_response_json)
744
+
745
+ async def remove_app(self, app_id: str) -> typing.Any:
746
+ """
747
+ Remove app, all its variant, containers and images
748
+
749
+ Arguments:
750
+ app -- App to remove
751
+
752
+ Parameters:
753
+ - app_id: str.
754
+ ---
755
+ from agenta.client import AsyncAgentaApi
756
+
757
+ client = AsyncAgentaApi(
758
+ api_key="YOUR_API_KEY",
759
+ base_url="https://yourhost.com/path/to/api",
760
+ )
761
+ await client.apps.remove_app(
762
+ app_id="app_id",
763
+ )
764
+ """
765
+ _response = await self._client_wrapper.httpx_client.request(
766
+ "DELETE",
767
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}"),
768
+ headers=self._client_wrapper.get_headers(),
769
+ timeout=60,
770
+ )
771
+ if 200 <= _response.status_code < 300:
772
+ return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore
773
+ if _response.status_code == 422:
774
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
775
+ try:
776
+ _response_json = _response.json()
777
+ except JSONDecodeError:
778
+ raise ApiError(status_code=_response.status_code, body=_response.text)
779
+ raise ApiError(status_code=_response.status_code, body=_response_json)
780
+
781
+ async def create_app_and_variant_from_template(
782
+ self,
783
+ *,
784
+ app_name: str,
785
+ template_id: str,
786
+ env_vars: typing.Dict[str, str],
787
+ organization_id: typing.Optional[str] = OMIT,
788
+ workspace_id: typing.Optional[str] = OMIT,
789
+ ) -> AppVariantResponse:
790
+ """
791
+ Create an app and variant from a template.
792
+
793
+ Args:
794
+ payload (CreateAppVariant): The payload containing the app and variant information.
795
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
796
+
797
+ Raises:
798
+ HTTPException: If the user has reached the app limit or if an app with the same name already exists.
799
+
800
+ Returns:
801
+ AppVariantResponse: The output of the created app variant.
802
+
803
+ Parameters:
804
+ - app_name: str.
805
+
806
+ - template_id: str.
807
+
808
+ - env_vars: typing.Dict[str, str].
809
+
810
+ - organization_id: typing.Optional[str].
811
+
812
+ - workspace_id: typing.Optional[str].
813
+ ---
814
+ from agenta.client import AsyncAgentaApi
815
+
816
+ client = AsyncAgentaApi(
817
+ api_key="YOUR_API_KEY",
818
+ base_url="https://yourhost.com/path/to/api",
819
+ )
820
+ await client.apps.create_app_and_variant_from_template(
821
+ app_name="app_name",
822
+ template_id="template_id",
823
+ env_vars={"env_vars": "env_vars"},
824
+ )
825
+ """
826
+ _request: typing.Dict[str, typing.Any] = {
827
+ "app_name": app_name,
828
+ "template_id": template_id,
829
+ "env_vars": env_vars,
830
+ }
831
+ if organization_id is not OMIT:
832
+ _request["organization_id"] = organization_id
833
+ if workspace_id is not OMIT:
834
+ _request["workspace_id"] = workspace_id
835
+ _response = await self._client_wrapper.httpx_client.request(
836
+ "POST",
837
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apps/app_and_variant_from_template"),
838
+ json=jsonable_encoder(_request),
839
+ headers=self._client_wrapper.get_headers(),
840
+ timeout=60,
841
+ )
842
+ if 200 <= _response.status_code < 300:
843
+ return pydantic.parse_obj_as(AppVariantResponse, _response.json()) # type: ignore
844
+ if _response.status_code == 422:
845
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
846
+ try:
847
+ _response_json = _response.json()
848
+ except JSONDecodeError:
849
+ raise ApiError(status_code=_response.status_code, body=_response.text)
850
+ raise ApiError(status_code=_response.status_code, body=_response_json)
851
+
852
+ async def list_environments(self, app_id: str) -> typing.List[EnvironmentOutput]:
853
+ """
854
+ Retrieve a list of environments for a given app ID.
855
+
856
+ Args:
857
+ app_id (str): The ID of the app to retrieve environments for.
858
+ stoken_session (SessionContainer, optional): The session container. Defaults to Depends(verify_session()).
859
+
860
+ Returns:
861
+ List[EnvironmentOutput]: A list of environment objects.
862
+
863
+ Parameters:
864
+ - app_id: str.
865
+ ---
866
+ from agenta.client import AsyncAgentaApi
867
+
868
+ client = AsyncAgentaApi(
869
+ api_key="YOUR_API_KEY",
870
+ base_url="https://yourhost.com/path/to/api",
871
+ )
872
+ await client.apps.list_environments(
873
+ app_id="app_id",
874
+ )
875
+ """
876
+ _response = await self._client_wrapper.httpx_client.request(
877
+ "GET",
878
+ urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/environments"),
879
+ headers=self._client_wrapper.get_headers(),
880
+ timeout=60,
881
+ )
882
+ if 200 <= _response.status_code < 300:
883
+ return pydantic.parse_obj_as(typing.List[EnvironmentOutput], _response.json()) # type: ignore
884
+ if _response.status_code == 422:
885
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
886
+ try:
887
+ _response_json = _response.json()
888
+ except JSONDecodeError:
889
+ raise ApiError(status_code=_response.status_code, body=_response.text)
890
+ raise ApiError(status_code=_response.status_code, body=_response_json)
891
+
892
+ async def environment_revisions(self, app_id: str, environment_name: typing.Any) -> EnvironmentOutputExtended:
893
+ """
894
+ Parameters:
895
+ - app_id: str.
896
+
897
+ - environment_name: typing.Any.
898
+ """
899
+ _response = await self._client_wrapper.httpx_client.request(
900
+ "GET",
901
+ urllib.parse.urljoin(
902
+ f"{self._client_wrapper.get_base_url()}/", f"apps/{app_id}/revisions/{environment_name}"
903
+ ),
904
+ headers=self._client_wrapper.get_headers(),
905
+ timeout=60,
906
+ )
907
+ if 200 <= _response.status_code < 300:
908
+ return pydantic.parse_obj_as(EnvironmentOutputExtended, _response.json()) # type: ignore
909
+ if _response.status_code == 422:
910
+ raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _response.json())) # type: ignore
911
+ try:
912
+ _response_json = _response.json()
913
+ except JSONDecodeError:
914
+ raise ApiError(status_code=_response.status_code, body=_response.text)
915
+ raise ApiError(status_code=_response.status_code, body=_response_json)