Skip to content

feat(llm): extract BaseGeminiLLM, export extension point#571

Draft
matteomedioli wants to merge 2 commits into
matteo/split-http-client-helperfrom
matteo/base-gemini-llm
Draft

feat(llm): extract BaseGeminiLLM, export extension point#571
matteomedioli wants to merge 2 commits into
matteo/split-http-client-helperfrom
matteo/base-gemini-llm

Conversation

@matteomedioli

@matteomedioli matteomedioli commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Stack

Merge order: #565#567#566#571 / #572 (last two in either order). Each PR builds on the previous one. Until its base merges, GitHub may show parent commits in the diff — review only the commits unique to this branch.

Description

Same split as #566, applied to Gemini.

  • New BaseGeminiLLM holds all the shared logic: message building, config and schema building, response parsing, tool handling. GeminiLLM becomes a thin subclass whose only job is creating the genai.Client.
  • BaseGeminiLLM is exported from neo4j_graphrag.llm as a supported extension point. A subclass reaching a custom endpoint just builds its own client — everything else is inherited. A test proves the contract: a minimal subclass that only assigns a client runs invoke() end to end.

Strictly no behavior change:

  • An earlier version of this PR also enabled the supports_structured_output flag for Gemini. That silently changes pipeline defaults for existing users, so it moved to its own PR (feat(llm): GeminiLLM declares supports_structured_output = True #573) with a proper breaking-change note. This PR stays a pure refactor.
  • GeminiLLM's parent class changes from the two interface classes to LLMBase, which extends both — every existing isinstance check still passes, no deprecation warning fires, and the class gains context-manager support (with GeminiLLM(...) as llm:) like the other providers.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update
  • Project configuration change

Complexity

Complexity: Low

How Has This Been Tested?

  • Unit tests
  • E2E tests
  • Manual tests

Checklist

  • Documentation has been updated
  • Unit tests have been updated
  • Examples have been updated
  • CLA (https://neo4j.com/developer/cla/) has been signed
  • CHANGELOG.md updated

…sponse-parsing logic

GeminiLLM now subclasses BaseGeminiLLM and is responsible only for
constructing the genai.Client; everything else (get_messages,
get_messages_v2, config/schema building, tool handling, response
parsing) moves to the base class unchanged. BaseGeminiLLM is exported
from neo4j_graphrag.llm as a documented extension point, mirroring
BaseAnthropicLLM/BaseOpenAILLM.

Also sets supports_structured_output = True on the base class: GeminiLLM
already implements structured output via response_schema/response_mime_type
but never declared the capability flag, so callers had to patch it in
manually.
Review follow-ups:
- Drop the supports_structured_output=True flag flip: it changes
  SimpleKGPipeline/extractor default behavior for existing GeminiLLM
  users and belongs in its own PR with a (breaking)-labeled changelog
  entry, mirroring how the AnthropicLLM flag change was documented.
- Replace method-identity assertions (implementation-shape tests) with a
  minimal BaseGeminiLLM subclass test that exercises invoke() end to
  end — the actual exported extension contract.
@matteomedioli
matteomedioli force-pushed the matteo/split-http-client-helper branch from 2b6a1f6 to 5a6541c Compare July 17, 2026 15:21
@matteomedioli
matteomedioli force-pushed the matteo/base-gemini-llm branch from 6510347 to 44e0906 Compare July 17, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant