From 862c1e9743755e7dfcdcc9648ca2ce07369602d1 Mon Sep 17 00:00:00 2001 From: m4 Date: Thu, 30 Jul 2026 09:29:06 +0800 Subject: [PATCH] docs(registry): supersede flat temperature/top_p overrides with mutually-exclusive sampling_override temperature and top_p cannot be set together; the flat-fields design allowed both. Replaced by a discriminated union (default | temperature | top_p) where overriding one omits the other from the request entirely. Co-Authored-By: Claude Opus 4.7 --- ...hread-generation-param-overrides-design.md | 4 +- .../2026-07-30-sampling-override-design.md | 142 ++++++++++++++++++ 2 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 docs/superpowers/specs/2026-07-30-sampling-override-design.md diff --git a/docs/superpowers/specs/2026-07-28-thread-generation-param-overrides-design.md b/docs/superpowers/specs/2026-07-28-thread-generation-param-overrides-design.md index 2730efa..50d0528 100644 --- a/docs/superpowers/specs/2026-07-28-thread-generation-param-overrides-design.md +++ b/docs/superpowers/specs/2026-07-28-thread-generation-param-overrides-design.md @@ -1,7 +1,9 @@ # 会话级生成参数覆盖(temperature / top_p)设计 日期:2026-07-28 -状态:已批准(方案 A) +状态:已被取代 — temperature/top_p 平铺字段方案存在互斥缺陷(temperature +与 top_p 不能同时覆盖),由 2026-07-30-sampling-override-design.md +(判别联合方案)替代。本文件仅作历史留存。 ## 背景与目标 diff --git a/docs/superpowers/specs/2026-07-30-sampling-override-design.md b/docs/superpowers/specs/2026-07-30-sampling-override-design.md new file mode 100644 index 0000000..045838d --- /dev/null +++ b/docs/superpowers/specs/2026-07-30-sampling-override-design.md @@ -0,0 +1,142 @@ +# 会话级采样参数覆盖互斥(sampling_override)设计 + +日期:2026-07-30 +状态:已批准(方案 B,判别联合) +取代:2026-07-28-thread-generation-param-overrides-design.md 中 +temperature/top_p 平铺字段方案(该方案已落地,本次为修订重写) + +## 背景与目标 + +temperature 与 top_p 是互斥的采样参数:主流 provider(Anthropic、OpenAI +等)要求一次请求只调整其一,同时发送两者会被拒绝或行为未定义。2026-07-28 +的设计允许两个滑块独立覆盖、同时冻结进快照,这是错误的。 + +本设计把会话级采样覆盖改为**判别联合**:用户三选一——**默认(不设置)/ +temperature / top_p**,结构上同一时刻至多覆盖一个;覆盖其一时,另一个 +参数连同注册表默认值一起从请求中省略。 + +非目标:不改注册表默认值编辑路径;registry 自身同时配置两个默认值的行为 +维持现状(属于注册表配置者的责任);不覆盖 auxiliary/vision 角色。 + +## 方案 + +### 1. 数据模型(全链路统一命名 `sampling_override`) + +WebUI(`EvoScientist-WebUI/src/lib/modelRegistry.ts`): + +```ts +type SamplingOverride = + | { kind: "temperature"; value: number } // 0–2 + | { kind: "top_p"; value: number }; // (0,1] + +type ThreadModelSelection = + | "inherit" + | { + primary: ModelRef; + reasoning_effort?: ReasoningEffort | null; + sampling_override?: SamplingOverride | null; // null = 注册表默认 + }; +``` + +后端(`EvoScientist/model_registry/snapshots.py`)`SnapshotCreateRequest` +移除平铺 `temperature`/`top_p` 字段,替换为: + +```python +class SamplingOverride(BaseModel): + kind: Literal["temperature", "top_p"] + value: float # model validator 按 kind 校验:temperature ∈ [0,2];top_p ∈ (0,1] + +sampling_override: SamplingOverride | None = None +``` + +- 线程元数据 `model_selection` 携带新形状;`useChat` 的元数据读取镜像同步。 +- **旧的平铺 `temperature`/`top_p` 元数据键容忍并丢弃**(与 legacy + `auxiliary` 一致),不做迁移;功能上线时间短,用户重设一次即可。 +- `inherit` 模式:与推理滑块一致,不允许携带覆盖(BFF parse 拒绝)。 + +### 2. resolver 语义(核心) + +`ModelResolver.resolve()` 与 `resolve_parameters()` 的 +`temperature_override`/`top_p_override` 两个 kwargs 替换为单个 +`sampling_override: SamplingOverride | None`: + +- `kind="temperature"` → temperature 取覆盖值、走 adapter `ParameterRule` + 契约校验;**top_p 直接 `OMIT`**——不继承 model 值也不继承 provider 默认, + 请求里整个不出现。 +- `kind="top_p"` → 对称处理,temperature `OMIT`。 +- `None` → 维持现状(注册表默认照常继承,可能两者都发)。 + +`compute_selection_hash(primary, reasoning_effort, sampling_override)`: +override 序列化为 `{"kind": ..., "value": ...}` 或 `null`。旧 hash 自然失效 +生成新快照,无需迁移。 + +快照 payload 的 `request_options` 结构不变,只改值来源。 + +### 3. BFF 与 runs 路由 + +- `parseThreadModelSelection`(`src/lib/server/threadModelSelection.ts`) + 按 kind 校验 value 范围(temperature 0–2;top_p (0,1]);kind 非法、value + 越界/非有限数 → 400。模型级契约(如 Anthropic temperature ≤ 1)不在 BFF + 硬编码,留给快照创建时 adapter 校验。 +- runs 路由 POST `/api/runtime-snapshots` 的 body 把两个平铺字段换成 + `sampling_override`(inherit 或无覆盖时为 null)。 +- CAS PATCH 端点不变,`model_selection_revision` 照常递增。 + +### 4. 聊天栏 UI + +模型名旁放分段选择器(segmented control;小屏