Repository navigation
feat(llm): add an OpenAI-compatible provider with a configurable base URL - #88
Merged
Merged
Conversation
… URL `llm.provider` accepted one value, so the key documented a choice the user did not have. It now accepts `openai-compatible` alongside `anthropic`, which reaches any endpoint speaking the OpenAI chat-completions dialect: hosted ones that are cheaper, and servers on the user's own machine, where release data never leaves it. Ollama, LM Studio, llama.cpp and vLLM all serve that dialect, so one adapter covers them rather than one per runner. Defaults move out of the property initializers into `LlmProviderDefaults`, because a default that is right for one provider is wrong for the other. For `openai-compatible` neither `model` nor `baseUrl` has one: the models an endpoint serves are its own, and an endpoint default would have to be a hosted one, which would send release data off the machine for anyone who configured only the model. Both failures name the key they are missing. `baseUrl` applies to both providers, since `AnthropicClient.BaseUrl` exists and a proxy in front of the Anthropic API is the same need. A missing API key is tolerated. The endpoints this exists for do not read the Authorization header at all, and `ApiKeyCredential` rejects an empty string in its constructor, so a placeholder stands in rather than letting "no key needed" crash before a request goes out. A hosted endpoint sees the placeholder and answers 401, which is the intended outcome: the refusal comes from the endpoint. `thinking` is refused for this provider at startup instead of being dropped silently. It travels in an Anthropic request type, so passing it to any other client would fail on the first call rather than while wiring up. Two things found by running it rather than by reading it: - `NetworkTimeout` is raised to 10 minutes. The SDK default of 100 seconds suits a hosted API and fails the case this provider exists for; against a local 14B model it killed two of three audience texts, each after four retries. - `localhost:11434` parses as an absolute URI whose scheme is `localhost`, so the scheme is checked too. A forgotten http:// would otherwise surface far from the setting that caused it. `Chartula.Core` is untouched. The package is referenced by `Chartula.Cli` alone, and costs no trim warnings: of the 1230 in a trimmer publish, 1204 come from the Anthropic SDK and none from this one. Closes #78
Owner
Author
|
Related to #87, which this PR does not close. The Also related: #85 and #86 were found while smoke-testing this branch and are now bundled under #94, which is where the work should happen. Both carry |
1 of 5 tasks
3 tasks done
goldbarth
added a commit
that referenced
this pull request
Oct 1, 2026
… alone (#319) Follows #318, which added the ADR index and template. - **Why:** the reason the domain knows no model provider was argued in one bullet of `architecture.md`, in `CLAUDE.md`, and implied in `testing.md`, but recorded nowhere as a decision with its date and its cost. A contributor who wanted to call a provider feature from `Chartula.Core` found a rule without the reasons behind it. - **ADR 0004** records it in the template of #318: decided 2026-07-16 in #41 (for #2), recorded here. - **Context:** two operations need a model, both with structured output; the product promises several providers (#75); a domain tied to one SDK ties the pipeline to it, and lets a test of the domain reach a real model, which costs tokens, needs a key and depends on the model. - **Decision:** `Chartula.Core` references `Microsoft.Extensions.AI` alone, `ChatModel` sends to an `IChatClient`, the provider packages are referenced by `Chartula.Cli` alone, and what the domain asks of a model is expressed in `Microsoft.Extensions.AI` terms. Provider knowledge such as `ClaudeThinkingSupport` stays in `Cli/Composition`. - **Consequences, precise about the tests:** `Chartula.Core.Tests` cannot reach a model by construction. `Chartula.Cli.Tests` does reference the SDKs, on purpose, and stays offline because its tests replace the network, not because of its references; the ADR says so rather than claiming the whole suite is safe by construction. Also: a provider joins in the composition root (#88 changed no file in `Chartula.Core`), the domain is limited to what `IChatClient` expresses, a provider package is weighed for trimming (ADR 0002), and referencing one from `Core` or `Infrastructure` starts as an issue. - **`architecture.md`** keeps the choice as one line and links the ADR instead of arguing it; **`testing.md`** links the ADR for why no Core test can reach a model. - The index in `adr/README.md` lists 0004. **Verified:** - The references were read from the project files: `Chartula.Core.csproj` holds `Microsoft.Extensions.AI` and nothing else; `Anthropic` and `Microsoft.Extensions.AI.OpenAI` are in `Chartula.Cli.csproj` only; `Chartula.Cli.Tests` references `Chartula.Cli`. - The decision date and pull request from `git log -S IChatClient` and #41's description; the provider promise from the decision comment on #75; that #88 touched no file in `src/Chartula.Core` from its diff. - `GetResponseAsync<T>`, `ReasoningOptions` and `UsageDetails` as used in `ChatModel.cs` and `ChatModelOptions.cs`. - Every relative link and anchor in all Markdown files of the repository resolves (script, with a negative test). Tests: none, documentation only.
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.
Closes #78.
llm.provideraccepted one value, so the key documented a choice the user did not have. It now acceptsopenai-compatible, which reaches any endpoint speaking the OpenAI chat-completions dialect - hosted ones that are cheaper, and a server on the user's own machine, where release data never leaves it.What
LlmProvider+LlmProviderParser, in the shapeThinkingModealready uses. An unknown name throws rather than falling back, because silently reaching a different provider would send release data somewhere the user did not choose.LlmProviderDefaultstakes the defaults out of the property initializers. A default that is right for one provider is wrong for the other.llm.baseUrl, applying to both providers -AnthropicClient.BaseUrlexists, and a proxy in front of the Anthropic API is the same need.OpenAiCompatibleChatClientis the only place the OpenAI package is named, which is what keeps it out of the domain.Decisions worth disagreeing with
Neither
modelnorbaseUrlhas a default foropenai-compatible. The models an endpoint serves are its own. The endpoint is the more deliberate omission: a default would have to be a hosted one, and this provider exists so release data can stay on the user's machine - anyone configuring only the model would then send it off the machine without being asked. Both errors name the missing key and give an example.A missing API key builds a client anyway. Ollama, LM Studio, llama.cpp and vLLM do not read the Authorization header.
ApiKeyCredentialrejects an empty string in its constructor, so a placeholder stands in - otherwise "no key needed" becomes a crash before any request goes out. A hosted endpoint sees the placeholder and answers 401, which is the point: the refusal comes from the endpoint, as it already did for Anthropic.thinkingis refused rather than dropped. It travels in an Anthropic request type. Handing that to another client fails on the first call; refusing at startup fails where the setting was made.Native AOT
Trimmer publish,
linux-x64, self-contained, on 2026-08-03:This inverts the expectation in the issue. Of the 1230 warnings, 1204 come from
Anthropic.*and 24 from YamlDotNet; this package adds none, because the OpenAI SDK serializes throughSystem.ClientModelwith hand-written readers rather than reflection. The only new transitive dependency on net10.0 isSystem.ClientModel- not Azure.Core. The already-shipped provider SDK is the AOT blocker, not this one.Caveat: a trimmer run is not a native AOT run.
clangis absent on the machine, so there is no native binary size andIL3050from package assemblies is unmeasured.Two things found by running it
NetworkTimeoutraised to 10 minutes. The SDK default is 100 seconds - fine for a hosted API, wrong for the case this provider exists for. Against a local 14B model it killed two of three audience texts, each after four retries.The base URL scheme is checked, not just the parse.
localhost:11434parses as an absolute URI whose scheme islocalhostand whose path is11434. A forgottenhttp://would have surfaced far from the setting that caused it.Smoke runs
Three runs against Ollama 0.21.0 on 2026-08-03,
v0.1.0of this repository:qwen2.5-coder:7bqwen2.5:14bqwen2.5:14bThe first two measured a broken configuration rather than the models. Ollama truncated every prompt from ~12,400 tokens to 4,096, and since the instruction sits at the front while truncation keeps the end, the model received the text under review with neither the facts nor the task. Raising the context produced a usable changelog from the same model.
Two findings were filed rather than fixed here: #85 (a truncated prompt must fail the run) and #86 (a thorough check that never saw the facts must not report as clean).
AC 6 is only half met. The hosted smoke run is outstanding - it needs a key, and it is the one that exercises the real key path, HTTPS, and an endpoint that does not enforce the schema by constrained decoding. Recorded as an open item on #78 rather than quietly dropped.
On #79
Its trigger did not fire: Ollama held the JSON schema on every call. Precisely, though - it enforces the schema by constrained decoding rather than the model following it; a request for a poem, sent with the verdict schema, came back as a valid verdict. The poor text quality is not a #79 trigger, since a native adapter would not have changed it. That was the context window. One runner, two models: LM Studio, llama.cpp and vLLM stay unverified.
Tests
12 new, 315 green. No test covers
NetworkTimeout- it is an SDK-internal option observable only through a genuinely slow response, and a test reproducing that would tie the suite's runtime to a timeout.🤖 Generated with Claude Code