-
-
Notifications
You must be signed in to change notification settings - Fork 74
feat(ext): add route selector extension point and adaptive strategy #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c31d624
feat(ext): add route selector extension point and adaptive strategy
SantiagoDePolonia 189beca
fix(ext): address route-selector review findings
SantiagoDePolonia b3c07a4
test(virtualmodels): cover every pricing pointer in the isolation test
SantiagoDePolonia 454b7cc
feat(dashboard): server-driven virtual-model strategy dropdown
SantiagoDePolonia fe6a0e6
fix(dashboard): describe adaptive as extension-defined
SantiagoDePolonia 38263ff
Merge remote-tracking branch 'origin/main' into feat/ext-route-selector
SantiagoDePolonia 094d1d1
fix(dashboard): gate adaptive help text on server support
SantiagoDePolonia c6ec988
Merge remote-tracking branch 'origin/main' into feat/ext-route-selector
SantiagoDePolonia 8879ea9
fix(admin): preserve VIRTUAL_MODEL_STRATEGIES through runtime-config …
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package ext | ||
|
|
||
| import "time" | ||
|
|
||
| // RouteCandidate is one currently viable target of a load-balanced virtual | ||
| // model, offered to a RouteSelector. Pricing comes from the model registry | ||
| // and is per million tokens; nil means the registry has no price for the | ||
| // target. | ||
| type RouteCandidate struct { | ||
| // Provider is the configured provider name (e.g. "openai", "azure-eu"). | ||
| Provider string | ||
| // Model is the provider-native model ID (e.g. "gpt-4o"). | ||
| Model string | ||
| // Qualified is "provider/model", the stable key selection answers with. | ||
| Qualified string | ||
| // Weight is the operator-configured target weight; 0 means unset (treat | ||
| // as 1). | ||
| Weight float64 | ||
| InputPerMtok *float64 | ||
| OutputPerMtok *float64 | ||
| } | ||
|
|
||
| // RouteRequest asks a RouteSelector to pick one target for a request routed | ||
| // through a load-balanced virtual model. Candidates are the targets that are | ||
| // catalog-supported and have rate-limit capacity right now, in declared | ||
| // order; there are always at least two (single-candidate picks bypass the | ||
| // selector so an alias behaves identically with and without one). | ||
| type RouteRequest struct { | ||
| // Source is the virtual model name the request addressed. | ||
| Source string | ||
| // SessionID is the detected client session, when present. Session | ||
| // affinity is enforced by core before the selector runs; the ID is | ||
| // provided for observability only. | ||
| SessionID string | ||
| Candidates []RouteCandidate | ||
| } | ||
|
|
||
| // RouteTarget identifies a provider/model pair as seen by the upstream | ||
| // client layer. | ||
| type RouteTarget struct { | ||
| Provider string | ||
| Model string | ||
| } | ||
|
|
||
| // Qualified returns the "provider/model" key matching RouteCandidate.Qualified. | ||
| func (t RouteTarget) Qualified() string { return t.Provider + "/" + t.Model } | ||
|
|
||
| // RouteOutcome describes one completed upstream call. Every call is | ||
| // reported — primaries and failover attempts alike — so selectors learn from | ||
| // traffic they did not steer. Transport-level retries inside the provider | ||
| // client are aggregated into their call's single outcome: StatusCode and Err | ||
| // reflect the final result, and Duration spans the whole call including | ||
| // retry backoff, so a target that only succeeds after internal retries still | ||
| // scores slower than a target that succeeds at once. | ||
| type RouteOutcome struct { | ||
| RouteTarget | ||
| // Endpoint is the upstream API endpoint (e.g. "/chat/completions"). | ||
| Endpoint string | ||
| // StatusCode is the final upstream HTTP status; 0 on a network error. | ||
| StatusCode int | ||
| // Duration is the call duration, including any transport-level retries. | ||
| // For streaming requests it measures time to stream establishment, not | ||
| // the full stream lifetime. | ||
| Duration time.Duration | ||
| Stream bool | ||
| // Err is the client-layer error, nil on success. | ||
| Err error | ||
| } | ||
|
|
||
| // RouteSelector steers load balancing for virtual models using the | ||
| // "adaptive" strategy. Core consults the selector only to pick among | ||
| // currently viable targets; session affinity, rate-limit capacity, failover | ||
| // chains, and retries all remain core's responsibility. | ||
| // | ||
| // Select must be fast and must not block: it runs on the request path before | ||
| // the upstream call. Implementations must be safe for concurrent use. A | ||
| // (_, false) answer — and any answer naming a model outside Candidates — | ||
| // falls back to weighted round robin, so selectors fail open by declining. | ||
| // | ||
| // OnAttemptStart and OnAttemptEnd observe the upstream client lifecycle, | ||
| // once per upstream call (transport-level retries within a call are | ||
| // aggregated — see RouteOutcome). For streaming requests OnAttemptEnd fires | ||
| // when the stream is established, not when it closes. | ||
| type RouteSelector interface { | ||
| Name() string | ||
| Select(req RouteRequest) (qualified string, ok bool) | ||
| OnAttemptStart(target RouteTarget) | ||
| OnAttemptEnd(outcome RouteOutcome) | ||
| } |
77 changes: 39 additions & 38 deletions
77
...oard/static/dist/assets/index-BohrvrMp.js → ...oard/static/dist/assets/index-nyMi7SZX.js
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.