mirascope 2.0.0a6__py3-none-any.whl → 2.0.1__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/api/_generated/__init__.py +186 -5
- mirascope/api/_generated/annotations/client.py +38 -6
- mirascope/api/_generated/annotations/raw_client.py +366 -47
- mirascope/api/_generated/annotations/types/annotations_create_response.py +19 -6
- mirascope/api/_generated/annotations/types/annotations_get_response.py +19 -6
- mirascope/api/_generated/annotations/types/annotations_list_response_annotations_item.py +22 -7
- mirascope/api/_generated/annotations/types/annotations_update_response.py +19 -6
- mirascope/api/_generated/api_keys/__init__.py +12 -2
- mirascope/api/_generated/api_keys/client.py +107 -6
- mirascope/api/_generated/api_keys/raw_client.py +486 -38
- mirascope/api/_generated/api_keys/types/__init__.py +7 -1
- mirascope/api/_generated/api_keys/types/api_keys_list_all_for_org_response_item.py +40 -0
- mirascope/api/_generated/client.py +36 -0
- mirascope/api/_generated/docs/raw_client.py +71 -9
- mirascope/api/_generated/environment.py +3 -3
- mirascope/api/_generated/environments/__init__.py +6 -0
- mirascope/api/_generated/environments/client.py +158 -9
- mirascope/api/_generated/environments/raw_client.py +620 -52
- mirascope/api/_generated/environments/types/__init__.py +10 -0
- mirascope/api/_generated/environments/types/environments_get_analytics_response.py +60 -0
- mirascope/api/_generated/environments/types/environments_get_analytics_response_top_functions_item.py +24 -0
- mirascope/api/_generated/{organizations/types/organizations_credits_response.py → environments/types/environments_get_analytics_response_top_models_item.py} +6 -3
- mirascope/api/_generated/errors/__init__.py +6 -0
- mirascope/api/_generated/errors/bad_request_error.py +5 -2
- mirascope/api/_generated/errors/conflict_error.py +5 -2
- mirascope/api/_generated/errors/payment_required_error.py +15 -0
- mirascope/api/_generated/errors/service_unavailable_error.py +14 -0
- mirascope/api/_generated/errors/too_many_requests_error.py +15 -0
- mirascope/api/_generated/functions/__init__.py +10 -0
- mirascope/api/_generated/functions/client.py +222 -8
- mirascope/api/_generated/functions/raw_client.py +975 -134
- mirascope/api/_generated/functions/types/__init__.py +28 -4
- mirascope/api/_generated/functions/types/functions_get_by_env_response.py +53 -0
- mirascope/api/_generated/functions/types/functions_get_by_env_response_dependencies_value.py +22 -0
- mirascope/api/_generated/functions/types/functions_list_by_env_response.py +25 -0
- mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item.py +56 -0
- mirascope/api/_generated/functions/types/functions_list_by_env_response_functions_item_dependencies_value.py +22 -0
- mirascope/api/_generated/health/raw_client.py +74 -10
- mirascope/api/_generated/organization_invitations/__init__.py +33 -0
- mirascope/api/_generated/organization_invitations/client.py +546 -0
- mirascope/api/_generated/organization_invitations/raw_client.py +1519 -0
- mirascope/api/_generated/organization_invitations/types/__init__.py +53 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response.py +34 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_accept_response_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_request_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response.py +48 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_create_response_status.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response.py +48 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_get_response_status.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item.py +48 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_role.py +7 -0
- mirascope/api/_generated/organization_invitations/types/organization_invitations_list_response_item_status.py +7 -0
- mirascope/api/_generated/organization_memberships/__init__.py +19 -0
- mirascope/api/_generated/organization_memberships/client.py +302 -0
- mirascope/api/_generated/organization_memberships/raw_client.py +736 -0
- mirascope/api/_generated/organization_memberships/types/__init__.py +27 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item.py +33 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_list_response_item_role.py +7 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_request_role.py +7 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response.py +31 -0
- mirascope/api/_generated/organization_memberships/types/organization_memberships_update_response_role.py +7 -0
- mirascope/api/_generated/organizations/__init__.py +26 -2
- mirascope/api/_generated/organizations/client.py +442 -20
- mirascope/api/_generated/organizations/raw_client.py +1763 -164
- mirascope/api/_generated/organizations/types/__init__.py +48 -2
- mirascope/api/_generated/organizations/types/organizations_create_payment_intent_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_request_target_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response.py +47 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item.py +33 -0
- mirascope/api/_generated/organizations/types/organizations_preview_subscription_change_response_validation_errors_item_resource.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_router_balance_response.py +24 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response.py +53 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_current_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_payment_method.py +26 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change.py +34 -0
- mirascope/api/_generated/organizations/types/organizations_subscription_response_scheduled_change_target_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_update_subscription_request_target_plan.py +7 -0
- mirascope/api/_generated/organizations/types/organizations_update_subscription_response.py +35 -0
- mirascope/api/_generated/project_memberships/__init__.py +25 -0
- mirascope/api/_generated/project_memberships/client.py +437 -0
- mirascope/api/_generated/project_memberships/raw_client.py +1039 -0
- mirascope/api/_generated/project_memberships/types/__init__.py +29 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_create_request_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_create_response.py +35 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_create_response_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item.py +33 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_list_response_item_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_update_request_role.py +7 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_update_response.py +35 -0
- mirascope/api/_generated/project_memberships/types/project_memberships_update_response_role.py +7 -0
- mirascope/api/_generated/projects/raw_client.py +415 -58
- mirascope/api/_generated/reference.md +2767 -397
- mirascope/api/_generated/tags/__init__.py +19 -0
- mirascope/api/_generated/tags/client.py +504 -0
- mirascope/api/_generated/tags/raw_client.py +1288 -0
- mirascope/api/_generated/tags/types/__init__.py +17 -0
- mirascope/api/_generated/tags/types/tags_create_response.py +41 -0
- mirascope/api/_generated/tags/types/tags_get_response.py +41 -0
- mirascope/api/_generated/tags/types/tags_list_response.py +23 -0
- mirascope/api/_generated/tags/types/tags_list_response_tags_item.py +41 -0
- mirascope/api/_generated/tags/types/tags_update_response.py +41 -0
- mirascope/api/_generated/token_cost/__init__.py +7 -0
- mirascope/api/_generated/token_cost/client.py +160 -0
- mirascope/api/_generated/token_cost/raw_client.py +264 -0
- mirascope/api/_generated/token_cost/types/__init__.py +8 -0
- mirascope/api/_generated/token_cost/types/token_cost_calculate_request_usage.py +54 -0
- mirascope/api/_generated/token_cost/types/token_cost_calculate_response.py +52 -0
- mirascope/api/_generated/traces/__init__.py +20 -0
- mirascope/api/_generated/traces/client.py +543 -0
- mirascope/api/_generated/traces/raw_client.py +1366 -96
- mirascope/api/_generated/traces/types/__init__.py +28 -0
- mirascope/api/_generated/traces/types/traces_get_analytics_summary_response.py +6 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response.py +33 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_by_env_response_spans_item.py +88 -0
- mirascope/api/_generated/traces/types/traces_get_trace_detail_response_spans_item.py +0 -2
- mirascope/api/_generated/traces/types/traces_list_by_function_hash_response.py +25 -0
- mirascope/api/_generated/traces/types/traces_list_by_function_hash_response_traces_item.py +44 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item.py +26 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_attribute_filters_item_operator.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_by.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_request_sort_order.py +7 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_response.py +26 -0
- mirascope/api/_generated/traces/types/traces_search_by_env_response_spans_item.py +50 -0
- mirascope/api/_generated/traces/types/traces_search_response_spans_item.py +10 -1
- mirascope/api/_generated/types/__init__.py +32 -2
- mirascope/api/_generated/types/bad_request_error_body.py +50 -0
- mirascope/api/_generated/types/date.py +3 -0
- mirascope/api/_generated/types/immutable_resource_error.py +22 -0
- mirascope/api/_generated/types/internal_server_error_body.py +3 -3
- mirascope/api/_generated/types/plan_limit_exceeded_error.py +32 -0
- mirascope/api/_generated/types/plan_limit_exceeded_error_tag.py +7 -0
- mirascope/api/_generated/types/pricing_unavailable_error.py +23 -0
- mirascope/api/_generated/types/rate_limit_error.py +31 -0
- mirascope/api/_generated/types/rate_limit_error_tag.py +5 -0
- mirascope/api/_generated/types/service_unavailable_error_body.py +24 -0
- mirascope/api/_generated/types/service_unavailable_error_tag.py +7 -0
- mirascope/api/_generated/types/subscription_past_due_error.py +31 -0
- mirascope/api/_generated/types/subscription_past_due_error_tag.py +7 -0
- mirascope/api/settings.py +19 -1
- mirascope/llm/__init__.py +53 -10
- mirascope/llm/calls/__init__.py +2 -1
- mirascope/llm/calls/calls.py +3 -1
- mirascope/llm/calls/decorator.py +21 -7
- mirascope/llm/content/tool_output.py +22 -5
- mirascope/llm/exceptions.py +284 -71
- mirascope/llm/formatting/__init__.py +17 -0
- mirascope/llm/formatting/format.py +112 -35
- mirascope/llm/formatting/output_parser.py +178 -0
- mirascope/llm/formatting/partial.py +80 -7
- mirascope/llm/formatting/primitives.py +192 -0
- mirascope/llm/formatting/types.py +20 -8
- mirascope/llm/messages/__init__.py +3 -0
- mirascope/llm/messages/_utils.py +34 -0
- mirascope/llm/models/__init__.py +5 -0
- mirascope/llm/models/models.py +137 -69
- mirascope/llm/{providers/base → models}/params.py +7 -57
- mirascope/llm/models/thinking_config.py +61 -0
- mirascope/llm/prompts/_utils.py +0 -32
- mirascope/llm/prompts/decorator.py +16 -5
- mirascope/llm/prompts/prompts.py +131 -68
- mirascope/llm/providers/__init__.py +1 -4
- mirascope/llm/providers/anthropic/_utils/__init__.py +2 -0
- mirascope/llm/providers/anthropic/_utils/beta_decode.py +18 -9
- mirascope/llm/providers/anthropic/_utils/beta_encode.py +62 -13
- mirascope/llm/providers/anthropic/_utils/decode.py +18 -9
- mirascope/llm/providers/anthropic/_utils/encode.py +26 -7
- mirascope/llm/providers/anthropic/_utils/errors.py +2 -2
- mirascope/llm/providers/anthropic/beta_provider.py +64 -18
- mirascope/llm/providers/anthropic/provider.py +91 -33
- mirascope/llm/providers/base/__init__.py +0 -4
- mirascope/llm/providers/base/_utils.py +55 -6
- mirascope/llm/providers/base/base_provider.py +116 -37
- mirascope/llm/providers/google/_utils/__init__.py +2 -0
- mirascope/llm/providers/google/_utils/decode.py +20 -7
- mirascope/llm/providers/google/_utils/encode.py +26 -7
- mirascope/llm/providers/google/_utils/errors.py +3 -2
- mirascope/llm/providers/google/provider.py +64 -18
- mirascope/llm/providers/mirascope/_utils.py +13 -17
- mirascope/llm/providers/mirascope/provider.py +49 -18
- mirascope/llm/providers/mlx/_utils.py +7 -2
- mirascope/llm/providers/mlx/encoding/base.py +5 -2
- mirascope/llm/providers/mlx/encoding/transformers.py +5 -2
- mirascope/llm/providers/mlx/mlx.py +23 -6
- mirascope/llm/providers/mlx/provider.py +42 -13
- mirascope/llm/providers/openai/_utils/errors.py +2 -2
- mirascope/llm/providers/openai/completions/_utils/encode.py +20 -16
- mirascope/llm/providers/openai/completions/base_provider.py +40 -11
- mirascope/llm/providers/openai/provider.py +40 -10
- mirascope/llm/providers/openai/responses/_utils/__init__.py +2 -0
- mirascope/llm/providers/openai/responses/_utils/decode.py +19 -6
- mirascope/llm/providers/openai/responses/_utils/encode.py +22 -10
- mirascope/llm/providers/openai/responses/provider.py +56 -18
- mirascope/llm/providers/provider_registry.py +93 -19
- mirascope/llm/responses/__init__.py +6 -1
- mirascope/llm/responses/_utils.py +102 -12
- mirascope/llm/responses/base_response.py +5 -2
- mirascope/llm/responses/base_stream_response.py +115 -25
- mirascope/llm/responses/response.py +2 -1
- mirascope/llm/responses/root_response.py +89 -17
- mirascope/llm/responses/stream_response.py +6 -9
- mirascope/llm/tools/decorator.py +9 -4
- mirascope/llm/tools/tool_schema.py +12 -6
- mirascope/llm/tools/toolkit.py +35 -27
- mirascope/llm/tools/tools.py +45 -20
- mirascope/ops/__init__.py +4 -0
- mirascope/ops/_internal/configuration.py +82 -31
- mirascope/ops/_internal/exporters/exporters.py +64 -11
- mirascope/ops/_internal/instrumentation/llm/common.py +530 -0
- mirascope/ops/_internal/instrumentation/llm/cost.py +190 -0
- mirascope/ops/_internal/instrumentation/llm/encode.py +1 -1
- mirascope/ops/_internal/instrumentation/llm/llm.py +116 -1242
- mirascope/ops/_internal/instrumentation/llm/model.py +1798 -0
- mirascope/ops/_internal/instrumentation/llm/response.py +521 -0
- mirascope/ops/_internal/instrumentation/llm/serialize.py +300 -0
- mirascope/ops/_internal/protocols.py +83 -1
- mirascope/ops/_internal/traced_calls.py +4 -0
- mirascope/ops/_internal/traced_functions.py +118 -8
- mirascope/ops/_internal/tracing.py +78 -1
- mirascope/ops/_internal/utils.py +52 -4
- {mirascope-2.0.0a6.dist-info → mirascope-2.0.1.dist-info}/METADATA +12 -11
- mirascope-2.0.1.dist-info/RECORD +423 -0
- {mirascope-2.0.0a6.dist-info → mirascope-2.0.1.dist-info}/licenses/LICENSE +1 -1
- mirascope-2.0.0a6.dist-info/RECORD +0 -316
- {mirascope-2.0.0a6.dist-info → mirascope-2.0.1.dist-info}/WHEEL +0 -0
|
@@ -1,58 +1,8 @@
|
|
|
1
1
|
"""Base parameters for LLM providers."""
|
|
2
2
|
|
|
3
|
-
from typing import
|
|
4
|
-
from typing_extensions import Required
|
|
3
|
+
from typing import TypedDict
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
"""Level of effort/reasoning to apply to thinking."""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ThinkingConfig(TypedDict, total=False):
|
|
11
|
-
"""Configuration for extended reasoning/thinking in LLM responses.
|
|
12
|
-
|
|
13
|
-
Thinking is a process where the model spends additional tokens reasoning about
|
|
14
|
-
the prompt before generating a response. Providing any `ThinkingConfig` will enable
|
|
15
|
-
thinking (unless it is specifically disabled via level="minimal"). Depending on
|
|
16
|
-
the provider and model, thinking may always be active regardless of user settings.
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
level: Required[ThinkingLevel]
|
|
20
|
-
"""Level of effort/reasoning to apply to thinking.
|
|
21
|
-
|
|
22
|
-
- none: Disable thinking entirely. Minimizes cost and latency.
|
|
23
|
-
- default: Use the provider's default
|
|
24
|
-
- minimal: Use the provider's lowest setting for reasoning
|
|
25
|
-
- medium: Use a moderate amount of reasoning tokens
|
|
26
|
-
- high: Allow extensive resources for thinking
|
|
27
|
-
- max: Uses as much thinking as allowed by the provider.
|
|
28
|
-
|
|
29
|
-
Mirascope makes a best effort to apply the chosen thinking level, but exact behavior
|
|
30
|
-
varies by provider and model. For example, some models may not support thinking,
|
|
31
|
-
while other models may not allow disabling it.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
include_summaries: bool
|
|
35
|
-
"""Whether to generate reasoning summaries (human readable Thoughts) from model output.
|
|
36
|
-
|
|
37
|
-
Generally, providers do not return raw model thinking output, but may produce
|
|
38
|
-
thought summaries. When `include_summaries` is true, these will be requested from
|
|
39
|
-
the provider (if available). Otherwise, they will not be requested.
|
|
40
|
-
"""
|
|
41
|
-
|
|
42
|
-
encode_thoughts_as_text: bool
|
|
43
|
-
"""Re-encode Thought content as text for model consumption.
|
|
44
|
-
|
|
45
|
-
If `True`, when an `AssistantMessage` contains `Thoughts` and is passed back
|
|
46
|
-
to an LLM, those `Thoughts` will be encoded as `Text`, ensuring the assistant
|
|
47
|
-
can read its prior reasoning. This contrasts with provider defaults which may
|
|
48
|
-
ignore prior thoughts, particularly if tool calls are not involved.
|
|
49
|
-
|
|
50
|
-
When `True`, Mirascope will re-encode messages rather than reusing raw provider
|
|
51
|
-
response content, which may disable provider-specific optimizations like cached
|
|
52
|
-
reasoning tokens.
|
|
53
|
-
|
|
54
|
-
Defaults to `False` if unset.
|
|
55
|
-
"""
|
|
5
|
+
from .thinking_config import ThinkingConfig
|
|
56
6
|
|
|
57
7
|
|
|
58
8
|
class Params(TypedDict, total=False):
|
|
@@ -75,8 +25,8 @@ class Params(TypedDict, total=False):
|
|
|
75
25
|
|
|
76
26
|
top_p: float
|
|
77
27
|
"""Nucleus sampling parameter (0.0 to 1.0).
|
|
78
|
-
|
|
79
|
-
Tokens are selected from the most to least probable until the sum of their
|
|
28
|
+
|
|
29
|
+
Tokens are selected from the most to least probable until the sum of their
|
|
80
30
|
probabilities equals this value. Use a lower value for less random responses and a
|
|
81
31
|
higher value for more random responses.
|
|
82
32
|
"""
|
|
@@ -93,7 +43,7 @@ class Params(TypedDict, total=False):
|
|
|
93
43
|
|
|
94
44
|
seed: int
|
|
95
45
|
"""Random seed for reproducibility.
|
|
96
|
-
|
|
46
|
+
|
|
97
47
|
When ``seed`` is fixed to a specific number, the model makes a best
|
|
98
48
|
effort to provide the same response for repeated requests.
|
|
99
49
|
|
|
@@ -102,7 +52,7 @@ class Params(TypedDict, total=False):
|
|
|
102
52
|
|
|
103
53
|
stop_sequences: list[str]
|
|
104
54
|
"""Stop sequences to end generation.
|
|
105
|
-
|
|
55
|
+
|
|
106
56
|
The model will stop generating text if one of these strings is encountered in the
|
|
107
57
|
response.
|
|
108
58
|
"""
|
|
@@ -111,7 +61,7 @@ class Params(TypedDict, total=False):
|
|
|
111
61
|
"""Configuration for extended reasoning/thinking.
|
|
112
62
|
|
|
113
63
|
Pass a `ThinkingConfig` to configure thinking behavior. The `level` field controls
|
|
114
|
-
whether thinking is enabled and how much reasoning to use. Level may be one of
|
|
64
|
+
whether thinking is enabled and how much reasoning to use. Level may be one of
|
|
115
65
|
"minimal", "low", "medium", or "high". If level is unset, then thinking is enabled
|
|
116
66
|
with a provider-specific default level.
|
|
117
67
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Configuration for extended reasoning/thinking in LLM responses."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
from typing_extensions import Required, TypedDict
|
|
5
|
+
|
|
6
|
+
ThinkingLevel = Literal["none", "default", "minimal", "low", "medium", "high", "max"]
|
|
7
|
+
"""Level of effort/reasoning to apply to thinking."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ThinkingConfig(TypedDict, total=False):
|
|
11
|
+
"""Configuration for extended reasoning/thinking in LLM responses.
|
|
12
|
+
|
|
13
|
+
Thinking is a process where the model spends additional tokens reasoning about
|
|
14
|
+
the prompt before generating a response. Providing any `ThinkingConfig` will enable
|
|
15
|
+
thinking (unless it is specifically disabled via level="minimal"). Depending on
|
|
16
|
+
the provider and model, thinking may always be active regardless of user settings.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
level: Required[ThinkingLevel]
|
|
20
|
+
"""Level of effort/reasoning to apply to thinking.
|
|
21
|
+
|
|
22
|
+
- none: Disable thinking entirely. Minimizes cost and latency.
|
|
23
|
+
- default: Use the provider's default
|
|
24
|
+
- minimal: Use the provider's lowest setting for reasoning
|
|
25
|
+
- medium: Use a moderate amount of reasoning tokens
|
|
26
|
+
- high: Allow extensive resources for thinking
|
|
27
|
+
- max: Uses as much thinking as allowed by the provider.
|
|
28
|
+
|
|
29
|
+
Mirascope makes a best effort to apply the chosen thinking level, but exact behavior
|
|
30
|
+
varies by provider and model. For example, some models may not support thinking,
|
|
31
|
+
while other models may not allow disabling it.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
include_thoughts: bool
|
|
35
|
+
"""Whether to include Thought content in the model output.
|
|
36
|
+
|
|
37
|
+
Depending on the model and provider, enabling include_thoughts to true may
|
|
38
|
+
request reasoning summaries (which are not the underlying reasoning tokens,
|
|
39
|
+
but a readable summary produced by another model), or it may be the original
|
|
40
|
+
reasoning tokens.
|
|
41
|
+
|
|
42
|
+
When include_thoughts is false, no summaries will be requested, and thoughts
|
|
43
|
+
will not be included in the output even if they were provided by the provider.
|
|
44
|
+
|
|
45
|
+
Defaults to false.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
encode_thoughts_as_text: bool
|
|
49
|
+
"""Re-encode Thought content as text for model consumption.
|
|
50
|
+
|
|
51
|
+
If `True`, when an `AssistantMessage` contains `Thoughts` and is passed back
|
|
52
|
+
to an LLM, those `Thoughts` will be encoded as `Text`, ensuring the assistant
|
|
53
|
+
can read its prior reasoning. This contrasts with provider defaults which may
|
|
54
|
+
ignore prior thoughts, particularly if tool calls are not involved.
|
|
55
|
+
|
|
56
|
+
When `True`, Mirascope will re-encode messages rather than reusing raw provider
|
|
57
|
+
response content, which may disable provider-specific optimizations like cached
|
|
58
|
+
reasoning tokens.
|
|
59
|
+
|
|
60
|
+
Defaults to `False` if unset.
|
|
61
|
+
"""
|
mirascope/llm/prompts/_utils.py
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import inspect
|
|
2
|
-
from collections.abc import Sequence
|
|
3
2
|
from typing_extensions import TypeIs
|
|
4
3
|
|
|
5
4
|
from ..context import DepsT, _utils as _context_utils
|
|
6
|
-
from ..messages import (
|
|
7
|
-
AssistantMessage,
|
|
8
|
-
Message,
|
|
9
|
-
SystemMessage,
|
|
10
|
-
UserContent,
|
|
11
|
-
UserMessage,
|
|
12
|
-
user,
|
|
13
|
-
)
|
|
14
5
|
from ..types import P
|
|
15
6
|
from .protocols import (
|
|
16
7
|
AsyncContextMessageTemplate,
|
|
@@ -20,29 +11,6 @@ from .protocols import (
|
|
|
20
11
|
)
|
|
21
12
|
|
|
22
13
|
|
|
23
|
-
def is_messages(
|
|
24
|
-
messages_or_content: Sequence[Message] | UserContent,
|
|
25
|
-
) -> TypeIs[Sequence[Message]]:
|
|
26
|
-
if isinstance(messages_or_content, list):
|
|
27
|
-
if not messages_or_content:
|
|
28
|
-
raise ValueError("Empty array may not be used as message content")
|
|
29
|
-
return isinstance(
|
|
30
|
-
messages_or_content[0], SystemMessage | UserMessage | AssistantMessage
|
|
31
|
-
)
|
|
32
|
-
return False
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def promote_to_messages(result: Sequence[Message] | UserContent) -> Sequence[Message]:
|
|
36
|
-
"""Promote a prompt result to a list of messages.
|
|
37
|
-
|
|
38
|
-
If the result is already a list of Messages, returns it as-is.
|
|
39
|
-
If the result is UserContent, wraps it in a single user message.
|
|
40
|
-
"""
|
|
41
|
-
if is_messages(result):
|
|
42
|
-
return result
|
|
43
|
-
return [user(result)]
|
|
44
|
-
|
|
45
|
-
|
|
46
14
|
def is_context_promptable(
|
|
47
15
|
fn: ContextMessageTemplate[P, DepsT]
|
|
48
16
|
| AsyncContextMessageTemplate[P, DepsT]
|
|
@@ -4,7 +4,7 @@ from collections.abc import Sequence
|
|
|
4
4
|
from typing import Generic, cast, overload
|
|
5
5
|
|
|
6
6
|
from ..context import DepsT
|
|
7
|
-
from ..formatting import Format, FormattableT
|
|
7
|
+
from ..formatting import Format, FormattableT, OutputParser
|
|
8
8
|
from ..tools import (
|
|
9
9
|
AsyncContextTool,
|
|
10
10
|
AsyncContextToolkit,
|
|
@@ -46,13 +46,18 @@ class PromptDecorator(Generic[ToolT, FormattableT]):
|
|
|
46
46
|
tools: Sequence[ToolT] | None
|
|
47
47
|
"""The tools that are included in the prompt, if any."""
|
|
48
48
|
|
|
49
|
-
format:
|
|
49
|
+
format: (
|
|
50
|
+
type[FormattableT] | Format[FormattableT] | OutputParser[FormattableT] | None
|
|
51
|
+
)
|
|
50
52
|
"""The structured output format off the prompt, if any."""
|
|
51
53
|
|
|
52
54
|
def __init__(
|
|
53
55
|
self,
|
|
54
56
|
tools: Sequence[ToolT] | None = None,
|
|
55
|
-
format: type[FormattableT]
|
|
57
|
+
format: type[FormattableT]
|
|
58
|
+
| Format[FormattableT]
|
|
59
|
+
| OutputParser[FormattableT]
|
|
60
|
+
| None = None,
|
|
56
61
|
) -> None:
|
|
57
62
|
"""Initialize the decorator with optional tools and format."""
|
|
58
63
|
self.tools = tools
|
|
@@ -168,7 +173,10 @@ def prompt(
|
|
|
168
173
|
def prompt(
|
|
169
174
|
*,
|
|
170
175
|
tools: Sequence[ToolT] | None = None,
|
|
171
|
-
format: type[FormattableT]
|
|
176
|
+
format: type[FormattableT]
|
|
177
|
+
| Format[FormattableT]
|
|
178
|
+
| OutputParser[FormattableT]
|
|
179
|
+
| None = None,
|
|
172
180
|
) -> PromptDecorator[ToolT, FormattableT]:
|
|
173
181
|
"""Create a decorator for Prompt functions with tools and format"""
|
|
174
182
|
|
|
@@ -181,7 +189,10 @@ def prompt(
|
|
|
181
189
|
| None = None,
|
|
182
190
|
*,
|
|
183
191
|
tools: Sequence[ToolT] | None = None,
|
|
184
|
-
format: type[FormattableT]
|
|
192
|
+
format: type[FormattableT]
|
|
193
|
+
| Format[FormattableT]
|
|
194
|
+
| OutputParser[FormattableT]
|
|
195
|
+
| None = None,
|
|
185
196
|
) -> (
|
|
186
197
|
AsyncContextPrompt[P, DepsT, FormattableT]
|
|
187
198
|
| ContextPrompt[P, DepsT, FormattableT]
|