mirascope 1.21.1__py3-none-any.whl → 1.21.3__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/core/bedrock/_utils/_setup_call.py +14 -2
- mirascope/core/google/tool.py +43 -32
- {mirascope-1.21.1.dist-info → mirascope-1.21.3.dist-info}/METADATA +1 -1
- {mirascope-1.21.1.dist-info → mirascope-1.21.3.dist-info}/RECORD +6 -6
- {mirascope-1.21.1.dist-info → mirascope-1.21.3.dist-info}/WHEEL +0 -0
- {mirascope-1.21.1.dist-info → mirascope-1.21.3.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import os
|
|
5
6
|
from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator
|
|
6
7
|
from functools import wraps
|
|
7
8
|
from typing import Any, ParamSpec, cast, overload
|
|
@@ -223,12 +224,23 @@ def setup_call(
|
|
|
223
224
|
|
|
224
225
|
call_kwargs |= cast(BedrockCallKwargs, {"modelId": model, "messages": messages})
|
|
225
226
|
|
|
227
|
+
env_vars = {}
|
|
228
|
+
if access_key_id := os.getenv("AWS_ACCESS_KEY_ID"):
|
|
229
|
+
env_vars["aws_access_key_id"] = access_key_id
|
|
230
|
+
if secret_access_key := os.getenv("AWS_SECRET_ACCESS_KEY"):
|
|
231
|
+
env_vars["aws_secret_access_key"] = secret_access_key
|
|
232
|
+
if session_token := os.getenv("AWS_SESSION_TOKEN"):
|
|
233
|
+
env_vars["aws_session_token"] = session_token
|
|
234
|
+
if region_name := os.getenv("AWS_REGION_NAME"):
|
|
235
|
+
env_vars["region_name"] = region_name
|
|
236
|
+
if profile_name := os.getenv("AWS_PROFILE"):
|
|
237
|
+
env_vars["profile_name"] = profile_name
|
|
226
238
|
if client is None:
|
|
227
239
|
if fn_is_async(fn):
|
|
228
|
-
session = get_session()
|
|
240
|
+
session = get_session(env_vars=env_vars)
|
|
229
241
|
_client = _AsyncBedrockRuntimeWrappedClient(session, model)
|
|
230
242
|
else:
|
|
231
|
-
session = Session()
|
|
243
|
+
session = Session(**env_vars)
|
|
232
244
|
_client = session.client("bedrock-runtime")
|
|
233
245
|
else:
|
|
234
246
|
_client = client
|
mirascope/core/google/tool.py
CHANGED
|
@@ -70,41 +70,50 @@ class GoogleTool(BaseTool):
|
|
|
70
70
|
fn["parameters"] = model_schema
|
|
71
71
|
|
|
72
72
|
if "parameters" in fn:
|
|
73
|
-
#
|
|
73
|
+
# Define a function to handle both ref resolution and examples conversion
|
|
74
|
+
def resolve_refs_and_fix_examples(
|
|
75
|
+
schema: dict[str, Any], defs: dict[str, Any] | None = None
|
|
76
|
+
) -> dict[str, Any]:
|
|
77
|
+
"""Recursively resolve $ref references and fix examples/example fields."""
|
|
78
|
+
# If this is a reference, resolve it
|
|
79
|
+
if "$ref" in schema:
|
|
80
|
+
ref = schema["$ref"]
|
|
81
|
+
if ref.startswith("#/$defs/") and defs:
|
|
82
|
+
ref_key = ref.replace("#/$defs/", "")
|
|
83
|
+
if ref_key in defs:
|
|
84
|
+
# Merge the definition with the current schema (excluding $ref)
|
|
85
|
+
resolved = {
|
|
86
|
+
**{k: v for k, v in schema.items() if k != "$ref"},
|
|
87
|
+
**resolve_refs_and_fix_examples(defs[ref_key], defs),
|
|
88
|
+
}
|
|
89
|
+
return resolved
|
|
90
|
+
|
|
91
|
+
# Handle examples -> example conversion
|
|
92
|
+
result = {}
|
|
93
|
+
for key, value in schema.items():
|
|
94
|
+
# Convert "examples" to "example" for Google Schema
|
|
95
|
+
if key == "examples":
|
|
96
|
+
result["example"] = value
|
|
97
|
+
elif isinstance(value, dict):
|
|
98
|
+
result[key] = resolve_refs_and_fix_examples(value, defs)
|
|
99
|
+
elif isinstance(value, list):
|
|
100
|
+
result[key] = [
|
|
101
|
+
resolve_refs_and_fix_examples(item, defs)
|
|
102
|
+
if isinstance(item, dict)
|
|
103
|
+
else item
|
|
104
|
+
for item in value
|
|
105
|
+
]
|
|
106
|
+
else:
|
|
107
|
+
result[key] = value
|
|
108
|
+
return result
|
|
109
|
+
|
|
110
|
+
# Extract $defs if they exist
|
|
111
|
+
defs = {}
|
|
74
112
|
if "$defs" in fn["parameters"]:
|
|
75
113
|
defs = fn["parameters"].pop("$defs")
|
|
76
114
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# If this is a reference, resolve it
|
|
80
|
-
if "$ref" in schema:
|
|
81
|
-
ref = schema["$ref"]
|
|
82
|
-
if ref.startswith("#/$defs/"):
|
|
83
|
-
ref_key = ref.replace("#/$defs/", "")
|
|
84
|
-
if ref_key in defs:
|
|
85
|
-
# Merge the definition with the current schema (excluding $ref)
|
|
86
|
-
resolved = {
|
|
87
|
-
**{k: v for k, v in schema.items() if k != "$ref"},
|
|
88
|
-
**resolve_refs(defs[ref_key]),
|
|
89
|
-
}
|
|
90
|
-
return resolved
|
|
91
|
-
|
|
92
|
-
# Process all other keys recursively
|
|
93
|
-
result = {}
|
|
94
|
-
for key, value in schema.items():
|
|
95
|
-
if isinstance(value, dict):
|
|
96
|
-
result[key] = resolve_refs(value)
|
|
97
|
-
elif isinstance(value, list):
|
|
98
|
-
result[key] = [
|
|
99
|
-
resolve_refs(item) if isinstance(item, dict) else item
|
|
100
|
-
for item in value
|
|
101
|
-
]
|
|
102
|
-
else:
|
|
103
|
-
result[key] = value
|
|
104
|
-
return result
|
|
105
|
-
|
|
106
|
-
# Resolve all references in the parameters
|
|
107
|
-
fn["parameters"] = resolve_refs(fn["parameters"])
|
|
115
|
+
# Resolve all references in the parameters and fix examples
|
|
116
|
+
fn["parameters"] = resolve_refs_and_fix_examples(fn["parameters"], defs)
|
|
108
117
|
|
|
109
118
|
def handle_enum_schema(prop_schema: dict[str, Any]) -> dict[str, Any]:
|
|
110
119
|
if "enum" in prop_schema:
|
|
@@ -112,6 +121,7 @@ class GoogleTool(BaseTool):
|
|
|
112
121
|
return prop_schema
|
|
113
122
|
|
|
114
123
|
# Process properties after resolving references
|
|
124
|
+
# We're already handling examples -> example conversion recursively above
|
|
115
125
|
fn["parameters"]["properties"] = {
|
|
116
126
|
prop: {
|
|
117
127
|
key: value
|
|
@@ -120,6 +130,7 @@ class GoogleTool(BaseTool):
|
|
|
120
130
|
}
|
|
121
131
|
for prop, prop_schema in fn["parameters"]["properties"].items()
|
|
122
132
|
}
|
|
133
|
+
|
|
123
134
|
return Tool(function_declarations=[FunctionDeclaration(**fn)])
|
|
124
135
|
|
|
125
136
|
@classmethod
|
|
@@ -158,7 +158,7 @@ mirascope/core/bedrock/_utils/_convert_message_params.py,sha256=ZPFj34ed0-4bmMld
|
|
|
158
158
|
mirascope/core/bedrock/_utils/_get_json_output.py,sha256=hW-IBBQ5YW85VljjFJHDDtu66zsaF2ydTbFxgCX_j6A,1159
|
|
159
159
|
mirascope/core/bedrock/_utils/_handle_stream.py,sha256=s8KNMNDKzvSIkFROtaZgbEJry78X_qCzTvGmHcL7UW0,3776
|
|
160
160
|
mirascope/core/bedrock/_utils/_message_param_converter.py,sha256=T45kksn78idbqD9NZ3Omx1nS_IoYmTfA5y-bAHlX2fM,6846
|
|
161
|
-
mirascope/core/bedrock/_utils/_setup_call.py,sha256=
|
|
161
|
+
mirascope/core/bedrock/_utils/_setup_call.py,sha256=XQs-JlviE0uhbBxEpjXP8812NbiObLYx5VkAwJJAF84,9168
|
|
162
162
|
mirascope/core/cohere/__init__.py,sha256=vk73WFGBOEmMFEiqWMRnPfxsCBDlDcq8SaLB2A6RKeo,830
|
|
163
163
|
mirascope/core/cohere/_call.py,sha256=y0nB_7h7FWCNxHRPywtAVCYXyeYX3uzTyYBPWnuLwUE,2261
|
|
164
164
|
mirascope/core/cohere/_call_kwargs.py,sha256=YmHwiofs0QADGp0wXUtOr_Z5Pt849zaCtIZmVyjw2OM,292
|
|
@@ -217,7 +217,7 @@ mirascope/core/google/call_response.py,sha256=8yn1cRtqxhnjjzLltfWMzLbaS1Dg7gmS4I
|
|
|
217
217
|
mirascope/core/google/call_response_chunk.py,sha256=oORYaGjOBv4U1IVhsR_ZS-Vr-B58I8G0-9d6Kcj9RM4,3427
|
|
218
218
|
mirascope/core/google/dynamic_config.py,sha256=O6j8F0fLVFuuNwURneu5OpPuu_bMEtbDEFHhJXRT6V0,857
|
|
219
219
|
mirascope/core/google/stream.py,sha256=bTxB8OUrKXxzmcX0C7_-LqtBfaAAazA5HjKZGSxxtLw,4466
|
|
220
|
-
mirascope/core/google/tool.py,sha256=
|
|
220
|
+
mirascope/core/google/tool.py,sha256=61a9Ejdxz41pwaab9VE2yvP_J1Aebua3BeRPJ_GJSnE,5138
|
|
221
221
|
mirascope/core/google/_utils/__init__.py,sha256=vL0hx6WKW5lqpUcFTFCFGvmwtR-pts0JzWgCXhaUVrI,388
|
|
222
222
|
mirascope/core/google/_utils/_convert_common_call_params.py,sha256=KA-z6uvRtdD4WydC0eXd3dzQuSh4x4WKNR8PAqFNUVY,1065
|
|
223
223
|
mirascope/core/google/_utils/_convert_finish_reason_to_common_finish_reasons.py,sha256=ig4tb7Zanz-tyZpvc9Ncd47a2FNTOS7-wl1PYBq-4cY,879
|
|
@@ -368,7 +368,7 @@ mirascope/v0/base/ops_utils.py,sha256=1Qq-VIwgHBaYutiZsS2MUQ4OgPC3APyywI5bTiTAmA
|
|
|
368
368
|
mirascope/v0/base/prompts.py,sha256=FM2Yz98cSnDceYogiwPrp4BALf3_F3d4fIOCGAkd-SE,1298
|
|
369
369
|
mirascope/v0/base/types.py,sha256=ZfatJoX0Yl0e3jhv0D_MhiSVHLYUeJsdN3um3iE10zY,352
|
|
370
370
|
mirascope/v0/base/utils.py,sha256=XREPENRQTu8gpMhHU8RC8qH_am3FfGUvY-dJ6x8i-mw,681
|
|
371
|
-
mirascope-1.21.
|
|
372
|
-
mirascope-1.21.
|
|
373
|
-
mirascope-1.21.
|
|
374
|
-
mirascope-1.21.
|
|
371
|
+
mirascope-1.21.3.dist-info/METADATA,sha256=C4EyG1JBa6VMuS-WqgsCGClL3eLVtBN0dPzL1nJ6Rsg,8730
|
|
372
|
+
mirascope-1.21.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
373
|
+
mirascope-1.21.3.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
|
|
374
|
+
mirascope-1.21.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|