Skip to content

feat(ts-sdk): expose llmProvider for bring-your-own-provider injection#115

Open
adnanrhussain wants to merge 3 commits into
mainfrom
ahussain/ts-llm-provider
Open

feat(ts-sdk): expose llmProvider for bring-your-own-provider injection#115
adnanrhussain wants to merge 3 commits into
mainfrom
ahussain/ts-llm-provider

Conversation

@adnanrhussain

@adnanrhussain adnanrhussain commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds llmProvider to BaseEvaluatorConfig and BatchConfig. Inject any object implementing the public LLMProvider interface and every evaluator routes its LLM calls through it, skipping the built-in OpenAI/Google/Anthropic API-key adapters. Lets you run the evaluators on a provider you already have wired — Vertex AI, Bedrock, an AI-SDK gateway — with no separate API keys.

Addresses #106.

Behavior

  • When llmProvider is set, API-key validation is skipped; the injected provider manages its own model, auth, and retries.
  • llmProvider and modelOverride are mutually exclusive — setting both throws ConfigurationError.
  • Ambient API keys are tolerated (unused) when llmProvider is set.
  • Works for single evaluators and batch. Programmatic only (no CLI flag).

Usage

const evaluator = new GradeLevelAppropriatenessEvaluator({ llmProvider: myProvider });
const result = await evaluator.evaluate(text);

Tests

tests/unit/evaluators/llm-provider.test.ts: no-key construction, routing through the injected provider, ambient-key tolerance, and the modelOverride conflict throw. typecheck / lint / 245 unit tests / build all pass.

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a bring-your-own-provider injection point to the TypeScript SDK so evaluators (including batch) can route all LLM calls through a caller-supplied LLMProvider, bypassing the built-in OpenAI/Google/Anthropic API-key adapters.

Changes:

  • Exposed llmProvider?: LLMProvider on BaseEvaluatorConfig and threaded it into provider creation logic (with a modelOverride conflict guard).
  • Exposed llmProvider?: LLMProvider on BatchConfig and plumbed it through BatchEvaluator evaluator instantiation.
  • Added unit tests covering no-key construction, call routing, ambient-key tolerance, and the llmProvider vs modelOverride conflict.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sdks/typescript/src/evaluators/base.ts Adds llmProvider to evaluator config, skips key validation when set, and returns injected provider from createConfiguredProvider().
sdks/typescript/src/batch/types.ts Adds llmProvider to batch config type so batches can share a custom provider.
sdks/typescript/src/batch/evaluator.ts Passes llmProvider through when constructing per-evaluator instances in a batch.
sdks/typescript/tests/unit/evaluators/llm-provider.test.ts Adds unit coverage for injection routing and configuration interactions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdks/typescript/src/evaluators/base.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +212 to +215
// An injected llmProvider replaces the built-in adapters entirely.
if (config.llmProvider) {
this.validateLlmProvider(config.llmProvider);

maxRetries: this.config.maxRetries,
telemetry: this.config.telemetry,
modelOverride: this.config.modelOverride,
llmProvider: this.config.llmProvider,
@adnanrhussain adnanrhussain force-pushed the ahussain/ts-llm-provider branch from affc642 to ee40021 Compare July 7, 2026 04:02

@czi-fsisenda czi-fsisenda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

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.

3 participants