diff options
Diffstat (limited to '.rules/plan/08-15-strip-ignored-params-and-temp.md')
| -rw-r--r-- | .rules/plan/08-15-strip-ignored-params-and-temp.md | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/.rules/plan/08-15-strip-ignored-params-and-temp.md b/.rules/plan/08-15-strip-ignored-params-and-temp.md new file mode 100644 index 0000000..5d555eb --- /dev/null +++ b/.rules/plan/08-15-strip-ignored-params-and-temp.md @@ -0,0 +1,142 @@ +# Phase 08 — Strip ignored params and validate temperature + +**Estimated time:** ~15 minutes +**Touches:** `lib/dispatch/adapter/minimax/request_builder.rb`. + +## Goal + +Two related changes in `RequestBuilder.build`: + +1. **Strip parameters MiniMax ignores** so the wire payload is clean. + Per MiniMax's compatibility docs the following Anthropic parameters + are *Ignored* by their endpoint: `top_k`, `stop_sequences`, + `service_tier`, `mcp_servers`, `context_management`, `container`. + Whatever shape they arrive in, they must not appear in the outgoing + body. + +2. **Validate `temperature`** to MiniMax's documented `(0.0, 1.0]` range. + Outside that range MiniMax returns a 400. Rather than ship malformed + requests, raise `ArgumentError` at build time when the value is `<= 0` + or `> 1`. `nil` is allowed (means "don't send temperature, MiniMax + uses its default"). + +## Steps + +### 1. Open `lib/dispatch/adapter/minimax/request_builder.rb` + +Locate the `RequestBuilder.build` method. It currently takes these +keywords: + +``` +model_id:, messages:, system:, tools:, is_oauth:, base_url:, +stream:, max_tokens:, thinking:, tool_choice:, cache_retention:, +metadata:, disable_strict_tools: +``` + +Phase 02 already removed the `is_oauth:` keyword from the callsite — make +sure it is removed from the parameter list here too. If it is not yet +removed, remove it now. + +### 2. Add a `temperature:` keyword and a `top_p:` keyword + +These are not currently exposed in `RequestBuilder.build`. Add them: + +```ruby +def build( + model_id:, + messages:, + system:, + tools:, + base_url:, + stream: true, + max_tokens: nil, + temperature: nil, + top_p: nil, + thinking: nil, + tool_choice: nil, + cache_retention: nil, + metadata: nil, + disable_strict_tools: false +) +``` + +(`top_p` is fully supported per MiniMax docs.) + +### 3. Validate temperature inside the method body + +Right after `model_info = ModelCatalog.build(model_id)` (or wherever the +opening sanity checks live), add: + +```ruby +unless temperature.nil? + unless temperature.is_a?(Numeric) + raise ArgumentError, + "temperature must be Numeric or nil, got #{temperature.class}" + end + if temperature <= 0.0 || temperature > 1.0 + raise ArgumentError, + "temperature must be in (0.0, 1.0], got #{temperature}" + end +end +``` + +### 4. Plumb temperature and top_p into the body + +After the base body assembly: + +```ruby +body[:temperature] = temperature unless temperature.nil? +body[:top_p] = top_p unless top_p.nil? +``` + +### 5. Strip ignored parameters from the body + +After all body assembly, before returning, strip the documented-ignored +keys (in case they were injected by `extra:` or merged in via metadata or +similar surprises): + +```ruby +IGNORED_KEYS = %i[top_k stop_sequences service_tier mcp_servers + context_management container].freeze + +def strip_ignored!(body) + IGNORED_KEYS.each do |k| + body.delete(k) + body.delete(k.to_s) + end +end +``` + +Call `strip_ignored!(body)` as the LAST step before `return body`. + +`IGNORED_KEYS` is module-level (top of the `RequestBuilder` module). + +### 6. Plumb the new kwargs from the adapter + +In `lib/dispatch/adapter/minimax.rb`, the `chat` and `count_tokens` +methods accept caller kwargs. They almost certainly already accept +`temperature:` and `top_p:` if they followed the Anthropic interface. If +not, add them and forward to `RequestBuilder.build`. Defaults: `nil`. + +DO NOT alter the temperature default behavior on the adapter — `nil` +means "don't send", which lets MiniMax pick its own server-side default. + +## Acceptance criteria + +- `grep -rn ':top_k\|:stop_sequences\|:service_tier\|:mcp_servers\|:context_management\|:container' lib/` should still match (the IGNORED_KEYS literal) but should NOT appear as keys in any built body. +- `RequestBuilder.build(temperature: 0.0, ...)` raises `ArgumentError`. +- `RequestBuilder.build(temperature: 1.01, ...)` raises `ArgumentError`. +- `RequestBuilder.build(temperature: -0.1, ...)` raises `ArgumentError`. +- `RequestBuilder.build(temperature: 0.5, ...)[:temperature]` is `0.5`. +- `RequestBuilder.build(temperature: 1.0, ...)[:temperature]` is `1.0`. +- `RequestBuilder.build(temperature: nil, ...).key?(:temperature)` is + `false`. +- `bundle exec rubocop --autocorrect-all` exits 0. + +## Verification + +Run `run_tests` with `project_path=reference/dispatch-adapter-minimax`. +Rubocop must be clean. `request_builder_spec.rb` failures referencing +`is_oauth` or expecting different shapes are acceptable (retargeted in +phase 13). New examples covering the temperature validation and ignored- +key stripping are NOT required here; phase 13 will add them. |
