feat(models): 模型映射新增最大输出 Token 列(max_output_size 直写 config.toml,models.dev 参考值一键填入/空值自动补全),移除无效的声明支持 1M 复选框;思考等级顺序修正为 low/medium/high/xhigh/max 且标签全英文 — bump to v0.8.0
Release / Version consistency (push) Canceled after 0s
Release / Build (macos-latest) (push) Canceled after 0s
Release / Build (ubuntu-latest) (push) Canceled after 0s
Release / Build (windows-latest) (push) Canceled after 0s
Release / Attach macOS install script (push) Canceled after 0s
Release / Version consistency (push) Canceled after 0s
Release / Build (macos-latest) (push) Canceled after 0s
Release / Build (ubuntu-latest) (push) Canceled after 0s
Release / Build (windows-latest) (push) Canceled after 0s
Release / Attach macOS install script (push) Canceled after 0s
This commit is contained in:
1 parent
30371a1ba6
commit
3c3c18925d
19 files changed
+412
-38
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import type { Model } from "../types";
|
||||
|
||||
/**
|
||||
* Helpers for the `max_output_size` model field.
|
||||
*
|
||||
* kimi-code keeps it in `[models."<alias>"] max_output_size`; it is not a
|
||||
* first-class field of Kimi Switch's Rust `Model` struct, so it round-trips
|
||||
* through `raw_other` (the pass-through bucket for unknown keys). Absent key =
|
||||
* unset = the upstream default applies, so clearing the field removes the key
|
||||
* rather than writing 0.
|
||||
*/
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> {
|
||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/** Read the override; undefined when absent or malformed (treated as unset). */
|
||||
export function readMaxOutputSize(rawOther: unknown): number | undefined {
|
||||
const value = asRecord(rawOther).max_output_size;
|
||||
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Parse the number input: blank / 0 / NaN mean "unset". */
|
||||
export function parseMaxOutputInput(text: string): number | undefined {
|
||||
const value = parseInt(text, 10);
|
||||
if (isNaN(value) || value <= 0) return undefined;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set (positive value) or drop (undefined) `max_output_size` on a raw_other
|
||||
* blob; every other preserved key is kept.
|
||||
*/
|
||||
export function setMaxOutputSize(
|
||||
rawOther: unknown,
|
||||
value: number | undefined,
|
||||
): Record<string, unknown> {
|
||||
const next = { ...asRecord(rawOther) };
|
||||
if (value === undefined) {
|
||||
delete next.max_output_size;
|
||||
} else {
|
||||
next.max_output_size = Math.floor(value);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/** Immutable update of a model entry's max_output_size override. */
|
||||
export function withMaxOutputSize(
|
||||
model: Model,
|
||||
value: number | undefined,
|
||||
): Model {
|
||||
return { ...model, raw_other: setMaxOutputSize(model.raw_other, value) };
|
||||
}
|
||||
Reference in new issue
Block a user