Implement RouterLLM and enhance OpenAI compatibility configuration - #2642
Open
openminddev wants to merge 2 commits into
Open
Implement RouterLLM and enhance OpenAI compatibility configuration#2642openminddev wants to merge 2 commits into
openminddev wants to merge 2 commits into
Conversation
Introduce a RouterLLM implementation (plugins/llm/router.go) that dispatches prompts to configured sub-LLMs based on keywords and regex patterns, supports a default route, shared API key propagation, and schema propagation. Extend openai_compat to accept tool_choice and extra_params (extraBody) and wire them into the returned openAICompatLLM; update tests accordingly (openai_compat_test.go) and add comprehensive router tests (router_test.go) to validate routing, scoring, call dispatch, schema propagation, and config validation.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new RouterLLM plugin to dynamically select among multiple LLM backends based on keyword/regex scoring, and expands the OpenAI-compatible configuration to allow overriding tool_choice and passing arbitrary extra_params into the request body.
Changes:
- Introduces
RouterLLMwith route scoring (keywords + regex patterns), default route fallback, and shared API key propagation. - Adds router unit tests covering route selection, fallback behavior, schema propagation, and config validation.
- Extends OpenAI-compat config with
tool_choiceandextra_params, plus tests validating these overrides.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| plugins/llm/router.go | New router LLM implementation with configurable routes, scoring, default route selection, and API key propagation. |
| plugins/llm/router_test.go | Tests for routing logic, schema propagation, and config validation paths. |
| plugins/llm/openai_compat.go | Adds tool_choice and extra_params to compat config and wires them into instance construction. |
| plugins/llm/openai_compat_test.go | Adds coverage to ensure tool_choice and extra_params are applied from config. |
Copy extraBody into the request body first, then explicitly set core fields so reserved keys (model, messages, tool_choice) cannot be overridden. Add maps import and allocate requestBody with capacity based on extraBody. Remove the manual loop that merged extraBody. Add TestOpenAICompatCallExtraBodyCannotOverrideCoreFields to verify core fields win, messages remain the built array, and non-reserved params (e.g. temperature) still pass through.
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.
This pull request introduces a new router-based LLM selection mechanism and enhances configuration flexibility for OpenAI-compatible LLMs. The most significant changes are the addition of the
RouterLLMfor dynamic routing of prompts to different LLM backends based on keywords and patterns, and the extension of the OpenAI compatibility layer to support extra parameters and tool choice overrides.New Router-based LLM Selection
router.go, implementingRouterLLM, which routes prompts to different LLMs based on configurable keywords and regex patterns, with support for a default route and API key propagation.router_test.go, covering route selection, fallback behavior, schema propagation, and configuration validation.OpenAI Compatibility Improvements
compatConfigto supporttool_choiceand arbitraryextra_params, allowing more flexible configuration of OpenAI-compatible LLMs.tool_choiceandextra_paramsare correctly overridden from the config.