donkit-llm 0.1.5__tar.gz → 0.1.6__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: donkit-llm
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Unified LLM model implementations for Donkit (OpenAI, Azure OpenAI, Claude, Vertex AI, Ollama)
5
5
  License: MIT
6
6
  Author: Donkit AI
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "donkit-llm"
3
- version = "0.1.5"
3
+ version = "0.1.6"
4
4
  description = "Unified LLM model implementations for Donkit (OpenAI, Azure OpenAI, Claude, Vertex AI, Ollama)"
5
5
  authors = ["Donkit AI <opensource@donkit.ai>"]
6
6
  license = "MIT"
@@ -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": request.response_format,
318
+ "schema": cleaned_schema,
277
319
  },
278
320
  }
279
321
  else: