mirascope 1.21.1__py3-none-any.whl → 1.21.2__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.
@@ -70,41 +70,50 @@ class GoogleTool(BaseTool):
70
70
  fn["parameters"] = model_schema
71
71
 
72
72
  if "parameters" in fn:
73
- # Resolve $defs and $ref
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
- def resolve_refs(schema: dict[str, Any]) -> dict[str, Any]:
78
- """Recursively resolve $ref references using the $defs dictionary."""
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mirascope
3
- Version: 1.21.1
3
+ Version: 1.21.2
4
4
  Summary: LLM abstractions that aren't obstructions
5
5
  Project-URL: Homepage, https://mirascope.com
6
6
  Project-URL: Documentation, https://mirascope.com/WELCOME
@@ -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=HPe7CZEn1nPFkvuigpDiTdU9y9cQGp6R68FChjETMAU,4623
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.1.dist-info/METADATA,sha256=G2jXSfZomkT1FvuLahmGaE83CA4RMPdhwIujlADIbc8,8730
372
- mirascope-1.21.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
373
- mirascope-1.21.1.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
374
- mirascope-1.21.1.dist-info/RECORD,,
371
+ mirascope-1.21.2.dist-info/METADATA,sha256=1dvAilky26Nim8aNFd5hQEypMwSS9MfUs0grmn__v9o,8730
372
+ mirascope-1.21.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
373
+ mirascope-1.21.2.dist-info/licenses/LICENSE,sha256=LAs5Q8mdawTsVdONpDGukwsoc4KEUBmmonDEL39b23Y,1072
374
+ mirascope-1.21.2.dist-info/RECORD,,