feat(ai): add openai-compatible structured + streaming adapters - #295
Merged
Conversation
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.
what
Add OpenAI-compatible provider adapters — one code path serves Ollama, LM Studio, vLLM, llama.cpp, and OpenAI itself. Third PR in the local-LLM routing sequence (PR1 structured seam, PR2 native-free routing surface).
providers/openai.ts—openaiStructured(StructuredProvider over/chat/completionswith json_schemaresponse_format) +openaiTransport(AiTransport over SSE stream). Both take injectablebaseUrl/apiKey/fetch; fall back to lazygetSecret('openai_api_key')+resolveAiFetch()in prod.registry.ts— wire the openai branch to build both adapters without touching secrets at construction time. Gemini branch still throws "not available yet" (lands next PR).routing.ts— addDEFAULT_OPENAI_BASE.why
Route high-volume tiers to a local/cheap backend so cost does not balloon. OpenAI-compat is the one wire format every local runtime speaks.
test
openai-provider.test.ts— structured maps completion + usage + refusal + non-2xx + empty-key guard; transport streams delta tokens, reports final usage chunk, routes errors to onError. All native-free (injected fetch).registry.test.ts— openai builds adapter/transport without db; gemini still throws.