feat(llmhubs): support tool calling and structured output in the Gemi…#45
feat(llmhubs): support tool calling and structured output in the Gemi…#45xinkuleee wants to merge 3 commits into
Conversation
…a provider_metadata
…arts Sanitize response/tool schemas against an explicit allowlist of Gemini Schema fields: convert single-value const to enum and drop unsupported format values and constraints (exclusiveMinimum/Maximum, multipleOf, ...) instead of forwarding them and failing the whole request. Also preserve and replay the original signed Part for text outputs (not only function calls) so a Gemini 3 thoughtSignature on a text Part survives the parse -> Content -> next-turn round trip.
|
the new allowlist filters schema field names, but it does not validate the value shape required by Gemini's OpenAPI In particular,
The newly added numeric-const test therefore asserts an output that Gemini's Please validate and normalize field values in addition to allowlisting keys. Non-string enums should either be represented using supported constraints, deliberately dropped/rejected, or sent through the JSON-Schema-specific API fields ( |
Summary
Adds Google Gemini function/tool calling and JSON-schema structured output to the
LLMHub Gemini adapter, so Gemini models can drive the chat agent (tools) and
structured routing (intent check).
tools/function_call/function_resultto GeminifunctionDeclarations/functionCall/functionResponse(role mappingassistant→model/tool→user, andcall_id↔function-name correlation since Gemini responses carry no call id);parse Gemini
functionCallback intofunction_calloutputs.OpenAPI-subset — inline
$ref/$defs, dropadditionalProperties/$schema,flatten single-element
allOf, and convert OptionalanyOf+{"type":"null"}to
nullable.response_format.type=json_schemato GeminiresponseMimeType+responseSchema(fixes chat intent-check routing on Gemini).supports_tools/supports_structured_outputfor the Gemini provider (core
io_profilederivation + backend equivalent).sanitizer (refs/defs/additionalProperties/allOf/anyOf-null/recursion), and
structured output.
Validation
make precommit-runcd backend && go test ./...cd core && uv run pytestFrontend is untouched, so its build/lint does not apply.
Checklist
CHANGELOG.mdunder## [Unreleased]for user-facing changes.Notes for reviewers
non-streaming path (
generate_streamyields a single chunk). Tool calling works,but without incremental token streaming; a follow-up can add
streamGenerateContent?alt=sse.against the full builtin tool set and the structured intent-check schema.
local default-model switch are gitignored and intentionally excluded from this PR.