Commit e7eb887
authored
feat: model_override adapter with parameterized adapter config (#438)
## Why
Some LLM providers don't respect reasoning-related fields in the request
body. Instead, they expose reasoning variants as **separate model
names** — e.g. `deepseek-r1` (with reasoning) vs `deepseek-r1-fast`
(without). When a client sends `reasoning: { effort: "none" }` or
`enable_thinking: false`, the provider ignores it because the client
addressed the "thinking" model, not the "fast" one.
Plexus currently has no way to bridge this gap — the router picks a
target model, and that's what gets sent to the provider. There was no
mechanism to say "if the client is asking for no reasoning, switch to
the fast variant instead."
## What This Enables
**Conditional model rewriting based on request content.** You can now
configure rules that say:
> "When the target model is `deepseek-r1` AND any of these conditions
are true (reasoning disabled, thinking turned off, budget set to zero,
etc.), rewrite the model name to `deepseek-r1-fast` before sending it to
the provider."
This means:
- Clients can keep using a single model alias (e.g. `glm-5.1`) and let
Plexus automatically pick the right provider variant based on what
features they're requesting
- Providers that use separate model names for reasoning/non-reasoning
variants are now first-class citizens in Plexus — no manual model
switching required
- The rewrite is transparent to the client — they still see the
canonical model name in billing/usage tracking
## Bonus Fix
The OpenAI chat→chat transformer was silently dropping any fields it
didn't explicitly know about (e.g. `enable_thinking`,
`chat_template_kwargs`, `thinking_budget`, `budget_tokens`, `thinking`).
This meant even if you configured conditions for those fields, the
adapter could never match them because the fields were gone by the time
it saw the payload.
Now, same-API-type transformations (chat→chat) preserve all unknown
fields from the original request body, overlaying only the fields that
need explicit transformation. This makes the adapter useful for any
non-standard field a provider might use.
## How to Use It
Configure the `model_override` adapter on a **per-model** basis in the
provider settings (via the Plexus UI or management API):
1. Open the provider in the UI, expand the model entry (e.g.
`zai-org/GLM-5.1-FP8`)
2. Under **Model Adapters**, enable **Model Override**
3. Add rules specifying:
- **Match model** — the provider model name to match against (e.g.
`zai-org/GLM-5.1-FP8`)
- **Rewrite to** — the model name to send instead (e.g. `glm-5.1-fast`)
- **Conditions** — dotted-path fields and values, any match triggers the
rewrite (OR semantics)
Example conditions for detecting "no reasoning" requests:
| Field path | Value |
|---|---|
| `reasoning.enabled` | `false` |
| `reasoning.effort` | `"none"` |
| `enable_thinking` | `false` |
| `thinking.type` | `"disabled"` |
| `chat_template_kwargs.enable_thinking` | `false` |
| `thinking_budget` | `0` |
| `budget_tokens` | `0` |
If `value` is left empty, the condition matches on field presence alone
(any value).
## Implementation Notes
- **Adapter config** upgraded from bare strings to uniform `{ name,
options }` entries. Legacy format is normalized lazily on read — no DB
migration needed, rows self-heal on next save
- **Adapter interface** gains optional `options` parameter on all hooks;
existing adapters are backward-compatible
- **Frontend** includes an inline rule editor for model_override
conditions in the per-model adapter section
- 1344 backend tests passing, frontend build + typecheck + lint clean1 parent 989140d commit e7eb887
17 files changed
Lines changed: 1105 additions & 115 deletions
File tree
- docs
- openapi/components/schemas
- packages
- backend
- src
- __tests__/adapters
- db
- services
- transformers
- adapters
- __tests__
- types
- test/integration
- frontend/src/components/providers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| |||
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
167 | 228 | | |
168 | 229 | | |
169 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
113 | 125 | | |
114 | 126 | | |
115 | | - | |
116 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
117 | 131 | | |
118 | 132 | | |
119 | 133 | | |
| |||
176 | 190 | | |
177 | 191 | | |
178 | 192 | | |
179 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
180 | 206 | | |
181 | 207 | | |
182 | 208 | | |
183 | 209 | | |
184 | 210 | | |
185 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
186 | 215 | | |
187 | 216 | | |
188 | 217 | | |
| |||
192 | 221 | | |
193 | 222 | | |
194 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
195 | 231 | | |
196 | 232 | | |
197 | 233 | | |
| |||
Lines changed: 68 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 6 | + | |
10 | 7 | | |
11 | 8 | | |
12 | 9 | | |
| |||
29 | 26 | | |
30 | 27 | | |
31 | 28 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
37 | 35 | | |
38 | 36 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
56 | 70 | | |
57 | 71 | | |
58 | 72 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
63 | 76 | | |
64 | 77 | | |
65 | 78 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
69 | 103 | | |
70 | 104 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
75 | 110 | | |
76 | 111 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
65 | 119 | | |
66 | 120 | | |
67 | 121 | | |
| |||
0 commit comments