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.
- mirascope/__init__.py +2 -2
- mirascope/api/__init__.py +6 -0
- mirascope/api/_generated/README.md +207 -0
- mirascope/api/_generated/__init__.py +85 -0
- mirascope/api/_generated/client.py +155 -0
- mirascope/api/_generated/core/__init__.py +52 -0
- mirascope/api/_generated/core/api_error.py +23 -0
- mirascope/api/_generated/core/client_wrapper.py +58 -0
- mirascope/api/_generated/core/datetime_utils.py +30 -0
- mirascope/api/_generated/core/file.py +70 -0
- mirascope/api/_generated/core/force_multipart.py +16 -0
- mirascope/api/_generated/core/http_client.py +619 -0
- mirascope/api/_generated/core/http_response.py +55 -0
- mirascope/api/_generated/core/jsonable_encoder.py +102 -0
- mirascope/api/_generated/core/pydantic_utilities.py +310 -0
- mirascope/api/_generated/core/query_encoder.py +60 -0
- mirascope/api/_generated/core/remove_none_from_dict.py +11 -0
- mirascope/api/_generated/core/request_options.py +35 -0
- mirascope/api/_generated/core/serialization.py +282 -0
- mirascope/api/_generated/docs/__init__.py +4 -0
- mirascope/api/_generated/docs/client.py +95 -0
- mirascope/api/_generated/docs/raw_client.py +132 -0
- mirascope/api/_generated/environment.py +9 -0
- mirascope/api/_generated/errors/__init__.py +7 -0
- mirascope/api/_generated/errors/bad_request_error.py +15 -0
- mirascope/api/_generated/health/__init__.py +7 -0
- mirascope/api/_generated/health/client.py +96 -0
- mirascope/api/_generated/health/raw_client.py +129 -0
- mirascope/api/_generated/health/types/__init__.py +8 -0
- mirascope/api/_generated/health/types/health_check_response.py +24 -0
- mirascope/api/_generated/health/types/health_check_response_status.py +5 -0
- mirascope/api/_generated/reference.md +167 -0
- mirascope/api/_generated/traces/__init__.py +55 -0
- mirascope/api/_generated/traces/client.py +162 -0
- mirascope/api/_generated/traces/raw_client.py +168 -0
- mirascope/api/_generated/traces/types/__init__.py +95 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item.py +36 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource.py +31 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item.py +25 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value.py +54 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_array_value.py +23 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value.py +28 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_resource_attributes_item_value_kvlist_value_values_item.py +24 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item.py +35 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope.py +35 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item.py +27 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value.py +54 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_array_value.py +23 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_scope_attributes_item_value_kvlist_value.py +28 -0
- 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
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item.py +60 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item.py +29 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value.py +54 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_array_value.py +23 -0
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_attributes_item_value_kvlist_value.py +28 -0
- 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
- mirascope/api/_generated/traces/types/traces_create_request_resource_spans_item_scope_spans_item_spans_item_status.py +24 -0
- mirascope/api/_generated/traces/types/traces_create_response.py +27 -0
- mirascope/api/_generated/traces/types/traces_create_response_partial_success.py +28 -0
- mirascope/api/_generated/types/__init__.py +21 -0
- mirascope/api/_generated/types/http_api_decode_error.py +31 -0
- mirascope/api/_generated/types/http_api_decode_error_tag.py +5 -0
- mirascope/api/_generated/types/issue.py +44 -0
- mirascope/api/_generated/types/issue_tag.py +17 -0
- mirascope/api/_generated/types/property_key.py +7 -0
- mirascope/api/_generated/types/property_key_tag.py +29 -0
- mirascope/api/_generated/types/property_key_tag_tag.py +5 -0
- mirascope/api/client.py +255 -0
- mirascope/api/settings.py +81 -0
- mirascope/llm/__init__.py +41 -11
- mirascope/llm/calls/calls.py +81 -57
- mirascope/llm/calls/decorator.py +121 -115
- mirascope/llm/content/__init__.py +3 -2
- mirascope/llm/context/_utils.py +19 -6
- mirascope/llm/exceptions.py +30 -16
- mirascope/llm/formatting/_utils.py +9 -5
- mirascope/llm/formatting/format.py +2 -2
- mirascope/llm/formatting/from_call_args.py +2 -2
- mirascope/llm/messages/message.py +13 -5
- mirascope/llm/models/__init__.py +2 -2
- mirascope/llm/models/models.py +189 -81
- mirascope/llm/prompts/__init__.py +13 -12
- mirascope/llm/prompts/_utils.py +27 -24
- mirascope/llm/prompts/decorator.py +133 -204
- mirascope/llm/prompts/prompts.py +424 -0
- mirascope/llm/prompts/protocols.py +25 -59
- mirascope/llm/providers/__init__.py +38 -0
- mirascope/llm/{clients → providers}/_missing_import_stubs.py +8 -6
- mirascope/llm/providers/anthropic/__init__.py +24 -0
- mirascope/llm/{clients → providers}/anthropic/_utils/decode.py +5 -4
- mirascope/llm/{clients → providers}/anthropic/_utils/encode.py +31 -10
- mirascope/llm/providers/anthropic/model_id.py +40 -0
- mirascope/llm/{clients/anthropic/clients.py → providers/anthropic/provider.py} +33 -418
- mirascope/llm/{clients → providers}/base/__init__.py +3 -3
- mirascope/llm/{clients → providers}/base/_utils.py +10 -7
- mirascope/llm/{clients/base/client.py → providers/base/base_provider.py} +255 -126
- mirascope/llm/providers/google/__init__.py +21 -0
- mirascope/llm/{clients → providers}/google/_utils/decode.py +6 -4
- mirascope/llm/{clients → providers}/google/_utils/encode.py +30 -24
- mirascope/llm/providers/google/model_id.py +28 -0
- mirascope/llm/providers/google/provider.py +438 -0
- mirascope/llm/providers/load_provider.py +48 -0
- mirascope/llm/providers/mlx/__init__.py +24 -0
- mirascope/llm/providers/mlx/_utils.py +107 -0
- mirascope/llm/providers/mlx/encoding/__init__.py +8 -0
- mirascope/llm/providers/mlx/encoding/base.py +69 -0
- mirascope/llm/providers/mlx/encoding/transformers.py +131 -0
- mirascope/llm/providers/mlx/mlx.py +237 -0
- mirascope/llm/providers/mlx/model_id.py +17 -0
- mirascope/llm/providers/mlx/provider.py +411 -0
- mirascope/llm/providers/model_id.py +16 -0
- mirascope/llm/providers/openai/__init__.py +6 -0
- mirascope/llm/providers/openai/completions/__init__.py +20 -0
- mirascope/llm/{clients/openai/responses → providers/openai/completions}/_utils/__init__.py +2 -0
- mirascope/llm/{clients → providers}/openai/completions/_utils/decode.py +5 -3
- mirascope/llm/{clients → providers}/openai/completions/_utils/encode.py +33 -23
- mirascope/llm/providers/openai/completions/provider.py +456 -0
- mirascope/llm/providers/openai/model_id.py +31 -0
- mirascope/llm/providers/openai/model_info.py +246 -0
- mirascope/llm/providers/openai/provider.py +386 -0
- mirascope/llm/providers/openai/responses/__init__.py +21 -0
- mirascope/llm/{clients → providers}/openai/responses/_utils/decode.py +5 -3
- mirascope/llm/{clients → providers}/openai/responses/_utils/encode.py +28 -17
- mirascope/llm/providers/openai/responses/provider.py +470 -0
- mirascope/llm/{clients → providers}/openai/shared/_utils.py +7 -3
- mirascope/llm/providers/provider_id.py +13 -0
- mirascope/llm/providers/provider_registry.py +167 -0
- mirascope/llm/responses/base_response.py +10 -5
- mirascope/llm/responses/base_stream_response.py +10 -5
- mirascope/llm/responses/response.py +24 -13
- mirascope/llm/responses/root_response.py +7 -12
- mirascope/llm/responses/stream_response.py +35 -23
- mirascope/llm/tools/__init__.py +9 -2
- mirascope/llm/tools/_utils.py +12 -3
- mirascope/llm/tools/decorator.py +10 -10
- mirascope/llm/tools/protocols.py +4 -4
- mirascope/llm/tools/tool_schema.py +44 -9
- mirascope/llm/tools/tools.py +12 -11
- mirascope/ops/__init__.py +156 -0
- mirascope/ops/_internal/__init__.py +5 -0
- mirascope/ops/_internal/closure.py +1118 -0
- mirascope/ops/_internal/configuration.py +126 -0
- mirascope/ops/_internal/context.py +76 -0
- mirascope/ops/_internal/exporters/__init__.py +26 -0
- mirascope/ops/_internal/exporters/exporters.py +342 -0
- mirascope/ops/_internal/exporters/processors.py +104 -0
- mirascope/ops/_internal/exporters/types.py +165 -0
- mirascope/ops/_internal/exporters/utils.py +29 -0
- mirascope/ops/_internal/instrumentation/__init__.py +8 -0
- mirascope/ops/_internal/instrumentation/llm/__init__.py +8 -0
- mirascope/ops/_internal/instrumentation/llm/encode.py +238 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/__init__.py +38 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_input_messages.py +31 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_output_messages.py +38 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/gen_ai_system_instructions.py +18 -0
- mirascope/ops/_internal/instrumentation/llm/gen_ai_types/shared.py +100 -0
- mirascope/ops/_internal/instrumentation/llm/llm.py +1288 -0
- mirascope/ops/_internal/propagation.py +198 -0
- mirascope/ops/_internal/protocols.py +51 -0
- mirascope/ops/_internal/session.py +139 -0
- mirascope/ops/_internal/spans.py +232 -0
- mirascope/ops/_internal/traced_calls.py +371 -0
- mirascope/ops/_internal/traced_functions.py +394 -0
- mirascope/ops/_internal/tracing.py +276 -0
- mirascope/ops/_internal/types.py +13 -0
- mirascope/ops/_internal/utils.py +75 -0
- mirascope/ops/_internal/versioned_calls.py +512 -0
- mirascope/ops/_internal/versioned_functions.py +346 -0
- mirascope/ops/_internal/versioning.py +303 -0
- mirascope/ops/exceptions.py +21 -0
- {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/METADATA +77 -1
- mirascope-2.0.0a3.dist-info/RECORD +206 -0
- {mirascope-2.0.0a1.dist-info → mirascope-2.0.0a3.dist-info}/WHEEL +1 -1
- mirascope/graphs/__init__.py +0 -22
- mirascope/graphs/finite_state_machine.py +0 -625
- mirascope/llm/agents/__init__.py +0 -15
- mirascope/llm/agents/agent.py +0 -97
- mirascope/llm/agents/agent_template.py +0 -45
- mirascope/llm/agents/decorator.py +0 -176
- mirascope/llm/calls/base_call.py +0 -33
- mirascope/llm/clients/__init__.py +0 -34
- mirascope/llm/clients/anthropic/__init__.py +0 -25
- mirascope/llm/clients/anthropic/model_ids.py +0 -8
- mirascope/llm/clients/google/__init__.py +0 -20
- mirascope/llm/clients/google/clients.py +0 -853
- mirascope/llm/clients/google/model_ids.py +0 -15
- mirascope/llm/clients/openai/__init__.py +0 -25
- mirascope/llm/clients/openai/completions/__init__.py +0 -28
- mirascope/llm/clients/openai/completions/_utils/model_features.py +0 -81
- mirascope/llm/clients/openai/completions/clients.py +0 -833
- mirascope/llm/clients/openai/completions/model_ids.py +0 -8
- mirascope/llm/clients/openai/responses/__init__.py +0 -26
- mirascope/llm/clients/openai/responses/_utils/model_features.py +0 -87
- mirascope/llm/clients/openai/responses/clients.py +0 -832
- mirascope/llm/clients/openai/responses/model_ids.py +0 -8
- mirascope/llm/clients/providers.py +0 -175
- mirascope-2.0.0a1.dist-info/RECORD +0 -102
- /mirascope/llm/{clients → providers}/anthropic/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/base/kwargs.py +0 -0
- /mirascope/llm/{clients → providers}/base/params.py +0 -0
- /mirascope/llm/{clients → providers}/google/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/google/message.py +0 -0
- /mirascope/llm/{clients/openai/completions → providers/openai/responses}/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/openai/shared/__init__.py +0 -0
- {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,
|
|
20
|
+
from ....tools import FORMAT_TOOL_NAME, AnyToolSchema, BaseToolkit
|
|
21
21
|
from ...base import Params, _utils as _base_utils
|
|
22
|
-
from ..
|
|
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}",
|
|
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
|
-
|
|
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.
|
|
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:
|
|
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[
|
|
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,
|
|
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",
|
|
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/")
|