mbxai 0.6.14__py3-none-any.whl → 0.6.16__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.
mbxai/tools/types.py CHANGED
@@ -3,7 +3,7 @@ Type definitions for the tools package.
3
3
  """
4
4
 
5
5
  from typing import Any, Callable
6
- from pydantic import BaseModel
6
+ from pydantic import BaseModel, Field
7
7
 
8
8
  class ToolCall(BaseModel):
9
9
  """A tool call from the model."""
@@ -20,11 +20,76 @@ class Tool(BaseModel):
20
20
 
21
21
  def to_openai_function(self) -> dict[str, Any]:
22
22
  """Convert the tool to an OpenAI function definition."""
23
+ # Ensure schema is in strict format
24
+ strict_schema = self._ensure_strict_schema(self.schema)
25
+
23
26
  return {
24
27
  "type": "function",
25
28
  "function": {
26
29
  "name": self.name,
27
30
  "description": self.description,
28
- "parameters": self.schema
31
+ "parameters": strict_schema
29
32
  }
30
- }
33
+ }
34
+
35
+ def _ensure_strict_schema(self, schema: dict[str, Any]) -> dict[str, Any]:
36
+ """Ensure the schema is in strict format required by OpenAI.
37
+
38
+ Args:
39
+ schema: The input schema to validate and convert
40
+
41
+ Returns:
42
+ A schema in strict format
43
+ """
44
+ # If schema has a $ref, resolve it
45
+ if "$ref" in schema:
46
+ ref = schema["$ref"].split("/")[-1]
47
+ schema = schema.get("$defs", {}).get(ref, {})
48
+
49
+ # If schema has an input wrapper, unwrap it
50
+ if "properties" in schema and "input" in schema["properties"]:
51
+ input_schema = schema["properties"]["input"]
52
+ if "$ref" in input_schema:
53
+ ref = input_schema["$ref"].split("/")[-1]
54
+ input_schema = schema.get("$defs", {}).get(ref, {})
55
+ schema = input_schema
56
+
57
+ # Create a new schema object to ensure we have all required fields
58
+ strict_schema = {
59
+ "type": "object",
60
+ "properties": {},
61
+ "required": []
62
+ }
63
+
64
+ # Copy over properties, ensuring each has type and description
65
+ if "properties" in schema:
66
+ for prop_name, prop in schema["properties"].items():
67
+ # Create a new property object with required fields
68
+ new_prop = {
69
+ "type": prop.get("type", "string"),
70
+ "description": prop.get("description", f"The {prop_name} parameter")
71
+ }
72
+
73
+ # Copy over any additional fields that might be useful
74
+ for key, value in prop.items():
75
+ if key not in new_prop:
76
+ new_prop[key] = value
77
+
78
+ strict_schema["properties"][prop_name] = new_prop
79
+
80
+ # Copy over required fields
81
+ if "required" in schema:
82
+ strict_schema["required"] = schema["required"]
83
+
84
+ # Ensure all required fields are actually in properties
85
+ strict_schema["required"] = [
86
+ req for req in strict_schema["required"]
87
+ if req in strict_schema["properties"]
88
+ ]
89
+
90
+ # Add any additional fields from the original schema
91
+ for key, value in schema.items():
92
+ if key not in strict_schema:
93
+ strict_schema[key] = value
94
+
95
+ return strict_schema
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mbxai
3
- Version: 0.6.14
3
+ Version: 0.6.16
4
4
  Summary: MBX AI SDK
5
5
  Project-URL: Homepage, https://www.mibexx.de
6
6
  Project-URL: Documentation, https://www.mibexx.de
@@ -11,8 +11,8 @@ mbxai/openrouter/models.py,sha256=b3IjjtZAjeGOf2rLsdnCD1HacjTnS8jmv_ZXorc-KJQ,26
11
11
  mbxai/tools/__init__.py,sha256=QUFaXhDm-UKcuAtT1rbKzhBkvyRBVokcQIOf9cxIuwc,160
12
12
  mbxai/tools/client.py,sha256=qOf8MiQ8_flPUNiMioOyjeEaV8rN1EBWb98T8qTC3D4,17582
13
13
  mbxai/tools/example.py,sha256=1HgKK39zzUuwFbnp3f0ThyWVfA_8P28PZcTwaUw5K78,2232
14
- mbxai/tools/types.py,sha256=fo5t9UbsHGynhA88vD_ecgDqL8iLvt2E1h1ym43Rrgk,745
15
- mbxai-0.6.14.dist-info/METADATA,sha256=2k-814igc4Y73kl6bhqN_P2-92TWbZwOd9m2n43LYH4,4108
16
- mbxai-0.6.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
- mbxai-0.6.14.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
18
- mbxai-0.6.14.dist-info/RECORD,,
14
+ mbxai/tools/types.py,sha256=pFSV59rebWASnIQb27wVg1kFYbCGZmPlOjrLNfNuvrc,3245
15
+ mbxai-0.6.16.dist-info/METADATA,sha256=d9Bpi8hqAYZZRz301NfXWU7A-50ZWSZqMTfbxvcMUbw,4108
16
+ mbxai-0.6.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
17
+ mbxai-0.6.16.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
18
+ mbxai-0.6.16.dist-info/RECORD,,
File without changes