mirascope 2.0.0a1__py3-none-any.whl → 2.0.0a3__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.
Files changed (205) hide show
  1. mirascope/__init__.py +2 -2
  2. mirascope/api/__init__.py +6 -0
  3. mirascope/api/_generated/README.md +207 -0
  4. mirascope/api/_generated/__init__.py +85 -0
  5. mirascope/api/_generated/client.py +155 -0
  6. mirascope/api/_generated/core/__init__.py +52 -0
  7. mirascope/api/_generated/core/api_error.py +23 -0
  8. mirascope/api/_generated/core/client_wrapper.py +58 -0
  9. mirascope/api/_generated/core/datetime_utils.py +30 -0
  10. mirascope/api/_generated/core/file.py +70 -0
  11. mirascope/api/_generated/core/force_multipart.py +16 -0
  12. mirascope/api/_generated/core/http_client.py +619 -0
  13. mirascope/api/_generated/core/http_response.py +55 -0
  14. mirascope/api/_generated/core/jsonable_encoder.py +102 -0
  15. mirascope/api/_generated/core/pydantic_utilities.py +310 -0
  16. mirascope/api/_generated/core/query_encoder.py +60 -0
  17. mirascope/api/_generated/core/remove_none_from_dict.py +11 -0
  18. mirascope/api/_generated/core/request_options.py +35 -0
  19. mirascope/api/_generated/core/serialization.py +282 -0
  20. mirascope/api/_generated/docs/__init__.py +4 -0
  21. mirascope/api/_generated/docs/client.py +95 -0
  22. mirascope/api/_generated/docs/raw_client.py +132 -0
  23. mirascope/api/_generated/environment.py +9 -0
  24. mirascope/api/_generated/errors/__init__.py +7 -0
  25. mirascope/api/_generated/errors/bad_request_error.py +15 -0
  26. mirascope/api/_generated/health/__init__.py +7 -0
  27. mirascope/api/_generated/health/client.py +96 -0
  28. mirascope/api/_generated/health/raw_client.py +129 -0
  29. mirascope/api/_generated/health/types/__init__.py +8 -0
  30. mirascope/api/_generated/health/types/health_check_response.py +24 -0
  31. mirascope/api/_generated/health/types/health_check_response_status.py +5 -0
  32. mirascope/api/_generated/reference.md +167 -0
  33. mirascope/api/_generated/traces/__init__.py +55 -0
  34. mirascope/api/_generated/traces/client.py +162 -0
  35. mirascope/api/_generated/traces/raw_client.py +168 -0
  36. mirascope/api/_generated/traces/types/__init__.py +95 -0
  37. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +36 -0
  38. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +31 -0
  39. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +25 -0
  40. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +54 -0
  41. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +23 -0
  42. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +28 -0
  43. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +24 -0
  44. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +35 -0
  45. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +35 -0
  46. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +27 -0
  47. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +54 -0
  48. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +23 -0
  49. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +28 -0
  50. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value_values_item.py +24 -0
  51. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +60 -0
  52. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +29 -0
  53. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +54 -0
  54. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +23 -0
  55. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +28 -0
  56. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value_values_item.py +24 -0
  57. mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +24 -0
  58. mirascope/api/_generated/traces/types/traces_create_response.py +27 -0
  59. mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +28 -0
  60. mirascope/api/_generated/types/__init__.py +21 -0
  61. mirascope/api/_generated/types/http_api_decode_error.py +31 -0
  62. mirascope/api/_generated/types/http_api_decode_error_tag.py +5 -0
  63. mirascope/api/_generated/types/issue.py +44 -0
  64. mirascope/api/_generated/types/issue_tag.py +17 -0
  65. mirascope/api/_generated/types/property_key.py +7 -0
  66. mirascope/api/_generated/types/property_key_tag.py +29 -0
  67. mirascope/api/_generated/types/property_key_tag_tag.py +5 -0
  68. mirascope/api/client.py +255 -0
  69. mirascope/api/settings.py +81 -0
  70. mirascope/llm/__init__.py +41 -11
  71. mirascope/llm/calls/calls.py +81 -57
  72. mirascope/llm/calls/decorator.py +121 -115
  73. mirascope/llm/content/__init__.py +3 -2
  74. mirascope/llm/context/_utils.py +19 -6
  75. mirascope/llm/exceptions.py +30 -16
  76. mirascope/llm/formatting/_utils.py +9 -5
  77. mirascope/llm/formatting/format.py +2 -2
  78. mirascope/llm/formatting/from_call_args.py +2 -2
  79. mirascope/llm/messages/message.py +13 -5
  80. mirascope/llm/models/__init__.py +2 -2
  81. mirascope/llm/models/models.py +189 -81
  82. mirascope/llm/prompts/__init__.py +13 -12
  83. mirascope/llm/prompts/_utils.py +27 -24
  84. mirascope/llm/prompts/decorator.py +133 -204
  85. mirascope/llm/prompts/prompts.py +424 -0
  86. mirascope/llm/prompts/protocols.py +25 -59
  87. mirascope/llm/providers/__init__.py +38 -0
  88. mirascope/llm/{clients → providers}/_missing_import_stubs.py +8 -6
  89. mirascope/llm/providers/anthropic/__init__.py +24 -0
  90. mirascope/llm/{clients → providers}/anthropic/_utils/decode.py +5 -4
  91. mirascope/llm/{clients → providers}/anthropic/_utils/encode.py +31 -10
  92. mirascope/llm/providers/anthropic/model_id.py +40 -0
  93. mirascope/llm/{clients/anthropic/clients.py → providers/anthropic/provider.py} +33 -418
  94. mirascope/llm/{clients → providers}/base/__init__.py +3 -3
  95. mirascope/llm/{clients → providers}/base/_utils.py +10 -7
  96. mirascope/llm/{clients/base/client.py → providers/base/base_provider.py} +255 -126
  97. mirascope/llm/providers/google/__init__.py +21 -0
  98. mirascope/llm/{clients → providers}/google/_utils/decode.py +6 -4
  99. mirascope/llm/{clients → providers}/google/_utils/encode.py +30 -24
  100. mirascope/llm/providers/google/model_id.py +28 -0
  101. mirascope/llm/providers/google/provider.py +438 -0
  102. mirascope/llm/providers/load_provider.py +48 -0
  103. mirascope/llm/providers/mlx/__init__.py +24 -0
  104. mirascope/llm/providers/mlx/_utils.py +107 -0
  105. mirascope/llm/providers/mlx/encoding/__init__.py +8 -0
  106. mirascope/llm/providers/mlx/encoding/base.py +69 -0
  107. mirascope/llm/providers/mlx/encoding/transformers.py +131 -0
  108. mirascope/llm/providers/mlx/mlx.py +237 -0
  109. mirascope/llm/providers/mlx/model_id.py +17 -0
  110. mirascope/llm/providers/mlx/provider.py +411 -0
  111. mirascope/llm/providers/model_id.py +16 -0
  112. mirascope/llm/providers/openai/__init__.py +6 -0
  113. mirascope/llm/providers/openai/completions/__init__.py +20 -0
  114. mirascope/llm/{clients/openai/responses → providers/openai/completions}/_utils/__init__.py +2 -0
  115. mirascope/llm/{clients → providers}/openai/completions/_utils/decode.py +5 -3
  116. mirascope/llm/{clients → providers}/openai/completions/_utils/encode.py +33 -23
  117. mirascope/llm/providers/openai/completions/provider.py +456 -0
  118. mirascope/llm/providers/openai/model_id.py +31 -0
  119. mirascope/llm/providers/openai/model_info.py +246 -0
  120. mirascope/llm/providers/openai/provider.py +386 -0
  121. mirascope/llm/providers/openai/responses/__init__.py +21 -0
  122. mirascope/llm/{clients → providers}/openai/responses/_utils/decode.py +5 -3
  123. mirascope/llm/{clients → providers}/openai/responses/_utils/encode.py +28 -17
  124. mirascope/llm/providers/openai/responses/provider.py +470 -0
  125. mirascope/llm/{clients → providers}/openai/shared/_utils.py +7 -3
  126. mirascope/llm/providers/provider_id.py +13 -0
  127. mirascope/llm/providers/provider_registry.py +167 -0
  128. mirascope/llm/responses/base_response.py +10 -5
  129. mirascope/llm/responses/base_stream_response.py +10 -5
  130. mirascope/llm/responses/response.py +24 -13
  131. mirascope/llm/responses/root_response.py +7 -12
  132. mirascope/llm/responses/stream_response.py +35 -23
  133. mirascope/llm/tools/__init__.py +9 -2
  134. mirascope/llm/tools/_utils.py +12 -3
  135. mirascope/llm/tools/decorator.py +10 -10
  136. mirascope/llm/tools/protocols.py +4 -4
  137. mirascope/llm/tools/tool_schema.py +44 -9
  138. mirascope/llm/tools/tools.py +12 -11
  139. mirascope/ops/__init__.py +156 -0
  140. mirascope/ops/_internal/__init__.py +5 -0
  141. mirascope/ops/_internal/closure.py +1118 -0
  142. mirascope/ops/_internal/configuration.py +126 -0
  143. mirascope/ops/_internal/context.py +76 -0
  144. mirascope/ops/_internal/exporters/__init__.py +26 -0
  145. mirascope/ops/_internal/exporters/exporters.py +342 -0
  146. mirascope/ops/_internal/exporters/processors.py +104 -0
  147. mirascope/ops/_internal/exporters/types.py +165 -0
  148. mirascope/ops/_internal/exporters/utils.py +29 -0
  149. mirascope/ops/_internal/instrumentation/__init__.py +8 -0
  150. mirascope/ops/_internal/instrumentation/llm/__init__.py +8 -0
  151. mirascope/ops/_internal/instrumentation/llm/encode.py +238 -0
  152. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/__init__.py +38 -0
  153. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_input_messages.py +31 -0
  154. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_output_messages.py +38 -0
  155. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_system_instructions.py +18 -0
  156. mirascope/ops/_internal/instrumentation/llm/gen_ai_types/shared.py +100 -0
  157. mirascope/ops/_internal/instrumentation/llm/llm.py +1288 -0
  158. mirascope/ops/_internal/propagation.py +198 -0
  159. mirascope/ops/_internal/protocols.py +51 -0
  160. mirascope/ops/_internal/session.py +139 -0
  161. mirascope/ops/_internal/spans.py +232 -0
  162. mirascope/ops/_internal/traced_calls.py +371 -0
  163. mirascope/ops/_internal/traced_functions.py +394 -0
  164. mirascope/ops/_internal/tracing.py +276 -0
  165. mirascope/ops/_internal/types.py +13 -0
  166. mirascope/ops/_internal/utils.py +75 -0
  167. mirascope/ops/_internal/versioned_calls.py +512 -0
  168. mirascope/ops/_internal/versioned_functions.py +346 -0
  169. mirascope/ops/_internal/versioning.py +303 -0
  170. mirascope/ops/exceptions.py +21 -0
  171. {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/METADATA +77 -1
  172. mirascope-2.0.0a3.dist-info/RECORD +206 -0
  173. {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/WHEEL +1 -1
  174. mirascope/graphs/__init__.py +0 -22
  175. mirascope/graphs/finite_state_machine.py +0 -625
  176. mirascope/llm/agents/__init__.py +0 -15
  177. mirascope/llm/agents/agent.py +0 -97
  178. mirascope/llm/agents/agent_template.py +0 -45
  179. mirascope/llm/agents/decorator.py +0 -176
  180. mirascope/llm/calls/base_call.py +0 -33
  181. mirascope/llm/clients/__init__.py +0 -34
  182. mirascope/llm/clients/anthropic/__init__.py +0 -25
  183. mirascope/llm/clients/anthropic/model_ids.py +0 -8
  184. mirascope/llm/clients/google/__init__.py +0 -20
  185. mirascope/llm/clients/google/clients.py +0 -853
  186. mirascope/llm/clients/google/model_ids.py +0 -15
  187. mirascope/llm/clients/openai/__init__.py +0 -25
  188. mirascope/llm/clients/openai/completions/__init__.py +0 -28
  189. mirascope/llm/clients/openai/completions/_utils/model_features.py +0 -81
  190. mirascope/llm/clients/openai/completions/clients.py +0 -833
  191. mirascope/llm/clients/openai/completions/model_ids.py +0 -8
  192. mirascope/llm/clients/openai/responses/__init__.py +0 -26
  193. mirascope/llm/clients/openai/responses/_utils/model_features.py +0 -87
  194. mirascope/llm/clients/openai/responses/clients.py +0 -832
  195. mirascope/llm/clients/openai/responses/model_ids.py +0 -8
  196. mirascope/llm/clients/providers.py +0 -175
  197. mirascope-2.0.0a1.dist-info/RECORD +0 -102
  198. /mirascope/llm/{clients → providers}/anthropic/_utils/__init__.py +0 -0
  199. /mirascope/llm/{clients → providers}/base/kwargs.py +0 -0
  200. /mirascope/llm/{clients → providers}/base/params.py +0 -0
  201. /mirascope/llm/{clients → providers}/google/_utils/__init__.py +0 -0
  202. /mirascope/llm/{clients → providers}/google/message.py +0 -0
  203. /mirascope/llm/{clients/openai/completions → providers/openai/responses}/_utils/__init__.py +0 -0
  204. /mirascope/llm/{clients → providers}/openai/shared/__init__.py +0 -0
  205. {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,282 @@
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 pydantic
8
+ import typing_extensions
9
+
10
+
11
+ class FieldMetadata:
12
+ """
13
+ Metadata class used to annotate fields to provide additional information.
14
+
15
+ Example:
16
+ class MyDict(TypedDict):
17
+ field: typing.Annotated[str, FieldMetadata(alias="field_name")]
18
+
19
+ Will serialize: `{"field": "value"}`
20
+ To: `{"field_name": "value"}`
21
+ """
22
+
23
+ alias: str
24
+
25
+ def __init__(self, *, alias: str) -> None:
26
+ self.alias = alias
27
+
28
+
29
+ def convert_and_respect_annotation_metadata(
30
+ *,
31
+ object_: typing.Any,
32
+ annotation: typing.Any,
33
+ inner_type: typing.Optional[typing.Any] = None,
34
+ direction: typing.Literal["read", "write"],
35
+ ) -> typing.Any:
36
+ """
37
+ Respect the metadata annotations on a field, such as aliasing. This function effectively
38
+ manipulates the dict-form of an object to respect the metadata annotations. This is primarily used for
39
+ TypedDicts, which cannot support aliasing out of the box, and can be extended for additional
40
+ utilities, such as defaults.
41
+
42
+ Parameters
43
+ ----------
44
+ object_ : typing.Any
45
+
46
+ annotation : type
47
+ The type we're looking to apply typing annotations from
48
+
49
+ inner_type : typing.Optional[type]
50
+
51
+ Returns
52
+ -------
53
+ typing.Any
54
+ """
55
+
56
+ if object_ is None:
57
+ return None
58
+ if inner_type is None:
59
+ inner_type = annotation
60
+
61
+ clean_type = _remove_annotations(inner_type)
62
+ # Pydantic models
63
+ if (
64
+ inspect.isclass(clean_type)
65
+ and issubclass(clean_type, pydantic.BaseModel)
66
+ and isinstance(object_, typing.Mapping)
67
+ ):
68
+ return _convert_mapping(object_, clean_type, direction)
69
+ # TypedDicts
70
+ if typing_extensions.is_typeddict(clean_type) and isinstance(
71
+ object_, typing.Mapping
72
+ ):
73
+ return _convert_mapping(object_, clean_type, direction)
74
+
75
+ if (
76
+ typing_extensions.get_origin(clean_type) == typing.Dict
77
+ or typing_extensions.get_origin(clean_type) == dict
78
+ or clean_type == typing.Dict
79
+ ) and isinstance(object_, typing.Dict):
80
+ key_type = typing_extensions.get_args(clean_type)[0]
81
+ value_type = typing_extensions.get_args(clean_type)[1]
82
+
83
+ return {
84
+ key: convert_and_respect_annotation_metadata(
85
+ object_=value,
86
+ annotation=annotation,
87
+ inner_type=value_type,
88
+ direction=direction,
89
+ )
90
+ for key, value in object_.items()
91
+ }
92
+
93
+ # If you're iterating on a string, do not bother to coerce it to a sequence.
94
+ if not isinstance(object_, str):
95
+ if (
96
+ typing_extensions.get_origin(clean_type) == typing.Set
97
+ or typing_extensions.get_origin(clean_type) == set
98
+ or clean_type == typing.Set
99
+ ) and isinstance(object_, typing.Set):
100
+ inner_type = typing_extensions.get_args(clean_type)[0]
101
+ return {
102
+ convert_and_respect_annotation_metadata(
103
+ object_=item,
104
+ annotation=annotation,
105
+ inner_type=inner_type,
106
+ direction=direction,
107
+ )
108
+ for item in object_
109
+ }
110
+ elif (
111
+ (
112
+ typing_extensions.get_origin(clean_type) == typing.List
113
+ or typing_extensions.get_origin(clean_type) == list
114
+ or clean_type == typing.List
115
+ )
116
+ and isinstance(object_, typing.List)
117
+ ) or (
118
+ (
119
+ typing_extensions.get_origin(clean_type) == typing.Sequence
120
+ or typing_extensions.get_origin(clean_type) == collections.abc.Sequence
121
+ or clean_type == typing.Sequence
122
+ )
123
+ and isinstance(object_, typing.Sequence)
124
+ ):
125
+ inner_type = typing_extensions.get_args(clean_type)[0]
126
+ return [
127
+ convert_and_respect_annotation_metadata(
128
+ object_=item,
129
+ annotation=annotation,
130
+ inner_type=inner_type,
131
+ direction=direction,
132
+ )
133
+ for item in object_
134
+ ]
135
+
136
+ if typing_extensions.get_origin(clean_type) == typing.Union:
137
+ # We should be able to ~relatively~ safely try to convert keys against all
138
+ # member types in the union, the edge case here is if one member aliases a field
139
+ # of the same name to a different name from another member
140
+ # Or if another member aliases a field of the same name that another member does not.
141
+ for member in typing_extensions.get_args(clean_type):
142
+ object_ = convert_and_respect_annotation_metadata(
143
+ object_=object_,
144
+ annotation=annotation,
145
+ inner_type=member,
146
+ direction=direction,
147
+ )
148
+ return object_
149
+
150
+ annotated_type = _get_annotation(annotation)
151
+ if annotated_type is None:
152
+ return object_
153
+
154
+ # If the object is not a TypedDict, a Union, or other container (list, set, sequence, etc.)
155
+ # Then we can safely call it on the recursive conversion.
156
+ return object_
157
+
158
+
159
+ def _convert_mapping(
160
+ object_: typing.Mapping[str, object],
161
+ expected_type: typing.Any,
162
+ direction: typing.Literal["read", "write"],
163
+ ) -> typing.Mapping[str, object]:
164
+ converted_object: typing.Dict[str, object] = {}
165
+ try:
166
+ annotations = typing_extensions.get_type_hints(
167
+ expected_type, include_extras=True
168
+ )
169
+ except NameError:
170
+ # The TypedDict contains a circular reference, so
171
+ # we use the __annotations__ attribute directly.
172
+ annotations = getattr(expected_type, "__annotations__", {})
173
+ aliases_to_field_names = _get_alias_to_field_name(annotations)
174
+ for key, value in object_.items():
175
+ if direction == "read" and key in aliases_to_field_names:
176
+ dealiased_key = aliases_to_field_names.get(key)
177
+ if dealiased_key is not None:
178
+ type_ = annotations.get(dealiased_key)
179
+ else:
180
+ type_ = annotations.get(key)
181
+ # Note you can't get the annotation by the field name if you're in read mode, so you must check the aliases map
182
+ #
183
+ # 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
184
+ # then we can just pass the value through as is
185
+ if type_ is None:
186
+ converted_object[key] = value
187
+ elif direction == "read" and key not in aliases_to_field_names:
188
+ converted_object[key] = convert_and_respect_annotation_metadata(
189
+ object_=value, annotation=type_, direction=direction
190
+ )
191
+ else:
192
+ converted_object[
193
+ _alias_key(key, type_, direction, aliases_to_field_names)
194
+ ] = convert_and_respect_annotation_metadata(
195
+ object_=value, annotation=type_, direction=direction
196
+ )
197
+ return converted_object
198
+
199
+
200
+ def _get_annotation(type_: typing.Any) -> typing.Optional[typing.Any]:
201
+ maybe_annotated_type = typing_extensions.get_origin(type_)
202
+ if maybe_annotated_type is None:
203
+ return None
204
+
205
+ if maybe_annotated_type == typing_extensions.NotRequired:
206
+ type_ = typing_extensions.get_args(type_)[0]
207
+ maybe_annotated_type = typing_extensions.get_origin(type_)
208
+
209
+ if maybe_annotated_type == typing_extensions.Annotated:
210
+ return type_
211
+
212
+ return None
213
+
214
+
215
+ def _remove_annotations(type_: typing.Any) -> typing.Any:
216
+ maybe_annotated_type = typing_extensions.get_origin(type_)
217
+ if maybe_annotated_type is None:
218
+ return type_
219
+
220
+ if maybe_annotated_type == typing_extensions.NotRequired:
221
+ return _remove_annotations(typing_extensions.get_args(type_)[0])
222
+
223
+ if maybe_annotated_type == typing_extensions.Annotated:
224
+ return _remove_annotations(typing_extensions.get_args(type_)[0])
225
+
226
+ return type_
227
+
228
+
229
+ def get_alias_to_field_mapping(type_: typing.Any) -> typing.Dict[str, str]:
230
+ annotations = typing_extensions.get_type_hints(type_, include_extras=True)
231
+ return _get_alias_to_field_name(annotations)
232
+
233
+
234
+ def get_field_to_alias_mapping(type_: typing.Any) -> typing.Dict[str, str]:
235
+ annotations = typing_extensions.get_type_hints(type_, include_extras=True)
236
+ return _get_field_to_alias_name(annotations)
237
+
238
+
239
+ def _get_alias_to_field_name(
240
+ field_to_hint: typing.Dict[str, typing.Any],
241
+ ) -> typing.Dict[str, str]:
242
+ aliases = {}
243
+ for field, hint in field_to_hint.items():
244
+ maybe_alias = _get_alias_from_type(hint)
245
+ if maybe_alias is not None:
246
+ aliases[maybe_alias] = field
247
+ return aliases
248
+
249
+
250
+ def _get_field_to_alias_name(
251
+ field_to_hint: typing.Dict[str, typing.Any],
252
+ ) -> typing.Dict[str, str]:
253
+ aliases = {}
254
+ for field, hint in field_to_hint.items():
255
+ maybe_alias = _get_alias_from_type(hint)
256
+ if maybe_alias is not None:
257
+ aliases[field] = maybe_alias
258
+ return aliases
259
+
260
+
261
+ def _get_alias_from_type(type_: typing.Any) -> typing.Optional[str]:
262
+ maybe_annotated_type = _get_annotation(type_)
263
+
264
+ if maybe_annotated_type is not None:
265
+ # The actual annotations are 1 onward, the first is the annotated type
266
+ annotations = typing_extensions.get_args(maybe_annotated_type)[1:]
267
+
268
+ for annotation in annotations:
269
+ if isinstance(annotation, FieldMetadata) and annotation.alias is not None:
270
+ return annotation.alias
271
+ return None
272
+
273
+
274
+ def _alias_key(
275
+ key: str,
276
+ type_: typing.Any,
277
+ direction: typing.Literal["read", "write"],
278
+ aliases_to_field_names: typing.Dict[str, str],
279
+ ) -> str:
280
+ if direction == "read":
281
+ return aliases_to_field_names.get(key, key)
282
+ return _get_alias_from_type(type_=type_) or key
@@ -0,0 +1,4 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
@@ -0,0 +1,95 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
6
+ from ..core.request_options import RequestOptions
7
+ from .raw_client import AsyncRawDocsClient, RawDocsClient
8
+
9
+
10
+ class DocsClient:
11
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
12
+ self._raw_client = RawDocsClient(client_wrapper=client_wrapper)
13
+
14
+ @property
15
+ def with_raw_response(self) -> RawDocsClient:
16
+ """
17
+ Retrieves a raw implementation of this client that returns raw responses.
18
+
19
+ Returns
20
+ -------
21
+ RawDocsClient
22
+ """
23
+ return self._raw_client
24
+
25
+ def openapi(
26
+ self, *, request_options: typing.Optional[RequestOptions] = None
27
+ ) -> typing.Optional[typing.Any]:
28
+ """
29
+ Parameters
30
+ ----------
31
+ request_options : typing.Optional[RequestOptions]
32
+ Request-specific configuration.
33
+
34
+ Returns
35
+ -------
36
+ typing.Optional[typing.Any]
37
+ Success
38
+
39
+ Examples
40
+ --------
41
+ from mirascope.api._generated import Mirascope
42
+
43
+ client = Mirascope()
44
+ client.docs.openapi()
45
+ """
46
+ _response = self._raw_client.openapi(request_options=request_options)
47
+ return _response.data
48
+
49
+
50
+ class AsyncDocsClient:
51
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
52
+ self._raw_client = AsyncRawDocsClient(client_wrapper=client_wrapper)
53
+
54
+ @property
55
+ def with_raw_response(self) -> AsyncRawDocsClient:
56
+ """
57
+ Retrieves a raw implementation of this client that returns raw responses.
58
+
59
+ Returns
60
+ -------
61
+ AsyncRawDocsClient
62
+ """
63
+ return self._raw_client
64
+
65
+ async def openapi(
66
+ self, *, request_options: typing.Optional[RequestOptions] = None
67
+ ) -> typing.Optional[typing.Any]:
68
+ """
69
+ Parameters
70
+ ----------
71
+ request_options : typing.Optional[RequestOptions]
72
+ Request-specific configuration.
73
+
74
+ Returns
75
+ -------
76
+ typing.Optional[typing.Any]
77
+ Success
78
+
79
+ Examples
80
+ --------
81
+ import asyncio
82
+
83
+ from mirascope.api._generated import AsyncMirascope
84
+
85
+ client = AsyncMirascope()
86
+
87
+
88
+ async def main() -> None:
89
+ await client.docs.openapi()
90
+
91
+
92
+ asyncio.run(main())
93
+ """
94
+ _response = await self._raw_client.openapi(request_options=request_options)
95
+ return _response.data
@@ -0,0 +1,132 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+ from json.decoder import JSONDecodeError
5
+
6
+ from ..core.api_error import ApiError
7
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8
+ from ..core.http_response import AsyncHttpResponse, HttpResponse
9
+ from ..core.pydantic_utilities import parse_obj_as
10
+ from ..core.request_options import RequestOptions
11
+ from ..errors.bad_request_error import BadRequestError
12
+ from ..types.http_api_decode_error import HttpApiDecodeError
13
+
14
+
15
+ class RawDocsClient:
16
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
17
+ self._client_wrapper = client_wrapper
18
+
19
+ def openapi(
20
+ self, *, request_options: typing.Optional[RequestOptions] = None
21
+ ) -> HttpResponse[typing.Optional[typing.Any]]:
22
+ """
23
+ Parameters
24
+ ----------
25
+ request_options : typing.Optional[RequestOptions]
26
+ Request-specific configuration.
27
+
28
+ Returns
29
+ -------
30
+ HttpResponse[typing.Optional[typing.Any]]
31
+ Success
32
+ """
33
+ _response = self._client_wrapper.httpx_client.request(
34
+ "docs/openapi.json",
35
+ method="GET",
36
+ request_options=request_options,
37
+ )
38
+ try:
39
+ if _response is None or not _response.text.strip():
40
+ return HttpResponse(response=_response, data=None)
41
+ if 200 <= _response.status_code < 300:
42
+ _data = typing.cast(
43
+ typing.Optional[typing.Any],
44
+ parse_obj_as(
45
+ type_=typing.Optional[typing.Any], # type: ignore
46
+ object_=_response.json(),
47
+ ),
48
+ )
49
+ return HttpResponse(response=_response, data=_data)
50
+ if _response.status_code == 400:
51
+ raise BadRequestError(
52
+ headers=dict(_response.headers),
53
+ body=typing.cast(
54
+ HttpApiDecodeError,
55
+ parse_obj_as(
56
+ type_=HttpApiDecodeError, # type: ignore
57
+ object_=_response.json(),
58
+ ),
59
+ ),
60
+ )
61
+ _response_json = _response.json()
62
+ except JSONDecodeError:
63
+ raise ApiError(
64
+ status_code=_response.status_code,
65
+ headers=dict(_response.headers),
66
+ body=_response.text,
67
+ )
68
+ raise ApiError(
69
+ status_code=_response.status_code,
70
+ headers=dict(_response.headers),
71
+ body=_response_json,
72
+ )
73
+
74
+
75
+ class AsyncRawDocsClient:
76
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
77
+ self._client_wrapper = client_wrapper
78
+
79
+ async def openapi(
80
+ self, *, request_options: typing.Optional[RequestOptions] = None
81
+ ) -> AsyncHttpResponse[typing.Optional[typing.Any]]:
82
+ """
83
+ Parameters
84
+ ----------
85
+ request_options : typing.Optional[RequestOptions]
86
+ Request-specific configuration.
87
+
88
+ Returns
89
+ -------
90
+ AsyncHttpResponse[typing.Optional[typing.Any]]
91
+ Success
92
+ """
93
+ _response = await self._client_wrapper.httpx_client.request(
94
+ "docs/openapi.json",
95
+ method="GET",
96
+ request_options=request_options,
97
+ )
98
+ try:
99
+ if _response is None or not _response.text.strip():
100
+ return AsyncHttpResponse(response=_response, data=None)
101
+ if 200 <= _response.status_code < 300:
102
+ _data = typing.cast(
103
+ typing.Optional[typing.Any],
104
+ parse_obj_as(
105
+ type_=typing.Optional[typing.Any], # type: ignore
106
+ object_=_response.json(),
107
+ ),
108
+ )
109
+ return AsyncHttpResponse(response=_response, data=_data)
110
+ if _response.status_code == 400:
111
+ raise BadRequestError(
112
+ headers=dict(_response.headers),
113
+ body=typing.cast(
114
+ HttpApiDecodeError,
115
+ parse_obj_as(
116
+ type_=HttpApiDecodeError, # type: ignore
117
+ object_=_response.json(),
118
+ ),
119
+ ),
120
+ )
121
+ _response_json = _response.json()
122
+ except JSONDecodeError:
123
+ raise ApiError(
124
+ status_code=_response.status_code,
125
+ headers=dict(_response.headers),
126
+ body=_response.text,
127
+ )
128
+ raise ApiError(
129
+ status_code=_response.status_code,
130
+ headers=dict(_response.headers),
131
+ body=_response_json,
132
+ )
@@ -0,0 +1,9 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import enum
4
+
5
+
6
+ class MirascopeEnvironment(enum.Enum):
7
+ PRODUCTION = "https://v2.mirascope.com/api/v0"
8
+ STAGING = "https://staging.mirascope.com/api/v0"
9
+ LOCAL = "http://localhost:3000/api/v0"
@@ -0,0 +1,7 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ from .bad_request_error import BadRequestError
6
+
7
+ __all__ = ["BadRequestError"]
@@ -0,0 +1,15 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.api_error import ApiError
6
+ from ..types.http_api_decode_error import HttpApiDecodeError
7
+
8
+
9
+ class BadRequestError(ApiError):
10
+ def __init__(
11
+ self,
12
+ body: HttpApiDecodeError,
13
+ headers: typing.Optional[typing.Dict[str, str]] = None,
14
+ ):
15
+ super().__init__(status_code=400, headers=headers, body=body)
@@ -0,0 +1,7 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ from .types import HealthCheckResponse, HealthCheckResponseStatus
6
+
7
+ __all__ = ["HealthCheckResponse", "HealthCheckResponseStatus"]
@@ -0,0 +1,96 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
6
+ from ..core.request_options import RequestOptions
7
+ from .raw_client import AsyncRawHealthClient, RawHealthClient
8
+ from .types.health_check_response import HealthCheckResponse
9
+
10
+
11
+ class HealthClient:
12
+ def __init__(self, *, client_wrapper: SyncClientWrapper):
13
+ self._raw_client = RawHealthClient(client_wrapper=client_wrapper)
14
+
15
+ @property
16
+ def with_raw_response(self) -> RawHealthClient:
17
+ """
18
+ Retrieves a raw implementation of this client that returns raw responses.
19
+
20
+ Returns
21
+ -------
22
+ RawHealthClient
23
+ """
24
+ return self._raw_client
25
+
26
+ def check(
27
+ self, *, request_options: typing.Optional[RequestOptions] = None
28
+ ) -> HealthCheckResponse:
29
+ """
30
+ Parameters
31
+ ----------
32
+ request_options : typing.Optional[RequestOptions]
33
+ Request-specific configuration.
34
+
35
+ Returns
36
+ -------
37
+ HealthCheckResponse
38
+ Success
39
+
40
+ Examples
41
+ --------
42
+ from mirascope.api._generated import Mirascope
43
+
44
+ client = Mirascope()
45
+ client.health.check()
46
+ """
47
+ _response = self._raw_client.check(request_options=request_options)
48
+ return _response.data
49
+
50
+
51
+ class AsyncHealthClient:
52
+ def __init__(self, *, client_wrapper: AsyncClientWrapper):
53
+ self._raw_client = AsyncRawHealthClient(client_wrapper=client_wrapper)
54
+
55
+ @property
56
+ def with_raw_response(self) -> AsyncRawHealthClient:
57
+ """
58
+ Retrieves a raw implementation of this client that returns raw responses.
59
+
60
+ Returns
61
+ -------
62
+ AsyncRawHealthClient
63
+ """
64
+ return self._raw_client
65
+
66
+ async def check(
67
+ self, *, request_options: typing.Optional[RequestOptions] = None
68
+ ) -> HealthCheckResponse:
69
+ """
70
+ Parameters
71
+ ----------
72
+ request_options : typing.Optional[RequestOptions]
73
+ Request-specific configuration.
74
+
75
+ Returns
76
+ -------
77
+ HealthCheckResponse
78
+ Success
79
+
80
+ Examples
81
+ --------
82
+ import asyncio
83
+
84
+ from mirascope.api._generated import AsyncMirascope
85
+
86
+ client = AsyncMirascope()
87
+
88
+
89
+ async def main() -> None:
90
+ await client.health.check()
91
+
92
+
93
+ asyncio.run(main())
94
+ """
95
+ _response = await self._raw_client.check(request_options=request_options)
96
+ return _response.data