donkit-llm 0.1.5__py3-none-any.whl → 0.1.6__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.
donkit/llm/openai_model.py
CHANGED
|
@@ -43,6 +43,43 @@ class OpenAIModel(LLMModelAbstract):
|
|
|
43
43
|
self._init_client(api_key, base_url, organization)
|
|
44
44
|
self._capabilities = self._determine_capabilities()
|
|
45
45
|
|
|
46
|
+
def _clean_schema_for_openai(self, schema: dict, is_gpt5: bool = False) -> dict:
|
|
47
|
+
"""Clean JSON Schema for OpenAI strict mode.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
schema: JSON Schema to clean
|
|
51
|
+
is_gpt5: Currently unused - both GPT-4o and GPT-5 support title/description
|
|
52
|
+
|
|
53
|
+
OpenAI Structured Outputs supports:
|
|
54
|
+
- title and description (useful metadata for the model)
|
|
55
|
+
- Automatically adds additionalProperties: false for all objects
|
|
56
|
+
- Recursively processes nested objects and arrays
|
|
57
|
+
|
|
58
|
+
Note: The main requirement is additionalProperties: false for all objects,
|
|
59
|
+
which is automatically added by this method.
|
|
60
|
+
"""
|
|
61
|
+
cleaned = {}
|
|
62
|
+
|
|
63
|
+
# Copy all fields, recursively processing nested structures
|
|
64
|
+
for key, value in schema.items():
|
|
65
|
+
if key == "properties" and isinstance(value, dict):
|
|
66
|
+
# Recursively clean properties
|
|
67
|
+
cleaned["properties"] = {
|
|
68
|
+
k: self._clean_schema_for_openai(v, is_gpt5) if isinstance(v, dict) else v
|
|
69
|
+
for k, v in value.items()
|
|
70
|
+
}
|
|
71
|
+
elif key == "items" and isinstance(value, dict):
|
|
72
|
+
# Recursively clean array items
|
|
73
|
+
cleaned["items"] = self._clean_schema_for_openai(value, is_gpt5)
|
|
74
|
+
else:
|
|
75
|
+
cleaned[key] = value
|
|
76
|
+
|
|
77
|
+
# Ensure additionalProperties is false for objects (required by OpenAI)
|
|
78
|
+
if cleaned.get("type") == "object" and "additionalProperties" not in cleaned:
|
|
79
|
+
cleaned["additionalProperties"] = False
|
|
80
|
+
|
|
81
|
+
return cleaned
|
|
82
|
+
|
|
46
83
|
def _get_base_model_name(self) -> str:
|
|
47
84
|
"""Get base model name for capability/parameter detection.
|
|
48
85
|
|
|
@@ -267,13 +304,18 @@ class OpenAIModel(LLMModelAbstract):
|
|
|
267
304
|
# If response_format is a JSON Schema dict with "type": "object", wrap it
|
|
268
305
|
if isinstance(request.response_format, dict):
|
|
269
306
|
if request.response_format.get("type") == "object":
|
|
270
|
-
# This is a JSON Schema - wrap it in json_schema format
|
|
307
|
+
# This is a JSON Schema - clean and wrap it in json_schema format
|
|
308
|
+
# GPT-5 and reasoning models need stricter schema cleaning
|
|
309
|
+
is_gpt5 = self._is_reasoning_model()
|
|
310
|
+
cleaned_schema = self._clean_schema_for_openai(
|
|
311
|
+
request.response_format, is_gpt5=is_gpt5
|
|
312
|
+
)
|
|
271
313
|
kwargs["response_format"] = {
|
|
272
314
|
"type": "json_schema",
|
|
273
315
|
"json_schema": {
|
|
274
316
|
"name": "response",
|
|
275
317
|
"strict": True,
|
|
276
|
-
"schema":
|
|
318
|
+
"schema": cleaned_schema,
|
|
277
319
|
},
|
|
278
320
|
}
|
|
279
321
|
else:
|
|
@@ -5,8 +5,8 @@ donkit/llm/factory.py,sha256=KoZ9bD6FsZjU3ldKL7szznDSB8gI1slnI1jGGwKIuVY,9195
|
|
|
5
5
|
donkit/llm/gemini_model.py,sha256=2uLoZr9HjUf1wxiZRGLQFcURCutsB2SV9f-1VaR6kGI,14413
|
|
6
6
|
donkit/llm/model_abstract.py,sha256=aOgYh3I96PsxSxnkIJ1ETx5UFeRxozCD1c44wiKoBSs,8191
|
|
7
7
|
donkit/llm/ollama_integration.py,sha256=WXeV2xNxP7gd1JyMsHMKaQOjvH7QYkLIPs7pmTPWFrg,13236
|
|
8
|
-
donkit/llm/openai_model.py,sha256=
|
|
8
|
+
donkit/llm/openai_model.py,sha256=zzo_wVYMqfId7IksfQyC4zr7lIMfiWmpeIqpKI3MgUo,27446
|
|
9
9
|
donkit/llm/vertex_model.py,sha256=LcdWBdx4JYzom2IsXxhNGEsrYf0N6JmwuRc3sqfKIos,29350
|
|
10
|
-
donkit_llm-0.1.
|
|
11
|
-
donkit_llm-0.1.
|
|
12
|
-
donkit_llm-0.1.
|
|
10
|
+
donkit_llm-0.1.6.dist-info/METADATA,sha256=RTN3wR7de8ToDFQeUs4WfD2nSnrvFc33GLmwrZF4bvc,742
|
|
11
|
+
donkit_llm-0.1.6.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
|
12
|
+
donkit_llm-0.1.6.dist-info/RECORD,,
|
|
File without changes
|