feat(llm): extract BaseAnthropicLLM, add base_url, export extension points - #566
Merged
Conversation
matteomedioli
force-pushed
the
matteo/base-anthropic-llm
branch
from
July 17, 2026 13:24
cc8c72e to
7f75af3
Compare
matteomedioli
changed the base branch from
matteo/anthropic-kwargs-bugfix
to
matteo/split-http-client-helper
July 17, 2026 13:24
This was referenced Jul 17, 2026
matteomedioli
force-pushed
the
matteo/split-http-client-helper
branch
from
July 17, 2026 15:02
0b4426b to
4baa924
Compare
matteomedioli
force-pushed
the
matteo/base-anthropic-llm
branch
from
July 17, 2026 15:02
7f75af3 to
c8b38b9
Compare
matteomedioli
force-pushed
the
matteo/split-http-client-helper
branch
from
July 17, 2026 15:07
4baa924 to
2b6a1f6
Compare
matteomedioli
force-pushed
the
matteo/base-anthropic-llm
branch
from
July 17, 2026 15:07
c8b38b9 to
6fca589
Compare
matteomedioli
force-pushed
the
matteo/split-http-client-helper
branch
from
July 17, 2026 15:21
2b6a1f6 to
5a6541c
Compare
matteomedioli
force-pushed
the
matteo/base-anthropic-llm
branch
2 times, most recently
from
July 17, 2026 15:41
cfc8dcb to
8470708
Compare
stellasia
reviewed
Jul 21, 2026
stellasia
reviewed
Jul 21, 2026
stellasia
reviewed
Jul 21, 2026
stellasia
reviewed
Jul 21, 2026
matteomedioli
force-pushed
the
matteo/split-http-client-helper
branch
from
July 22, 2026 11:42
5a6541c to
a819760
Compare
matteomedioli
force-pushed
the
matteo/base-anthropic-llm
branch
from
July 22, 2026 13:40
8470708 to
132e5a5
Compare
…tests Add unit tests verifying httpx.Client reaches only the sync Anthropic client, httpx.AsyncClient reaches only the async client, and an invalid http_client type warns and falls back to defaults for both clients. Also note the stale-venv anthropic version gotcha in AGENTS.md.
…d schema logic Moves the message-building, schema-conversion, and response-parsing logic that lived directly on AnthropicLLM into a new BaseAnthropicLLM base class, mirroring the BaseOpenAILLM/OpenAILLM split. AnthropicLLM becomes a subclass responsible only for constructing the SDK clients, paving the way for alternate Anthropic-compatible client implementations.
Allows routing Anthropic requests to a custom Anthropic-compatible endpoint by passing base_url through to both the sync and async SDK clients, alongside the existing http_client routing logic.
Add both base classes to neo4j_graphrag.llm's imports and __all__ so they are documented, supported entry points for subclassing custom LLM clients, with a test verifying the exports.
Covers the AnthropicLLM/BaseAnthropicLLM split: confirms AnthropicLLM subclasses BaseAnthropicLLM, exercises invoke/schema logic through a minimal BaseAnthropicLLM subclass, and verifies the new base_url parameter reaches both the sync and async Anthropic SDK clients (alone and combined with an explicit http_client).
…sses Adds a Sphinx docs page explaining what BaseAnthropicLLM and BaseOpenAILLM are for and how the http_client/base_url injection contract works, with a worked example of subclassing BaseAnthropicLLM to reach a custom endpoint. Links the page and adds API reference entries for both base classes.
Adds a changelog entry covering the new BaseAnthropicLLM base class, the base_url parameter on AnthropicLLM, the BaseAnthropicLLM/BaseOpenAILLM exports, and the new LLM extensibility docs page.
…tp_client_kwargs Review follow-ups: - llm_extensibility.rst no longer claims OpenAILLM declares base_url as a constructor parameter (it accepts it via **kwargs); warning wording fixed (warnings.warn, not logging). - Subclassing example now routes kwargs through split_http_client_kwargs so custom subclasses preserve the sync/async routing contract instead of reintroducing the type-mismatch bug. - split_http_client_kwargs exported from neo4j_graphrag.llm alongside the base classes, with an export test.
Same explicit parameter AnthropicLLM gains in this PR, so the two classes expose the custom-endpoint contract symmetrically. Forwarded to both the sync and async SDK clients; behavior via **kwargs is unchanged for existing callers. Docs and changelog updated to describe one shared contract instead of two paths.
matteomedioli
force-pushed
the
matteo/base-anthropic-llm
branch
from
July 22, 2026 15:47
132e5a5 to
7615841
Compare
stellasia
approved these changes
Jul 23, 2026
stellasia
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the answers!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Today, using
AnthropicLLM's logic against a different endpoint — a proxy, an internal gateway, a self-hosted compatible API — means forking the whole class. This PR makes it a small subclass instead, using the same pattern OpenAI already has (BaseOpenAILLM→OpenAILLM/AzureOpenAILLM).BaseAnthropicLLMholds everything that doesn't depend on how the connection is made: message building, schema conversion, response parsing, structured output.AnthropicLLMbecomes a thin subclass that only creates the two SDK clients. Logic moved as-is — no behavior change (full unit suite passes unchanged).AnthropicLLMandOpenAILLMboth gain an explicitbase_urlparameter to point at a custom endpoint. It already worked when passed through**kwargs; the explicit parameter makes it visible in the signature, docstring, and API docs, and keeps the two classes symmetric.BaseAnthropicLLM,BaseOpenAILLM, andsplit_http_client_kwargsare now exported fromneo4j_graphrag.llmas supported extension points (BaseOpenAILLMexisted but was never exported).llm_extensibility.rst) explains thebase_url/http_clientcontract, with a working subclass example.Notes for reviewers — deliberate decisions, happy to change any of them:
BaseOpenAILLM, the new base class has no abstract methods, so it can technically be instantiated (and fails on first call if no client was set). Kept consistent with the OpenAI base; makingclient/async_clientabstract properties across both is a possible follow-up.Type of Change
Complexity
Complexity: Medium
How Has This Been Tested?
Checklist