agenta 0.12.3__py3-none-any.whl → 0.32.0a1__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 (244) hide show
  1. agenta/__init__.py +64 -7
  2. agenta/cli/helper.py +7 -3
  3. agenta/cli/main.py +15 -50
  4. agenta/cli/variant_commands.py +50 -29
  5. agenta/client/Readme.md +72 -64
  6. agenta/client/api.py +2 -2
  7. agenta/client/backend/__init__.py +193 -22
  8. agenta/client/backend/access_control/__init__.py +1 -0
  9. agenta/client/backend/access_control/client.py +167 -0
  10. agenta/client/backend/apps/__init__.py +1 -0
  11. agenta/client/backend/apps/client.py +1691 -0
  12. agenta/client/backend/bases/__init__.py +1 -0
  13. agenta/client/backend/bases/client.py +190 -0
  14. agenta/client/backend/client.py +2508 -5712
  15. agenta/client/backend/configs/__init__.py +1 -0
  16. agenta/client/backend/configs/client.py +604 -0
  17. agenta/client/backend/containers/__init__.py +5 -0
  18. agenta/client/backend/containers/client.py +648 -0
  19. agenta/client/backend/containers/types/__init__.py +5 -0
  20. agenta/client/backend/{types → containers/types}/container_templates_response.py +1 -2
  21. agenta/client/backend/core/__init__.py +30 -0
  22. agenta/client/backend/core/client_wrapper.py +42 -9
  23. agenta/client/backend/core/file.py +70 -0
  24. agenta/client/backend/core/http_client.py +575 -0
  25. agenta/client/backend/core/jsonable_encoder.py +33 -39
  26. agenta/client/backend/core/pydantic_utilities.py +325 -0
  27. agenta/client/backend/core/query_encoder.py +60 -0
  28. agenta/client/backend/core/remove_none_from_dict.py +2 -2
  29. agenta/client/backend/core/request_options.py +35 -0
  30. agenta/client/backend/core/serialization.py +276 -0
  31. agenta/client/backend/environments/__init__.py +1 -0
  32. agenta/client/backend/environments/client.py +196 -0
  33. agenta/client/backend/evaluations/__init__.py +1 -0
  34. agenta/client/backend/evaluations/client.py +1469 -0
  35. agenta/client/backend/evaluators/__init__.py +1 -0
  36. agenta/client/backend/evaluators/client.py +1283 -0
  37. agenta/client/backend/observability/__init__.py +1 -0
  38. agenta/client/backend/observability/client.py +1286 -0
  39. agenta/client/backend/observability_v_1/__init__.py +5 -0
  40. agenta/client/backend/observability_v_1/client.py +763 -0
  41. agenta/client/backend/observability_v_1/types/__init__.py +7 -0
  42. agenta/client/backend/observability_v_1/types/format.py +5 -0
  43. agenta/client/backend/observability_v_1/types/query_analytics_response.py +7 -0
  44. agenta/client/backend/observability_v_1/types/query_traces_response.py +11 -0
  45. agenta/client/backend/scopes/__init__.py +1 -0
  46. agenta/client/backend/scopes/client.py +114 -0
  47. agenta/client/backend/testsets/__init__.py +1 -0
  48. agenta/client/backend/testsets/client.py +1284 -0
  49. agenta/client/backend/types/__init__.py +154 -26
  50. agenta/client/backend/types/agenta_node_dto.py +48 -0
  51. agenta/client/backend/types/agenta_node_dto_nodes_value.py +6 -0
  52. agenta/client/backend/types/agenta_nodes_response.py +30 -0
  53. agenta/client/backend/types/agenta_root_dto.py +30 -0
  54. agenta/client/backend/types/agenta_roots_response.py +30 -0
  55. agenta/client/backend/types/agenta_tree_dto.py +30 -0
  56. agenta/client/backend/types/agenta_trees_response.py +30 -0
  57. agenta/client/backend/types/aggregated_result.py +16 -31
  58. agenta/client/backend/types/aggregated_result_evaluator_config.py +8 -0
  59. agenta/client/backend/types/analytics_response.py +24 -0
  60. agenta/client/backend/types/app.py +17 -30
  61. agenta/client/backend/types/app_variant_response.py +36 -0
  62. agenta/client/backend/types/app_variant_revision.py +17 -32
  63. agenta/client/backend/types/base_output.py +13 -28
  64. agenta/client/backend/types/body_import_testset.py +15 -31
  65. agenta/client/backend/types/bucket_dto.py +26 -0
  66. agenta/client/backend/types/collect_status_response.py +22 -0
  67. agenta/client/backend/types/config_db.py +16 -31
  68. agenta/client/backend/types/config_dto.py +32 -0
  69. agenta/client/backend/types/config_response_model.py +32 -0
  70. agenta/client/backend/types/correct_answer.py +22 -0
  71. agenta/client/backend/types/create_app_output.py +13 -28
  72. agenta/client/backend/types/create_span.py +45 -0
  73. agenta/client/backend/types/create_trace_response.py +22 -0
  74. agenta/client/backend/types/docker_env_vars.py +13 -28
  75. agenta/client/backend/types/environment_output.py +22 -34
  76. agenta/client/backend/types/environment_output_extended.py +31 -0
  77. agenta/client/backend/types/environment_revision.py +26 -0
  78. agenta/client/backend/types/error.py +22 -0
  79. agenta/client/backend/types/evaluation.py +22 -33
  80. agenta/client/backend/types/evaluation_scenario.py +18 -33
  81. agenta/client/backend/types/evaluation_scenario_input.py +16 -31
  82. agenta/client/backend/types/evaluation_scenario_output.py +17 -30
  83. agenta/client/backend/types/evaluation_scenario_result.py +14 -29
  84. agenta/client/backend/types/evaluation_scenario_score_update.py +21 -0
  85. agenta/client/backend/types/evaluation_status_enum.py +11 -29
  86. agenta/client/backend/types/evaluation_type.py +3 -21
  87. agenta/client/backend/types/evaluator.py +20 -31
  88. agenta/client/backend/types/evaluator_config.py +21 -33
  89. agenta/client/backend/types/evaluator_mapping_output_interface.py +21 -0
  90. agenta/client/backend/types/evaluator_output_interface.py +21 -0
  91. agenta/client/backend/types/exception_dto.py +26 -0
  92. agenta/client/backend/types/get_config_response.py +23 -0
  93. agenta/client/backend/types/header_dto.py +22 -0
  94. agenta/client/backend/types/http_validation_error.py +14 -29
  95. agenta/client/backend/types/human_evaluation.py +18 -34
  96. agenta/client/backend/types/human_evaluation_scenario.py +22 -38
  97. agenta/client/backend/types/human_evaluation_scenario_input.py +13 -28
  98. agenta/client/backend/types/human_evaluation_scenario_output.py +13 -28
  99. agenta/client/backend/types/human_evaluation_scenario_update.py +30 -0
  100. agenta/client/backend/types/human_evaluation_update.py +22 -0
  101. agenta/client/backend/types/image.py +18 -32
  102. agenta/client/backend/types/invite_request.py +16 -30
  103. agenta/client/backend/types/legacy_analytics_response.py +29 -0
  104. agenta/client/backend/types/legacy_data_point.py +27 -0
  105. agenta/client/backend/types/lifecycle_dto.py +24 -0
  106. agenta/client/backend/types/link_dto.py +24 -0
  107. agenta/client/backend/types/list_api_keys_response.py +24 -0
  108. agenta/client/backend/types/llm_run_rate_limit.py +13 -28
  109. agenta/client/backend/types/llm_tokens.py +23 -0
  110. agenta/client/backend/types/metrics_dto.py +24 -0
  111. agenta/client/backend/types/new_human_evaluation.py +27 -0
  112. agenta/client/backend/types/new_testset.py +16 -31
  113. agenta/client/backend/types/node_dto.py +24 -0
  114. agenta/client/backend/types/node_type.py +19 -0
  115. agenta/client/backend/types/o_tel_context_dto.py +22 -0
  116. agenta/client/backend/types/o_tel_event_dto.py +23 -0
  117. agenta/client/backend/types/o_tel_extra_dto.py +26 -0
  118. agenta/client/backend/types/o_tel_link_dto.py +23 -0
  119. agenta/client/backend/types/o_tel_span_dto.py +37 -0
  120. agenta/client/backend/types/o_tel_span_kind.py +15 -0
  121. agenta/client/backend/types/o_tel_spans_response.py +24 -0
  122. agenta/client/backend/types/o_tel_status_code.py +8 -0
  123. agenta/client/backend/types/organization.py +22 -35
  124. agenta/client/backend/types/organization_output.py +13 -28
  125. agenta/client/backend/types/outputs.py +5 -0
  126. agenta/client/backend/types/parent_dto.py +21 -0
  127. agenta/client/backend/types/permission.py +41 -0
  128. agenta/client/backend/types/projects_response.py +28 -0
  129. agenta/client/backend/types/provider_key_dto.py +23 -0
  130. agenta/client/backend/types/provider_kind.py +21 -0
  131. agenta/client/backend/types/reference_dto.py +23 -0
  132. agenta/client/backend/types/reference_request_model.py +23 -0
  133. agenta/client/backend/types/result.py +18 -31
  134. agenta/client/backend/types/root_dto.py +21 -0
  135. agenta/client/backend/types/{human_evaluation_scenario_score.py → score.py} +1 -1
  136. agenta/client/backend/types/secret_dto.py +24 -0
  137. agenta/client/backend/types/{human_evaluation_scenario_update_score.py → secret_kind.py} +1 -1
  138. agenta/client/backend/types/secret_response_dto.py +27 -0
  139. agenta/client/backend/types/simple_evaluation_output.py +13 -28
  140. agenta/client/backend/types/span.py +39 -49
  141. agenta/client/backend/types/span_detail.py +44 -0
  142. agenta/client/backend/types/span_dto.py +54 -0
  143. agenta/client/backend/types/span_dto_nodes_value.py +9 -0
  144. agenta/client/backend/types/span_status_code.py +5 -0
  145. agenta/client/backend/types/span_variant.py +23 -0
  146. agenta/client/backend/types/status_code.py +5 -0
  147. agenta/client/backend/types/status_dto.py +23 -0
  148. agenta/client/backend/types/template.py +14 -29
  149. agenta/client/backend/types/template_image_info.py +21 -35
  150. agenta/client/backend/types/test_set_output_response.py +20 -33
  151. agenta/client/backend/types/test_set_simple_response.py +13 -28
  152. agenta/client/backend/types/time_dto.py +23 -0
  153. agenta/client/backend/types/trace_detail.py +44 -0
  154. agenta/client/backend/types/tree_dto.py +23 -0
  155. agenta/client/backend/types/tree_type.py +5 -0
  156. agenta/client/backend/types/update_app_output.py +22 -0
  157. agenta/client/backend/types/uri.py +13 -28
  158. agenta/client/backend/types/validation_error.py +13 -28
  159. agenta/client/backend/types/variant_action.py +14 -29
  160. agenta/client/backend/types/variant_action_enum.py +1 -19
  161. agenta/client/backend/types/with_pagination.py +26 -0
  162. agenta/client/backend/types/workspace_member_response.py +23 -0
  163. agenta/client/backend/types/workspace_permission.py +25 -0
  164. agenta/client/backend/types/workspace_response.py +29 -0
  165. agenta/client/backend/types/workspace_role.py +15 -0
  166. agenta/client/backend/types/workspace_role_response.py +23 -0
  167. agenta/client/backend/variants/__init__.py +5 -0
  168. agenta/client/backend/variants/client.py +2814 -0
  169. agenta/client/backend/variants/types/__init__.py +7 -0
  170. agenta/client/backend/variants/types/add_variant_from_base_and_config_response.py +8 -0
  171. agenta/client/backend/vault/__init__.py +1 -0
  172. agenta/client/backend/vault/client.py +685 -0
  173. agenta/client/client.py +1 -1
  174. agenta/config.py +0 -2
  175. agenta/config.toml +0 -1
  176. agenta/docker/docker-assets/Dockerfile.cloud.template +2 -1
  177. agenta/docker/docker-assets/Dockerfile.template +2 -1
  178. agenta/docker/docker_utils.py +11 -12
  179. agenta/sdk/__init__.py +58 -7
  180. agenta/sdk/agenta_init.py +182 -164
  181. agenta/sdk/assets.py +95 -0
  182. agenta/sdk/client.py +56 -0
  183. agenta/sdk/context/__init__.py +0 -0
  184. agenta/sdk/context/exporting.py +25 -0
  185. agenta/sdk/context/routing.py +27 -0
  186. agenta/sdk/context/tracing.py +28 -0
  187. agenta/sdk/decorators/__init__.py +0 -0
  188. agenta/sdk/decorators/routing.py +576 -0
  189. agenta/sdk/decorators/tracing.py +296 -0
  190. agenta/sdk/litellm/__init__.py +1 -0
  191. agenta/sdk/litellm/litellm.py +314 -0
  192. agenta/sdk/litellm/mockllm.py +27 -0
  193. agenta/sdk/litellm/mocks/__init__.py +26 -0
  194. agenta/sdk/managers/__init__.py +6 -0
  195. agenta/sdk/managers/config.py +208 -0
  196. agenta/sdk/managers/deployment.py +45 -0
  197. agenta/sdk/managers/secrets.py +38 -0
  198. agenta/sdk/managers/shared.py +639 -0
  199. agenta/sdk/managers/variant.py +182 -0
  200. agenta/sdk/managers/vault.py +16 -0
  201. agenta/sdk/middleware/__init__.py +0 -0
  202. agenta/sdk/middleware/auth.py +180 -0
  203. agenta/sdk/middleware/cache.py +47 -0
  204. agenta/sdk/middleware/config.py +255 -0
  205. agenta/sdk/middleware/cors.py +29 -0
  206. agenta/sdk/middleware/inline.py +38 -0
  207. agenta/sdk/middleware/mock.py +33 -0
  208. agenta/sdk/middleware/otel.py +40 -0
  209. agenta/sdk/middleware/vault.py +145 -0
  210. agenta/sdk/router.py +0 -7
  211. agenta/sdk/tracing/__init__.py +1 -0
  212. agenta/sdk/tracing/attributes.py +141 -0
  213. agenta/sdk/tracing/conventions.py +49 -0
  214. agenta/sdk/tracing/exporters.py +103 -0
  215. agenta/sdk/tracing/inline.py +1146 -0
  216. agenta/sdk/tracing/processors.py +121 -0
  217. agenta/sdk/tracing/spans.py +136 -0
  218. agenta/sdk/tracing/tracing.py +237 -0
  219. agenta/sdk/types.py +478 -74
  220. agenta/sdk/utils/__init__.py +0 -0
  221. agenta/sdk/utils/constants.py +1 -0
  222. agenta/sdk/utils/{helper/openai_cost.py → costs.py} +3 -0
  223. agenta/sdk/utils/exceptions.py +59 -0
  224. agenta/sdk/utils/globals.py +6 -10
  225. agenta/sdk/utils/helpers.py +8 -0
  226. agenta/sdk/utils/logging.py +21 -0
  227. agenta/sdk/utils/singleton.py +13 -0
  228. agenta/sdk/utils/timing.py +58 -0
  229. {agenta-0.12.3.dist-info → agenta-0.32.0a1.dist-info}/METADATA +98 -151
  230. agenta-0.32.0a1.dist-info/RECORD +263 -0
  231. {agenta-0.12.3.dist-info → agenta-0.32.0a1.dist-info}/WHEEL +1 -1
  232. agenta/client/backend/types/add_variant_from_base_and_config_response.py +0 -7
  233. agenta/client/backend/types/app_variant_output.py +0 -47
  234. agenta/client/backend/types/app_variant_output_extended.py +0 -50
  235. agenta/client/backend/types/delete_evaluation.py +0 -36
  236. agenta/client/backend/types/evaluation_webhook.py +0 -36
  237. agenta/client/backend/types/feedback.py +0 -40
  238. agenta/client/backend/types/get_config_reponse.py +0 -39
  239. agenta/client/backend/types/list_api_keys_output.py +0 -39
  240. agenta/client/backend/types/trace.py +0 -48
  241. agenta/sdk/agenta_decorator.py +0 -443
  242. agenta/sdk/context.py +0 -41
  243. agenta-0.12.3.dist-info/RECORD +0 -114
  244. {agenta-0.12.3.dist-info → agenta-0.32.0a1.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,276 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import collections
4
+ import inspect
5
+ import typing
6
+
7
+ import typing_extensions
8
+
9
+ import pydantic
10
+
11
+
12
+ class FieldMetadata:
13
+ """
14
+ Metadata class used to annotate fields to provide additional information.
15
+
16
+ Example:
17
+ class MyDict(TypedDict):
18
+ field: typing.Annotated[str, FieldMetadata(alias="field_name")]
19
+
20
+ Will serialize: `{"field": "value"}`
21
+ To: `{"field_name": "value"}`
22
+ """
23
+
24
+ alias: str
25
+
26
+ def __init__(self, *, alias: str) -> None:
27
+ self.alias = alias
28
+
29
+
30
+ def convert_and_respect_annotation_metadata(
31
+ *,
32
+ object_: typing.Any,
33
+ annotation: typing.Any,
34
+ inner_type: typing.Optional[typing.Any] = None,
35
+ direction: typing.Literal["read", "write"],
36
+ ) -> typing.Any:
37
+ """
38
+ Respect the metadata annotations on a field, such as aliasing. This function effectively
39
+ manipulates the dict-form of an object to respect the metadata annotations. This is primarily used for
40
+ TypedDicts, which cannot support aliasing out of the box, and can be extended for additional
41
+ utilities, such as defaults.
42
+
43
+ Parameters
44
+ ----------
45
+ object_ : typing.Any
46
+
47
+ annotation : type
48
+ The type we're looking to apply typing annotations from
49
+
50
+ inner_type : typing.Optional[type]
51
+
52
+ Returns
53
+ -------
54
+ typing.Any
55
+ """
56
+
57
+ if object_ is None:
58
+ return None
59
+ if inner_type is None:
60
+ inner_type = annotation
61
+
62
+ clean_type = _remove_annotations(inner_type)
63
+ # Pydantic models
64
+ if (
65
+ inspect.isclass(clean_type)
66
+ and issubclass(clean_type, pydantic.BaseModel)
67
+ and isinstance(object_, typing.Mapping)
68
+ ):
69
+ return _convert_mapping(object_, clean_type, direction)
70
+ # TypedDicts
71
+ if typing_extensions.is_typeddict(clean_type) and isinstance(
72
+ object_, typing.Mapping
73
+ ):
74
+ return _convert_mapping(object_, clean_type, direction)
75
+
76
+ if (
77
+ typing_extensions.get_origin(clean_type) == typing.Dict
78
+ or typing_extensions.get_origin(clean_type) == dict
79
+ or clean_type == typing.Dict
80
+ ) and isinstance(object_, typing.Dict):
81
+ key_type = typing_extensions.get_args(clean_type)[0]
82
+ value_type = typing_extensions.get_args(clean_type)[1]
83
+
84
+ return {
85
+ key: convert_and_respect_annotation_metadata(
86
+ object_=value,
87
+ annotation=annotation,
88
+ inner_type=value_type,
89
+ direction=direction,
90
+ )
91
+ for key, value in object_.items()
92
+ }
93
+
94
+ # If you're iterating on a string, do not bother to coerce it to a sequence.
95
+ if not isinstance(object_, str):
96
+ if (
97
+ typing_extensions.get_origin(clean_type) == typing.Set
98
+ or typing_extensions.get_origin(clean_type) == set
99
+ or clean_type == typing.Set
100
+ ) and isinstance(object_, typing.Set):
101
+ inner_type = typing_extensions.get_args(clean_type)[0]
102
+ return {
103
+ convert_and_respect_annotation_metadata(
104
+ object_=item,
105
+ annotation=annotation,
106
+ inner_type=inner_type,
107
+ direction=direction,
108
+ )
109
+ for item in object_
110
+ }
111
+ elif (
112
+ (
113
+ typing_extensions.get_origin(clean_type) == typing.List
114
+ or typing_extensions.get_origin(clean_type) == list
115
+ or clean_type == typing.List
116
+ )
117
+ and isinstance(object_, typing.List)
118
+ ) or (
119
+ (
120
+ typing_extensions.get_origin(clean_type) == typing.Sequence
121
+ or typing_extensions.get_origin(clean_type) == collections.abc.Sequence
122
+ or clean_type == typing.Sequence
123
+ )
124
+ and isinstance(object_, typing.Sequence)
125
+ ):
126
+ inner_type = typing_extensions.get_args(clean_type)[0]
127
+ return [
128
+ convert_and_respect_annotation_metadata(
129
+ object_=item,
130
+ annotation=annotation,
131
+ inner_type=inner_type,
132
+ direction=direction,
133
+ )
134
+ for item in object_
135
+ ]
136
+
137
+ if typing_extensions.get_origin(clean_type) == typing.Union:
138
+ # We should be able to ~relatively~ safely try to convert keys against all
139
+ # member types in the union, the edge case here is if one member aliases a field
140
+ # of the same name to a different name from another member
141
+ # Or if another member aliases a field of the same name that another member does not.
142
+ for member in typing_extensions.get_args(clean_type):
143
+ object_ = convert_and_respect_annotation_metadata(
144
+ object_=object_,
145
+ annotation=annotation,
146
+ inner_type=member,
147
+ direction=direction,
148
+ )
149
+ return object_
150
+
151
+ annotated_type = _get_annotation(annotation)
152
+ if annotated_type is None:
153
+ return object_
154
+
155
+ # If the object is not a TypedDict, a Union, or other container (list, set, sequence, etc.)
156
+ # Then we can safely call it on the recursive conversion.
157
+ return object_
158
+
159
+
160
+ def _convert_mapping(
161
+ object_: typing.Mapping[str, object],
162
+ expected_type: typing.Any,
163
+ direction: typing.Literal["read", "write"],
164
+ ) -> typing.Mapping[str, object]:
165
+ converted_object: typing.Dict[str, object] = {}
166
+ annotations = typing_extensions.get_type_hints(expected_type, include_extras=True)
167
+ aliases_to_field_names = _get_alias_to_field_name(annotations)
168
+ for key, value in object_.items():
169
+ if direction == "read" and key in aliases_to_field_names:
170
+ dealiased_key = aliases_to_field_names.get(key)
171
+ if dealiased_key is not None:
172
+ type_ = annotations.get(dealiased_key)
173
+ else:
174
+ type_ = annotations.get(key)
175
+ # Note you can't get the annotation by the field name if you're in read mode, so you must check the aliases map
176
+ #
177
+ # So this is effectively saying if we're in write mode, and we don't have a type, or if we're in read mode and we don't have an alias
178
+ # then we can just pass the value through as is
179
+ if type_ is None:
180
+ converted_object[key] = value
181
+ elif direction == "read" and key not in aliases_to_field_names:
182
+ converted_object[key] = convert_and_respect_annotation_metadata(
183
+ object_=value, annotation=type_, direction=direction
184
+ )
185
+ else:
186
+ converted_object[
187
+ _alias_key(key, type_, direction, aliases_to_field_names)
188
+ ] = convert_and_respect_annotation_metadata(
189
+ object_=value, annotation=type_, direction=direction
190
+ )
191
+ return converted_object
192
+
193
+
194
+ def _get_annotation(type_: typing.Any) -> typing.Optional[typing.Any]:
195
+ maybe_annotated_type = typing_extensions.get_origin(type_)
196
+ if maybe_annotated_type is None:
197
+ return None
198
+
199
+ if maybe_annotated_type == typing_extensions.NotRequired:
200
+ type_ = typing_extensions.get_args(type_)[0]
201
+ maybe_annotated_type = typing_extensions.get_origin(type_)
202
+
203
+ if maybe_annotated_type == typing_extensions.Annotated:
204
+ return type_
205
+
206
+ return None
207
+
208
+
209
+ def _remove_annotations(type_: typing.Any) -> typing.Any:
210
+ maybe_annotated_type = typing_extensions.get_origin(type_)
211
+ if maybe_annotated_type is None:
212
+ return type_
213
+
214
+ if maybe_annotated_type == typing_extensions.NotRequired:
215
+ return _remove_annotations(typing_extensions.get_args(type_)[0])
216
+
217
+ if maybe_annotated_type == typing_extensions.Annotated:
218
+ return _remove_annotations(typing_extensions.get_args(type_)[0])
219
+
220
+ return type_
221
+
222
+
223
+ def get_alias_to_field_mapping(type_: typing.Any) -> typing.Dict[str, str]:
224
+ annotations = typing_extensions.get_type_hints(type_, include_extras=True)
225
+ return _get_alias_to_field_name(annotations)
226
+
227
+
228
+ def get_field_to_alias_mapping(type_: typing.Any) -> typing.Dict[str, str]:
229
+ annotations = typing_extensions.get_type_hints(type_, include_extras=True)
230
+ return _get_field_to_alias_name(annotations)
231
+
232
+
233
+ def _get_alias_to_field_name(
234
+ field_to_hint: typing.Dict[str, typing.Any],
235
+ ) -> typing.Dict[str, str]:
236
+ aliases = {}
237
+ for field, hint in field_to_hint.items():
238
+ maybe_alias = _get_alias_from_type(hint)
239
+ if maybe_alias is not None:
240
+ aliases[maybe_alias] = field
241
+ return aliases
242
+
243
+
244
+ def _get_field_to_alias_name(
245
+ field_to_hint: typing.Dict[str, typing.Any],
246
+ ) -> typing.Dict[str, str]:
247
+ aliases = {}
248
+ for field, hint in field_to_hint.items():
249
+ maybe_alias = _get_alias_from_type(hint)
250
+ if maybe_alias is not None:
251
+ aliases[field] = maybe_alias
252
+ return aliases
253
+
254
+
255
+ def _get_alias_from_type(type_: typing.Any) -> typing.Optional[str]:
256
+ maybe_annotated_type = _get_annotation(type_)
257
+
258
+ if maybe_annotated_type is not None:
259
+ # The actual annotations are 1 onward, the first is the annotated type
260
+ annotations = typing_extensions.get_args(maybe_annotated_type)[1:]
261
+
262
+ for annotation in annotations:
263
+ if isinstance(annotation, FieldMetadata) and annotation.alias is not None:
264
+ return annotation.alias
265
+ return None
266
+
267
+
268
+ def _alias_key(
269
+ key: str,
270
+ type_: typing.Any,
271
+ direction: typing.Literal["read", "write"],
272
+ aliases_to_field_names: typing.Dict[str, str],
273
+ ) -> str:
274
+ if direction == "read":
275
+ return aliases_to_field_names.get(key, key)
276
+ return _get_alias_from_type(type_=type_) or key
@@ -0,0 +1 @@
1
+ # This file was auto-generated by Fern from our API Definition.
@@ -0,0 +1,196 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from ..core.client_wrapper import SyncClientWrapper
5
+ from ..core.request_options import RequestOptions
6
+ from ..core.pydantic_utilities import parse_obj_as
7
+ from ..errors.unprocessable_entity_error import UnprocessableEntityError
8
+ from ..types.http_validation_error import HttpValidationError
9
+ from json.decoder import JSONDecodeError
10
+ from ..core.api_error import ApiError
11
+ from ..core.client_wrapper import AsyncClientWrapper
12
+
13
+ # this is used as the default value for optional parameters
14
+ OMIT = typing.cast(typing.Any, ...)
15
+
16
+
17
+ class EnvironmentsClient:
18
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
19
+ self._client_wrapper = client_wrapper
20
+
21
+ def deploy_to_environment(
22
+ self,
23
+ *,
24
+ environment_name: str,
25
+ variant_id: str,
26
+ request_options: typing.Optional[RequestOptions] = None,
27
+ ) -> typing.Optional[typing.Any]:
28
+ """
29
+ Deploys a given variant to an environment
30
+
31
+ Args:
32
+ environment_name: Name of the environment to deploy to.
33
+ variant_id: variant id to deploy.
34
+ stoken_session: . Defaults to Depends(verify_session()).
35
+
36
+ Raises:
37
+ HTTPException: If the deployment fails.
38
+
39
+ Parameters
40
+ ----------
41
+ environment_name : str
42
+
43
+ variant_id : str
44
+
45
+ request_options : typing.Optional[RequestOptions]
46
+ Request-specific configuration.
47
+
48
+ Returns
49
+ -------
50
+ typing.Optional[typing.Any]
51
+ Successful Response
52
+
53
+ Examples
54
+ --------
55
+ from agenta import AgentaApi
56
+
57
+ client = AgentaApi(
58
+ api_key="YOUR_API_KEY",
59
+ base_url="https://yourhost.com/path/to/api",
60
+ )
61
+ client.environments.deploy_to_environment(
62
+ environment_name="environment_name",
63
+ variant_id="variant_id",
64
+ )
65
+ """
66
+ _response = self._client_wrapper.httpx_client.request(
67
+ "environments/deploy",
68
+ method="POST",
69
+ json={
70
+ "environment_name": environment_name,
71
+ "variant_id": variant_id,
72
+ },
73
+ headers={
74
+ "content-type": "application/json",
75
+ },
76
+ request_options=request_options,
77
+ omit=OMIT,
78
+ )
79
+ try:
80
+ if 200 <= _response.status_code < 300:
81
+ return typing.cast(
82
+ typing.Optional[typing.Any],
83
+ parse_obj_as(
84
+ type_=typing.Optional[typing.Any], # type: ignore
85
+ object_=_response.json(),
86
+ ),
87
+ )
88
+ if _response.status_code == 422:
89
+ raise UnprocessableEntityError(
90
+ typing.cast(
91
+ HttpValidationError,
92
+ parse_obj_as(
93
+ type_=HttpValidationError, # type: ignore
94
+ object_=_response.json(),
95
+ ),
96
+ )
97
+ )
98
+ _response_json = _response.json()
99
+ except JSONDecodeError:
100
+ raise ApiError(status_code=_response.status_code, body=_response.text)
101
+ raise ApiError(status_code=_response.status_code, body=_response_json)
102
+
103
+
104
+ class AsyncEnvironmentsClient:
105
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
106
+ self._client_wrapper = client_wrapper
107
+
108
+ async def deploy_to_environment(
109
+ self,
110
+ *,
111
+ environment_name: str,
112
+ variant_id: str,
113
+ request_options: typing.Optional[RequestOptions] = None,
114
+ ) -> typing.Optional[typing.Any]:
115
+ """
116
+ Deploys a given variant to an environment
117
+
118
+ Args:
119
+ environment_name: Name of the environment to deploy to.
120
+ variant_id: variant id to deploy.
121
+ stoken_session: . Defaults to Depends(verify_session()).
122
+
123
+ Raises:
124
+ HTTPException: If the deployment fails.
125
+
126
+ Parameters
127
+ ----------
128
+ environment_name : str
129
+
130
+ variant_id : str
131
+
132
+ request_options : typing.Optional[RequestOptions]
133
+ Request-specific configuration.
134
+
135
+ Returns
136
+ -------
137
+ typing.Optional[typing.Any]
138
+ Successful Response
139
+
140
+ Examples
141
+ --------
142
+ import asyncio
143
+
144
+ from agenta import AsyncAgentaApi
145
+
146
+ client = AsyncAgentaApi(
147
+ api_key="YOUR_API_KEY",
148
+ base_url="https://yourhost.com/path/to/api",
149
+ )
150
+
151
+
152
+ async def main() -> None:
153
+ await client.environments.deploy_to_environment(
154
+ environment_name="environment_name",
155
+ variant_id="variant_id",
156
+ )
157
+
158
+
159
+ asyncio.run(main())
160
+ """
161
+ _response = await self._client_wrapper.httpx_client.request(
162
+ "environments/deploy",
163
+ method="POST",
164
+ json={
165
+ "environment_name": environment_name,
166
+ "variant_id": variant_id,
167
+ },
168
+ headers={
169
+ "content-type": "application/json",
170
+ },
171
+ request_options=request_options,
172
+ omit=OMIT,
173
+ )
174
+ try:
175
+ if 200 <= _response.status_code < 300:
176
+ return typing.cast(
177
+ typing.Optional[typing.Any],
178
+ parse_obj_as(
179
+ type_=typing.Optional[typing.Any], # type: ignore
180
+ object_=_response.json(),
181
+ ),
182
+ )
183
+ if _response.status_code == 422:
184
+ raise UnprocessableEntityError(
185
+ typing.cast(
186
+ HttpValidationError,
187
+ parse_obj_as(
188
+ type_=HttpValidationError, # type: ignore
189
+ object_=_response.json(),
190
+ ),
191
+ )
192
+ )
193
+ _response_json = _response.json()
194
+ except JSONDecodeError:
195
+ raise ApiError(status_code=_response.status_code, body=_response.text)
196
+ raise ApiError(status_code=_response.status_code, body=_response_json)
@@ -0,0 +1 @@
1
+ # This file was auto-generated by Fern from our API Definition.