mirascope 2.0.0a2__py3-none-any.whl → 2.0.0a4__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 +141 -0
- mirascope/api/_generated/client.py +163 -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 +17 -0
- mirascope/api/_generated/errors/bad_request_error.py +15 -0
- mirascope/api/_generated/errors/conflict_error.py +15 -0
- mirascope/api/_generated/errors/forbidden_error.py +15 -0
- mirascope/api/_generated/errors/internal_server_error.py +15 -0
- mirascope/api/_generated/errors/not_found_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/organizations/__init__.py +25 -0
- mirascope/api/_generated/organizations/client.py +380 -0
- mirascope/api/_generated/organizations/raw_client.py +876 -0
- mirascope/api/_generated/organizations/types/__init__.py +23 -0
- mirascope/api/_generated/organizations/types/organizations_create_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_create_response_role.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_get_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_get_response_role.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_list_response_item.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_list_response_item_role.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_update_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_update_response_role.py +7 -0
- mirascope/api/_generated/projects/__init__.py +17 -0
- mirascope/api/_generated/projects/client.py +458 -0
- mirascope/api/_generated/projects/raw_client.py +1016 -0
- mirascope/api/_generated/projects/types/__init__.py +15 -0
- mirascope/api/_generated/projects/types/projects_create_response.py +30 -0
- mirascope/api/_generated/projects/types/projects_get_response.py +30 -0
- mirascope/api/_generated/projects/types/projects_list_response_item.py +30 -0
- mirascope/api/_generated/projects/types/projects_update_response.py +30 -0
- mirascope/api/_generated/reference.md +753 -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 +37 -0
- mirascope/api/_generated/types/already_exists_error.py +24 -0
- mirascope/api/_generated/types/already_exists_error_tag.py +5 -0
- mirascope/api/_generated/types/database_error.py +24 -0
- mirascope/api/_generated/types/database_error_tag.py +5 -0
- mirascope/api/_generated/types/http_api_decode_error.py +29 -0
- mirascope/api/_generated/types/http_api_decode_error_tag.py +5 -0
- mirascope/api/_generated/types/issue.py +40 -0
- mirascope/api/_generated/types/issue_tag.py +17 -0
- mirascope/api/_generated/types/not_found_error_body.py +24 -0
- mirascope/api/_generated/types/not_found_error_tag.py +5 -0
- mirascope/api/_generated/types/permission_denied_error.py +24 -0
- mirascope/api/_generated/types/permission_denied_error_tag.py +7 -0
- mirascope/api/_generated/types/property_key.py +7 -0
- mirascope/api/_generated/types/property_key_key.py +27 -0
- mirascope/api/_generated/types/property_key_key_tag.py +5 -0
- mirascope/api/client.py +255 -0
- mirascope/api/settings.py +81 -0
- mirascope/llm/__init__.py +45 -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 +44 -0
- mirascope/llm/{clients → providers}/_missing_import_stubs.py +8 -6
- mirascope/llm/providers/anthropic/__init__.py +29 -0
- mirascope/llm/providers/anthropic/_utils/__init__.py +23 -0
- mirascope/llm/providers/anthropic/_utils/beta_decode.py +271 -0
- mirascope/llm/providers/anthropic/_utils/beta_encode.py +216 -0
- mirascope/llm/{clients → providers}/anthropic/_utils/decode.py +44 -11
- mirascope/llm/providers/anthropic/_utils/encode.py +356 -0
- mirascope/llm/providers/anthropic/beta_provider.py +322 -0
- mirascope/llm/providers/anthropic/model_id.py +23 -0
- mirascope/llm/providers/anthropic/model_info.py +87 -0
- mirascope/llm/providers/anthropic/provider.py +416 -0
- mirascope/llm/{clients → providers}/base/__init__.py +3 -3
- mirascope/llm/{clients → providers}/base/_utils.py +25 -8
- 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 +61 -7
- mirascope/llm/{clients → providers}/google/_utils/encode.py +44 -30
- mirascope/llm/providers/google/model_id.py +22 -0
- mirascope/llm/providers/google/model_info.py +62 -0
- mirascope/llm/providers/google/provider.py +442 -0
- mirascope/llm/providers/load_provider.py +54 -0
- mirascope/llm/providers/mlx/__init__.py +24 -0
- mirascope/llm/providers/mlx/_utils.py +129 -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 +147 -0
- mirascope/llm/providers/mlx/mlx.py +237 -0
- mirascope/llm/providers/mlx/model_id.py +17 -0
- mirascope/llm/providers/mlx/provider.py +415 -0
- mirascope/llm/providers/model_id.py +16 -0
- mirascope/llm/providers/ollama/__init__.py +19 -0
- mirascope/llm/providers/ollama/provider.py +71 -0
- mirascope/llm/providers/openai/__init__.py +6 -0
- mirascope/llm/providers/openai/completions/__init__.py +25 -0
- mirascope/llm/{clients → providers}/openai/completions/_utils/__init__.py +2 -0
- mirascope/llm/{clients → providers}/openai/completions/_utils/decode.py +60 -6
- mirascope/llm/{clients → providers}/openai/completions/_utils/encode.py +37 -26
- mirascope/llm/providers/openai/completions/base_provider.py +513 -0
- mirascope/llm/providers/openai/completions/provider.py +22 -0
- mirascope/llm/providers/openai/model_id.py +31 -0
- mirascope/llm/providers/openai/model_info.py +303 -0
- mirascope/llm/providers/openai/provider.py +398 -0
- mirascope/llm/providers/openai/responses/__init__.py +21 -0
- mirascope/llm/{clients → providers}/openai/responses/_utils/decode.py +59 -6
- mirascope/llm/{clients → providers}/openai/responses/_utils/encode.py +34 -23
- mirascope/llm/providers/openai/responses/provider.py +469 -0
- mirascope/llm/providers/provider_id.py +23 -0
- mirascope/llm/providers/provider_registry.py +169 -0
- mirascope/llm/providers/together/__init__.py +19 -0
- mirascope/llm/providers/together/provider.py +40 -0
- mirascope/llm/responses/__init__.py +3 -0
- mirascope/llm/responses/base_response.py +14 -5
- mirascope/llm/responses/base_stream_response.py +35 -6
- mirascope/llm/responses/finish_reason.py +1 -0
- mirascope/llm/responses/response.py +33 -13
- mirascope/llm/responses/root_response.py +12 -13
- mirascope/llm/responses/stream_response.py +35 -23
- mirascope/llm/responses/usage.py +95 -0
- mirascope/llm/tools/__init__.py +9 -2
- mirascope/llm/tools/_utils.py +12 -3
- mirascope/llm/tools/protocols.py +4 -4
- mirascope/llm/tools/tool_schema.py +44 -9
- mirascope/llm/tools/tools.py +10 -9
- 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.0a2.dist-info → mirascope-2.0.0a4.dist-info}/METADATA +78 -3
- mirascope-2.0.0a4.dist-info/RECORD +247 -0
- {mirascope-2.0.0a2.dist-info → mirascope-2.0.0a4.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/_utils/encode.py +0 -243
- mirascope/llm/clients/anthropic/clients.py +0 -819
- 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/__init__.py +0 -13
- 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/openai/shared/__init__.py +0 -7
- mirascope/llm/clients/openai/shared/_utils.py +0 -55
- mirascope/llm/clients/providers.py +0 -175
- mirascope-2.0.0a2.dist-info/RECORD +0 -102
- /mirascope/llm/{clients → providers}/base/kwargs.py +0 -0
- /mirascope/llm/{clients → providers}/base/params.py +0 -0
- /mirascope/llm/{clients/anthropic → providers/google}/_utils/__init__.py +0 -0
- /mirascope/llm/{clients → providers}/google/message.py +0 -0
- /mirascope/llm/{clients/google → providers/openai/responses}/_utils/__init__.py +0 -0
- {mirascope-2.0.0a2.dist-info → mirascope-2.0.0a4.dist-info}/licenses/LICENSE +0 -0
mirascope/llm/exceptions.py
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"""Mirascope exception hierarchy for unified error handling across providers."""
|
|
1
|
+
"""Mirascope llm exception hierarchy for unified error handling across providers."""
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING
|
|
4
4
|
|
|
5
5
|
if TYPE_CHECKING:
|
|
6
|
-
from .clients import ModelId, Provider
|
|
7
6
|
from .formatting import FormattingMode
|
|
7
|
+
from .providers import ModelId, ProviderId
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class
|
|
11
|
-
"""Base exception for all Mirascope errors."""
|
|
10
|
+
class MirascopeLLMError(Exception):
|
|
11
|
+
"""Base exception for all Mirascope LLM errors."""
|
|
12
12
|
|
|
13
13
|
original_exception: Exception | None
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
class APIError(
|
|
16
|
+
class APIError(MirascopeLLMError):
|
|
17
17
|
"""Base class for API-related errors."""
|
|
18
18
|
|
|
19
19
|
status_code: int | None
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
class ConnectionError(
|
|
22
|
+
class ConnectionError(MirascopeLLMError):
|
|
23
23
|
"""Raised when unable to connect to the API (network issues, timeouts)."""
|
|
24
24
|
|
|
25
25
|
|
|
@@ -39,33 +39,33 @@ class NotFoundError(APIError):
|
|
|
39
39
|
"""Raised when requested resource is not found (404)."""
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
class ToolNotFoundError(
|
|
42
|
+
class ToolNotFoundError(MirascopeLLMError):
|
|
43
43
|
"""Raised if a tool_call cannot be converted to any corresponding tool."""
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
class FeatureNotSupportedError(
|
|
46
|
+
class FeatureNotSupportedError(MirascopeLLMError):
|
|
47
47
|
"""Raised if a Mirascope feature is unsupported by chosen provider.
|
|
48
48
|
|
|
49
49
|
If compatibility is model-specific, then `model_id` should be specified.
|
|
50
50
|
If the feature is not supported by the provider at all, then it may be `None`."""
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
provider_id: "ProviderId"
|
|
53
53
|
model_id: "ModelId | None"
|
|
54
54
|
feature: str
|
|
55
55
|
|
|
56
56
|
def __init__(
|
|
57
57
|
self,
|
|
58
58
|
feature: str,
|
|
59
|
-
|
|
59
|
+
provider_id: "ProviderId",
|
|
60
60
|
model_id: "ModelId | None" = None,
|
|
61
61
|
message: str | None = None,
|
|
62
62
|
) -> None:
|
|
63
63
|
if message is None:
|
|
64
64
|
model_msg = f" for model '{model_id}'" if model_id is not None else ""
|
|
65
|
-
message = f"Feature '{feature}' is not supported by provider '{
|
|
65
|
+
message = f"Feature '{feature}' is not supported by provider '{provider_id}'{model_msg}"
|
|
66
66
|
super().__init__(message)
|
|
67
67
|
self.feature = feature
|
|
68
|
-
self.
|
|
68
|
+
self.provider_id = provider_id
|
|
69
69
|
self.model_id = model_id
|
|
70
70
|
|
|
71
71
|
|
|
@@ -77,16 +77,16 @@ class FormattingModeNotSupportedError(FeatureNotSupportedError):
|
|
|
77
77
|
def __init__(
|
|
78
78
|
self,
|
|
79
79
|
formatting_mode: "FormattingMode",
|
|
80
|
-
|
|
80
|
+
provider_id: "ProviderId",
|
|
81
81
|
model_id: "ModelId | None" = None,
|
|
82
82
|
message: str | None = None,
|
|
83
83
|
) -> None:
|
|
84
84
|
if message is None:
|
|
85
85
|
model_msg = f" for model '{model_id}'" if model_id is not None else ""
|
|
86
|
-
message = f"Formatting mode '{formatting_mode}' is not supported by provider '{
|
|
86
|
+
message = f"Formatting mode '{formatting_mode}' is not supported by provider '{provider_id}'{model_msg}"
|
|
87
87
|
super().__init__(
|
|
88
88
|
feature=f"formatting_mode:{formatting_mode}",
|
|
89
|
-
|
|
89
|
+
provider_id=provider_id,
|
|
90
90
|
model_id=model_id,
|
|
91
91
|
message=message,
|
|
92
92
|
)
|
|
@@ -101,5 +101,19 @@ class ServerError(APIError):
|
|
|
101
101
|
"""Raised for server-side errors (500+)."""
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
class TimeoutError(
|
|
104
|
+
class TimeoutError(MirascopeLLMError):
|
|
105
105
|
"""Raised when requests timeout or deadline exceeded."""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class NoRegisteredProviderError(MirascopeLLMError):
|
|
109
|
+
"""Raised when no provider is registered for a given model_id."""
|
|
110
|
+
|
|
111
|
+
model_id: str
|
|
112
|
+
|
|
113
|
+
def __init__(self, model_id: str) -> None:
|
|
114
|
+
message = (
|
|
115
|
+
f"No provider registered for model '{model_id}'. "
|
|
116
|
+
f"Use llm.register_provider() to register a provider for this model."
|
|
117
|
+
)
|
|
118
|
+
super().__init__(message)
|
|
119
|
+
self.model_id = model_id
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
4
|
import json
|
|
5
|
+
from typing import Any, cast
|
|
5
6
|
|
|
6
|
-
from ..tools import FORMAT_TOOL_NAME, ToolParameterSchema, ToolSchema
|
|
7
|
+
from ..tools import FORMAT_TOOL_NAME, ToolFn, ToolParameterSchema, ToolSchema
|
|
7
8
|
from .types import Format, FormattableT, FormattingMode
|
|
8
9
|
|
|
9
10
|
TOOL_MODE_INSTRUCTIONS = f"""Always respond to the user's query using the {FORMAT_TOOL_NAME} tool for structured output."""
|
|
@@ -27,7 +28,9 @@ def default_formatting_instructions(
|
|
|
27
28
|
return inspect.cleandoc(instructions)
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
def create_tool_schema(
|
|
31
|
+
def create_tool_schema(
|
|
32
|
+
format: Format[FormattableT],
|
|
33
|
+
) -> ToolSchema[ToolFn[..., None]]:
|
|
31
34
|
"""Convert a `Format` to a `ToolSchema` for format parsing.
|
|
32
35
|
|
|
33
36
|
Args:
|
|
@@ -37,13 +40,14 @@ def create_tool_schema(format: Format[FormattableT]) -> ToolSchema:
|
|
|
37
40
|
`ToolSchema` for the format tool
|
|
38
41
|
"""
|
|
39
42
|
|
|
40
|
-
schema_dict = format.schema.copy()
|
|
43
|
+
schema_dict: dict[str, Any] = format.schema.copy()
|
|
41
44
|
schema_dict["type"] = "object"
|
|
42
45
|
|
|
43
46
|
properties = schema_dict.get("properties")
|
|
44
47
|
if not properties or not isinstance(properties, dict):
|
|
45
48
|
properties = {} # pragma: no cover
|
|
46
|
-
|
|
49
|
+
properties = cast(dict[str, Any], properties)
|
|
50
|
+
required: list[str] = list(properties.keys())
|
|
47
51
|
|
|
48
52
|
description = (
|
|
49
53
|
f"Use this tool to extract data in {format.name} format for a final response."
|
|
@@ -64,7 +68,7 @@ def create_tool_schema(format: Format[FormattableT]) -> ToolSchema:
|
|
|
64
68
|
"Format tool function should not be called."
|
|
65
69
|
) # pragma: no cover
|
|
66
70
|
|
|
67
|
-
tool_schema = ToolSchema.__new__(ToolSchema)
|
|
71
|
+
tool_schema = cast(ToolSchema[ToolFn[..., None]], ToolSchema.__new__(ToolSchema))
|
|
68
72
|
tool_schema.fn = _unused_format_fn
|
|
69
73
|
tool_schema.name = FORMAT_TOOL_NAME
|
|
70
74
|
tool_schema.description = description
|
|
@@ -10,7 +10,7 @@ from ..content import AssistantContentPart, Text, UserContentPart
|
|
|
10
10
|
from ..types import Jsonable
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
|
-
from ..
|
|
13
|
+
from ..providers import ModelId, ProviderId
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
@dataclass(kw_only=True)
|
|
@@ -51,12 +51,15 @@ class AssistantMessage:
|
|
|
51
51
|
name: str | None = None
|
|
52
52
|
"""A name identifying the creator of this message."""
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
provider_id: ProviderId | None
|
|
55
55
|
"""The LLM provider that generated this assistant message, if available."""
|
|
56
56
|
|
|
57
57
|
model_id: ModelId | None
|
|
58
58
|
"""The model identifier of the LLM that generated this assistant message, if available."""
|
|
59
59
|
|
|
60
|
+
provider_model_name: str | None
|
|
61
|
+
"""The provider-specific model identifier (e.g. "gpt-5:responses"), if available."""
|
|
62
|
+
|
|
60
63
|
raw_message: Jsonable | None
|
|
61
64
|
"""The provider-specific raw representation of this assistant message, if available.
|
|
62
65
|
|
|
@@ -149,8 +152,9 @@ def user(
|
|
|
149
152
|
def assistant(
|
|
150
153
|
content: AssistantContent,
|
|
151
154
|
*,
|
|
152
|
-
provider: Provider | None,
|
|
153
155
|
model_id: ModelId | None,
|
|
156
|
+
provider_id: ProviderId | None,
|
|
157
|
+
provider_model_name: str | None = None,
|
|
154
158
|
raw_message: Jsonable | None = None,
|
|
155
159
|
name: str | None = None,
|
|
156
160
|
) -> AssistantMessage:
|
|
@@ -159,8 +163,10 @@ def assistant(
|
|
|
159
163
|
Args:
|
|
160
164
|
content: The content of the message, which can be `str` or any `AssistantContent`,
|
|
161
165
|
or a sequence of assistant content pieces.
|
|
162
|
-
provider: Optional identifier of the provider that produced this message.
|
|
163
166
|
model_id: Optional id of the model that produced this message.
|
|
167
|
+
provider_id: Optional identifier of the provider that produced this message.
|
|
168
|
+
provider_model_name: Optional provider-specific model name. May include
|
|
169
|
+
provider-specific additional info (like api mode in "gpt-5:responses").
|
|
164
170
|
raw_message: Optional Jsonable object that contains the provider-specific
|
|
165
171
|
"raw" data representation of the content for this assistant message.
|
|
166
172
|
name: Optional name to identify a specific assistant in multi-party conversations.
|
|
@@ -168,6 +174,7 @@ def assistant(
|
|
|
168
174
|
Returns:
|
|
169
175
|
An `AssistantMessage`.
|
|
170
176
|
"""
|
|
177
|
+
|
|
171
178
|
if isinstance(content, str) or not isinstance(content, Sequence):
|
|
172
179
|
content = [content]
|
|
173
180
|
promoted_content = [
|
|
@@ -175,8 +182,9 @@ def assistant(
|
|
|
175
182
|
]
|
|
176
183
|
return AssistantMessage(
|
|
177
184
|
content=promoted_content,
|
|
178
|
-
|
|
185
|
+
provider_id=provider_id,
|
|
179
186
|
model_id=model_id,
|
|
187
|
+
provider_model_name=provider_model_name,
|
|
180
188
|
raw_message=raw_message,
|
|
181
189
|
name=name,
|
|
182
190
|
)
|
mirascope/llm/models/__init__.py
CHANGED
|
@@ -6,11 +6,11 @@ the model at runtime, and `llm.use_model()` retrieves the model from context or
|
|
|
6
6
|
creates a default one.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
from .models import Model,
|
|
9
|
+
from .models import Model, model, model_from_context, use_model
|
|
10
10
|
|
|
11
11
|
__all__ = [
|
|
12
12
|
"Model",
|
|
13
|
-
"get_model_from_context",
|
|
14
13
|
"model",
|
|
14
|
+
"model_from_context",
|
|
15
15
|
"use_model",
|
|
16
16
|
]
|