Repository navigation
Conversation
…ia upstream query and models.dev catalog, remove auto cap - 新增模型目录服务:启动后后台同步 models.dev(缓存到 ~/.deva,24h 刷新,失败回退缓存),并在服务商拉取模型清单时顺带采信 /models 响应里的 context_length / max_model_len / num_ctx 等真实字段 / add a model catalog service that syncs models.dev in the background (cached in ~/.deva, refreshed every 24h, falling back to cache) and picks up real context fields (context_length / max_model_len / num_ctx) from /models responses during model list fetch - contextWindowFor 分层改为:用户填写 > 上游 / models.dev > 内置正则表兜底 > 全局默认,报错学习值仍在最后取小 / reorder contextWindowFor priority to user override > upstream/models.dev > builtin rules fallback > global default, with learned error limits still applied last - 废除 AUTO_WINDOW_CAP:gemini / glm-5.x / deepseek-v4 等 1M 模型不再被压成 256K,本地小模型的保守值由内置表条目自身覆盖 / remove AUTO_WINDOW_CAP so 1M models like gemini / glm-5.x / deepseek-v4 are no longer capped to 256K, while local small models stay conservative via their own builtin entries - 模型详情页「自动」窗口改用主进程目录值,拿不到回退本地离线推断 / model detail page now shows the catalog-backed auto window, falling back to offline inference Closes sqfcyily#92
…ovider-aware catalog, upstream persistence, input vs context semantics - P1-01 models.dev 索引保留服务商维度,按 API 端点 host 匹配具体服务商取其声明值;跨服务商推断时取最小值,不再无条件混用最大窗口 / keep the provider dimension in the models.dev index and match by API endpoint host; fall back to the minimum across providers instead of mixing the maximum window - P1-02 上游 /models 窗口持久化到 ~/.deva/upstream-windows.json,重启后仍有效 / persist upstream /models windows to ~/.deva/upstream-windows.json so they survive restarts - P1-03 上游缓存按 apiHost 隔离并在每次成功拉取时整体替换该端点记录,换中转后旧值不残留 / scope upstream cache by apiHost and replace the endpoint record on each successful fetch so stale values do not leak across endpoint changes - P2-01 区分输入上限与总窗口:压缩线改为 min(input, context − output) − buffer,目录数据含独立输入上限时不再重复扣输出 / distinguish input limit from total context: compute the compaction line as min(input, context − output) − buffer so a declared input limit is not double-charged for output - P2-02 拉取 models.dev 后先验证能解析出有效模型条目再替换内存与磁盘缓存,避免无效响应清空好缓存 / validate that a fetched models.dev payload yields entries before replacing memory and disk cache, so an invalid response cannot clobber a good cache
|
已按 review 修复三个 P1 与两个 P2 问题(commit P1-01 跨服务商窗口混用 — models.dev 索引现保留服务商维度( P1-02 上游窗口重启丢失 — 上游 P1-03 端点更换后旧缓存残留 — 上游缓存改为按 P2-01 输入上限与总窗口语义 — 核实了 models.dev 语义: P2-02 无效目录覆盖缓存 — 拉取 models.dev 后先在副本上解析、确认能产出有效模型条目才替换内存索引与磁盘缓存;解析为空则保留旧缓存不写盘。 验证: 说明 / 未做:
|
…endpoint-scoped cache with port/path, full output wiring, cache protection - P1 上游缓存与 models.dev 端点匹配改用 origin+pathname(含协议、端口、路径)作为隔离键,本机并存的 Ollama/vLLM 等同 host 不同端口服务不再互相覆盖,同 host 不同路径的网关也各自独立 / scope upstream cache and models.dev endpoint matching by origin+pathname (scheme, port, path) so co-located local services like Ollama/vLLM on the same host but different ports, and gateways splitting upstreams by path, no longer overwrite each other - P1 models.dev 的 limit.output 完整接入输出预算:压缩线与实际 max_tokens 同序(用户手填 > 供应商声明 output > 协议默认 > 报错学习),避免压缩线低估输出预留而过晚压缩、请求撞限 / wire models.dev limit.output into the output budget with the same precedence in both the compaction line and the actual max_tokens (user override > declared output > protocol default > learned), so the compaction line no longer under-reserves output - P2 跨服务商匹配保留完整 input/context/output 记录(取 input 最小的那条),不再令 context=input 导致重复扣输出、提前压缩 / keep the full input/context/output record when matching across providers (the one with the smallest input) instead of forcing context=input and double-charging output - P2 上游 /models 仅在确认识别为有效清单(含合法空列表)时才替换缓存,解析失败/HTML 错误页/结构异常保留 last-known-good / only replace the upstream cache when the response is a recognizable model list (including a legitimately empty one); parse failures, HTML error pages and malformed structures keep the last-known-good data - P2 UI 统一显示输入上限:用量面板与模型设置页的「上下文窗口」均用 inputWindowFor(与压缩触发线同口径)/ unify the UI on the input limit: both the usage panel and the model settings page show inputWindowFor, consistent with the compaction trigger line - 健壮性:models.dev 磁盘缓存改为惰性且幂等恢复,不强依赖后台同步的调用时序 / make the models.dev disk cache restore lazy and idempotent so it does not depend on background-sync timing
|
第二轮 review 的两个 P1、三个 P2 已全部修复(commit P1 缓存忽略端口/路径 — 端点隔离键从 P1 models.dev output 未参与运行 — P2 跨服务商丢失总窗口 — 跨服务商匹配现保留完整 P2 异常响应清空缓存 — 上游 P2 UI 语义不一致 — 统一为输入上限:用量面板与模型设置页的「上下文窗口」均改用 顺带修了一个健壮性缺口:models.dev 磁盘缓存改为惰性 + 幂等恢复( 验证: |
实现 issue #92 的分层上下文窗口识别
把硬编码正则表从「唯一来源」降级为「离线兜底」,新增两个持续更新、贴合上游的真实数据源,并废除把 1M 模型压成 256K 的
AUTO_WINDOW_CAP。分层优先级(
contextWindowFor)改动内容
main/services/model-catalog.ts:启动后后台拉取models.dev/api.json(实测 3923 个模型),缓存到~/.deva/models-dev-cache.json,每 24h 刷新,失败沿用缓存。上游/models字段与 models.dev 统一索引,提供catalogContextWindow()。provider.ts:拉模型清单时顺带提取每个模型的context_length(OpenRouter)/max_model_len(vLLM)/num_ctx(Ollama)/context_window等字段写入目录——零额外请求。明确排除max_tokens(输出上限,不是窗口)。shared/context.ts:废除AUTO_WINDOW_CAP与capAutoWindow,autoContextWindow()返回不封顶值。本地小模型的保守值由内置表自身条目覆盖(qwen3:8b40K、llama32K),不依赖封顶。ModelDetail.tsx:「自动」窗口改经model:catalog-windowIPC 用主进程目录值,拿不到回退本地离线推断。验证
pnpm typecheck(node + web)通过。shared/context.ts离线推断用例核对:gemini-4 → 1M、deepseek-v4-flash → 1M、gpt-5 → 272K、kimi-k3 → 1M、qwen3:8b → 40K、未知模型 → 128K(均符合预期)。max_tokens正确排除。说明
rememberContextLimit学习值的 UI 展示与清除、设置里标注窗口来源)属于独立改进,可另开 issue。AUTO_WINDOW_CAP的移除是行为变更:部分用户的压缩阈值会显著变晚(更贴近真实窗口)。这正是 [Feature] 上下文窗口识别:从硬编码正则表转向「上游查询 + 公共模型数据库」 #92 的目标,但如你希望对正则表命中值保留封顶、仅对上游/数据库的真实值放开,我可以调整。build:linux打包耗时长),仅做了 typecheck 与逻辑验证。Closes #92