mbxai 0.6.14__py3-none-any.whl → 0.6.15__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,55 @@ 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":
|
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
|
+
# Ensure required fields are present
|
58
|
+
if "type" not in schema:
|
59
|
+
schema["type"] = "object"
|
60
|
+
|
61
|
+
if "properties" not in schema:
|
62
|
+
schema["properties"] = {}
|
63
|
+
|
64
|
+
if "required" not in schema:
|
65
|
+
schema["required"] = []
|
66
|
+
|
67
|
+
# Ensure all properties have type and description
|
68
|
+
for prop_name, prop in schema["properties"].items():
|
69
|
+
if "type" not in prop:
|
70
|
+
prop["type"] = "string" # Default to string if type not specified
|
71
|
+
if "description" not in prop:
|
72
|
+
prop["description"] = f"The {prop_name} parameter"
|
73
|
+
|
74
|
+
return schema
|
@@ -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=
|
15
|
-
mbxai-0.6.
|
16
|
-
mbxai-0.6.
|
17
|
-
mbxai-0.6.
|
18
|
-
mbxai-0.6.
|
14
|
+
mbxai/tools/types.py,sha256=Fcr0ivzz2Lt_XatKvG9lCWnlj0OVdRsfZ9YYcQUZebU,2401
|
15
|
+
mbxai-0.6.15.dist-info/METADATA,sha256=Oo-b9zXrMAWxuesfFqXW2JpieyVfyCO9Wh12v0YA5kI,4108
|
16
|
+
mbxai-0.6.15.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
17
|
+
mbxai-0.6.15.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
|
18
|
+
mbxai-0.6.15.dist-info/RECORD,,
|
File without changes
|
File without changes
|