donkit-llm 0.1.4__tar.gz → 0.1.5__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.
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/PKG-INFO +1 -1
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/pyproject.toml +1 -1
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/openai_model.py +18 -1
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/vertex_model.py +35 -39
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/__init__.py +0 -0
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/claude_model.py +0 -0
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/donkit_model.py +0 -0
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/factory.py +0 -0
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/gemini_model.py +0 -0
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/model_abstract.py +0 -0
- {donkit_llm-0.1.4 → donkit_llm-0.1.5}/src/donkit/llm/ollama_integration.py +0 -0
|
@@ -263,7 +263,24 @@ class OpenAIModel(LLMModelAbstract):
|
|
|
263
263
|
kwargs["tool_choice"] = request.tool_choice
|
|
264
264
|
|
|
265
265
|
if request.response_format:
|
|
266
|
-
|
|
266
|
+
# OpenAI requires specific format for structured output
|
|
267
|
+
# If response_format is a JSON Schema dict with "type": "object", wrap it
|
|
268
|
+
if isinstance(request.response_format, dict):
|
|
269
|
+
if request.response_format.get("type") == "object":
|
|
270
|
+
# This is a JSON Schema - wrap it in json_schema format
|
|
271
|
+
kwargs["response_format"] = {
|
|
272
|
+
"type": "json_schema",
|
|
273
|
+
"json_schema": {
|
|
274
|
+
"name": "response",
|
|
275
|
+
"strict": True,
|
|
276
|
+
"schema": request.response_format,
|
|
277
|
+
},
|
|
278
|
+
}
|
|
279
|
+
else:
|
|
280
|
+
# Already in correct format or simple type
|
|
281
|
+
kwargs["response_format"] = request.response_format
|
|
282
|
+
else:
|
|
283
|
+
kwargs["response_format"] = request.response_format
|
|
267
284
|
|
|
268
285
|
return kwargs
|
|
269
286
|
|
|
@@ -330,6 +330,39 @@ class VertexAIModel(LLMModelAbstract):
|
|
|
330
330
|
|
|
331
331
|
return convert(schema)
|
|
332
332
|
|
|
333
|
+
def _build_config_kwargs(
|
|
334
|
+
self, request: GenerateRequest, system_instruction: str | None = None
|
|
335
|
+
) -> dict[str, Any]:
|
|
336
|
+
"""Build configuration kwargs for Vertex AI generate/generate_stream."""
|
|
337
|
+
config_kwargs: dict[str, Any] = {
|
|
338
|
+
"temperature": request.temperature
|
|
339
|
+
if request.temperature is not None
|
|
340
|
+
else 0.2,
|
|
341
|
+
"top_p": request.top_p if request.top_p is not None else 0.95,
|
|
342
|
+
"max_output_tokens": request.max_tokens
|
|
343
|
+
if request.max_tokens is not None
|
|
344
|
+
else 8192,
|
|
345
|
+
}
|
|
346
|
+
if system_instruction:
|
|
347
|
+
config_kwargs["system_instruction"] = system_instruction
|
|
348
|
+
if request.stop:
|
|
349
|
+
config_kwargs["stop_sequences"] = request.stop
|
|
350
|
+
if request.response_format:
|
|
351
|
+
config_kwargs["response_mime_type"] = "application/json"
|
|
352
|
+
# If response_format is a JSON Schema dict with "type": "object", use it directly
|
|
353
|
+
if isinstance(request.response_format, dict):
|
|
354
|
+
if request.response_format.get("type") == "object":
|
|
355
|
+
# This is a JSON Schema - use it directly
|
|
356
|
+
config_kwargs["response_schema"] = self._clean_json_schema(
|
|
357
|
+
request.response_format
|
|
358
|
+
)
|
|
359
|
+
elif "schema" in request.response_format:
|
|
360
|
+
# Already wrapped in schema key
|
|
361
|
+
config_kwargs["response_schema"] = self._clean_json_schema(
|
|
362
|
+
request.response_format["schema"]
|
|
363
|
+
)
|
|
364
|
+
return config_kwargs
|
|
365
|
+
|
|
333
366
|
async def generate(self, request: GenerateRequest) -> GenerateResponse:
|
|
334
367
|
"""Generate a response using Vertex AI."""
|
|
335
368
|
await self.validate_request(request)
|
|
@@ -410,26 +443,7 @@ class VertexAIModel(LLMModelAbstract):
|
|
|
410
443
|
contents.append(user_content)
|
|
411
444
|
i += 1
|
|
412
445
|
|
|
413
|
-
config_kwargs =
|
|
414
|
-
"temperature": request.temperature
|
|
415
|
-
if request.temperature is not None
|
|
416
|
-
else 0.2,
|
|
417
|
-
"top_p": request.top_p if request.top_p is not None else 0.95,
|
|
418
|
-
"max_output_tokens": request.max_tokens
|
|
419
|
-
if request.max_tokens is not None
|
|
420
|
-
else 8192,
|
|
421
|
-
}
|
|
422
|
-
if system_instruction:
|
|
423
|
-
config_kwargs["system_instruction"] = system_instruction
|
|
424
|
-
if request.stop:
|
|
425
|
-
config_kwargs["stop_sequences"] = request.stop
|
|
426
|
-
if request.response_format:
|
|
427
|
-
config_kwargs["response_mime_type"] = "application/json"
|
|
428
|
-
if "schema" in request.response_format:
|
|
429
|
-
config_kwargs["response_schema"] = self._clean_json_schema(
|
|
430
|
-
request.response_format["schema"]
|
|
431
|
-
)
|
|
432
|
-
|
|
446
|
+
config_kwargs = self._build_config_kwargs(request, system_instruction)
|
|
433
447
|
config = genai.types.GenerateContentConfig(**config_kwargs)
|
|
434
448
|
|
|
435
449
|
if request.tools:
|
|
@@ -584,25 +598,7 @@ class VertexAIModel(LLMModelAbstract):
|
|
|
584
598
|
contents.append(user_content)
|
|
585
599
|
i += 1
|
|
586
600
|
|
|
587
|
-
config_kwargs
|
|
588
|
-
"temperature": request.temperature
|
|
589
|
-
if request.temperature is not None
|
|
590
|
-
else 0.2,
|
|
591
|
-
"top_p": request.top_p if request.top_p is not None else 0.95,
|
|
592
|
-
"max_output_tokens": request.max_tokens
|
|
593
|
-
if request.max_tokens is not None
|
|
594
|
-
else 8192,
|
|
595
|
-
}
|
|
596
|
-
if system_instruction:
|
|
597
|
-
config_kwargs["system_instruction"] = system_instruction
|
|
598
|
-
if request.stop:
|
|
599
|
-
config_kwargs["stop_sequences"] = request.stop
|
|
600
|
-
if request.response_format:
|
|
601
|
-
config_kwargs["response_mime_type"] = "application/json"
|
|
602
|
-
if "schema" in request.response_format:
|
|
603
|
-
config_kwargs["response_schema"] = self._clean_json_schema(
|
|
604
|
-
request.response_format["schema"]
|
|
605
|
-
)
|
|
601
|
+
config_kwargs = self._build_config_kwargs(request, system_instruction)
|
|
606
602
|
config_kwargs["automatic_function_calling"] = (
|
|
607
603
|
genai.types.AutomaticFunctionCallingConfig(maximum_remote_calls=100)
|
|
608
604
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|