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
@@ -17,9 +17,9 @@ from ....formatting import (
17
17
  resolve_format,
18
18
  )
19
19
  from ....messages import AssistantMessage, Message, UserMessage
20
- from ....tools import FORMAT_TOOL_NAME, BaseToolkit, ToolSchema
20
+ from ....tools import FORMAT_TOOL_NAME, AnyToolSchema, BaseToolkit
21
21
  from ...base import Params, _utils as _base_utils
22
- from ..model_ids import AnthropicModelId
22
+ from ..model_id import AnthropicModelId, model_name
23
23
 
24
24
  DEFAULT_MAX_TOKENS = 16000
25
25
 
@@ -33,7 +33,7 @@ def encode_image_mime_type(
33
33
  if mime_type in ("image/jpeg", "image/png", "image/gif", "image/webp"):
34
34
  return mime_type
35
35
  raise FeatureNotSupportedError(
36
- feature=f"Image with mime_type: {mime_type}", provider="anthropic"
36
+ feature=f"Image with mime_type: {mime_type}", provider_id="anthropic"
37
37
  ) # pragma: no cover
38
38
 
39
39
 
@@ -59,13 +59,22 @@ def _encode_content(
59
59
  """Convert mirascope content to Anthropic content format."""
60
60
 
61
61
  if len(content) == 1 and content[0].type == "text":
62
+ if not content[0].text:
63
+ raise FeatureNotSupportedError(
64
+ "empty message content",
65
+ "anthropic",
66
+ message="Anthropic does not support empty message content.",
67
+ )
62
68
  return content[0].text
63
69
 
64
70
  blocks: list[anthropic_types.ContentBlockParam] = []
65
71
 
66
72
  for part in content:
67
73
  if part.type == "text":
68
- blocks.append(anthropic_types.TextBlockParam(type="text", text=part.text))
74
+ if part.text:
75
+ blocks.append(
76
+ anthropic_types.TextBlockParam(type="text", text=part.text)
77
+ )
69
78
  elif part.type == "image":
70
79
  source: (
71
80
  anthropic_types.Base64ImageSourceParam
@@ -116,6 +125,13 @@ def _encode_content(
116
125
  else:
117
126
  raise NotImplementedError(f"Unsupported content type: {part.type}")
118
127
 
128
+ if not blocks:
129
+ raise FeatureNotSupportedError(
130
+ "empty message content",
131
+ "anthropic",
132
+ message="Anthropic does not support empty message content.",
133
+ )
134
+
119
135
  return blocks
120
136
 
121
137
 
@@ -136,7 +152,7 @@ def _encode_message(
136
152
 
137
153
  if (
138
154
  message.role == "assistant"
139
- and message.provider == "anthropic"
155
+ and message.provider_id == "anthropic"
140
156
  and message.model_id == model_id
141
157
  and message.raw_message
142
158
  and not encode_thoughts
@@ -149,7 +165,7 @@ def _encode_message(
149
165
 
150
166
 
151
167
  @lru_cache(maxsize=128)
152
- def _convert_tool_to_tool_param(tool: ToolSchema) -> anthropic_types.ToolParam:
168
+ def _convert_tool_to_tool_param(tool: AnyToolSchema) -> anthropic_types.ToolParam:
153
169
  """Convert a single Mirascope tool to Anthropic tool format with caching."""
154
170
  schema_dict = tool.parameters.model_dump(by_alias=True, exclude_none=True)
155
171
  schema_dict["type"] = "object"
@@ -164,21 +180,26 @@ def encode_request(
164
180
  *,
165
181
  model_id: AnthropicModelId,
166
182
  messages: Sequence[Message],
167
- tools: Sequence[ToolSchema] | BaseToolkit | None,
183
+ tools: Sequence[AnyToolSchema] | BaseToolkit[AnyToolSchema] | None,
168
184
  format: type[FormattableT] | Format[FormattableT] | None,
169
185
  params: Params,
170
186
  ) -> tuple[Sequence[Message], Format[FormattableT] | None, MessageCreateKwargs]:
171
187
  """Prepares a request for the `Anthropic.messages.create` method."""
188
+ if not model_id.startswith("anthropic/"): # pragma: no cover
189
+ raise ValueError(
190
+ f"Model ID must start with 'anthropic/' prefix, got: {model_id}"
191
+ )
192
+
172
193
  kwargs: MessageCreateKwargs = MessageCreateKwargs(
173
194
  {
174
- "model": model_id,
195
+ "model": model_name(model_id),
175
196
  "max_tokens": DEFAULT_MAX_TOKENS,
176
197
  }
177
198
  )
178
199
  encode_thoughts = False
179
200
 
180
201
  with _base_utils.ensure_all_params_accessed(
181
- params=params, provider="anthropic", unsupported_params=["seed"]
202
+ params=params, provider_id="anthropic", unsupported_params=["seed"]
182
203
  ) as param_accessor:
183
204
  if param_accessor.temperature is not None:
184
205
  kwargs["temperature"] = param_accessor.temperature
@@ -206,7 +227,7 @@ def encode_request(
206
227
  if format is not None:
207
228
  if format.mode == "strict":
208
229
  raise FormattingModeNotSupportedError(
209
- formatting_mode="strict", provider="anthropic"
230
+ formatting_mode="strict", provider_id="anthropic"
210
231
  )
211
232
  elif format.mode == "tool":
212
233
  format_tool_schema = _formatting_utils.create_tool_schema(format)
@@ -0,0 +1,40 @@
1
+ """Anthropic registered LLM models."""
2
+
3
+ from typing import Literal, TypeAlias
4
+
5
+ AnthropicModelId: TypeAlias = (
6
+ Literal[
7
+ "anthropic/claude-3-7-sonnet-latest",
8
+ "anthropic/claude-3-7-sonnet-20250219",
9
+ "anthropic/claude-3-5-haiku-latest",
10
+ "anthropic/claude-3-5-haiku-20241022",
11
+ "anthropic/claude-haiku-4-5",
12
+ "anthropic/claude-haiku-4-5-20251001",
13
+ "anthropic/claude-sonnet-4-20250514",
14
+ "anthropic/claude-sonnet-4-0",
15
+ "anthropic/claude-4-sonnet-20250514",
16
+ "anthropic/claude-sonnet-4-5",
17
+ "anthropic/claude-sonnet-4-5-20250929",
18
+ "anthropic/claude-opus-4-0",
19
+ "anthropic/claude-opus-4-20250514",
20
+ "anthropic/claude-4-opus-20250514",
21
+ "anthropic/claude-opus-4-1-20250805",
22
+ "anthropic/claude-3-opus-latest",
23
+ "anthropic/claude-3-opus-20240229",
24
+ "anthropic/claude-3-haiku-20240307",
25
+ ]
26
+ | str
27
+ )
28
+ """The Anthropic model ids registered with Mirascope."""
29
+
30
+
31
+ def model_name(model_id: AnthropicModelId) -> str:
32
+ """Extract the anthropic model name from the ModelId
33
+
34
+ Args:
35
+ model_id: Full model ID (e.g. "anthropic/claude-sonnet-4-5")
36
+
37
+ Returns:
38
+ Provider-specific model ID (e.g. "claude-sonnet-4-5")
39
+ """
40
+ return model_id.removeprefix("anthropic/")