Compare commits

..
2 Commits
Author SHA1 Message Date
infosave2007 4754e1a065 feat(cmf): per-model reasoning switch — 'thoughts: off' for thinking models
Docker / publish (push) Canceled after 0s
Release / crates-io (push) Canceled after 0s
Release / release (macos-14, aarch64-apple-darwin) (push) Canceled after 0s
Release / release (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Canceled after 0s
Release / release (windows-latest, x86_64-pc-windows-msvc) (push) Canceled after 0s
Each Local-models row gains a thoughts selector (auto/off). Off injects
enable_thinking=false (cortiq >= 0.2.1 renders the chat template with an empty
<think> block) into requests that don't set it themselves — the model answers
directly, faster and shorter. A client-supplied enable_thinking always wins.
2026-07-14 15:55:43 +03:00
infosave2007 3c4be5e966 feat(cmf): per-model generation defaults; safer delete-file default
Docker / publish (push) Canceled after 0s
Release / crates-io (push) Canceled after 0s
Release / release (macos-14, aarch64-apple-darwin) (push) Canceled after 0s
Release / release (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Canceled after 0s
Release / release (windows-latest, x86_64-pc-windows-msvc) (push) Canceled after 0s
- Each Local-models row gains default generation params — temperature, top-p,
  max tokens — applied by the gateway when the incoming request doesn't set
  them (an explicit request value always wins). Works for both the plain and
  streaming paths; top_p is now forwarded to OpenAI-compatible providers.
- The "also delete the model file from disk" checkbox in the delete dialog now
  defaults to UNCHECKED — deleting a pool entry no longer silently costs a
  multi-GB re-download/conversion.
2026-07-14 15:22:26 +03:00
9 changed files with 91 additions and 9 deletions
Generated
+1 -1
View File
@@ -285,7 +285,7 @@ checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
name = "cortiq-gateway"
version = "0.2.20"
version = "0.2.22"
dependencies = [
"anyhow",
"arc-swap",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "cortiq-gateway"
version = "0.2.20"
version = "0.2.22"
edition = "2021"
rust-version = "1.75"
license = "Apache-2.0"
+18
View File
@@ -89,6 +89,20 @@ pub struct CmfServer {
/// = force-enable on those layers.
#[serde(default)]
pub o1: String,
/// Default generation params for this model — applied by the gateway when
/// the incoming request does not set them (an explicit request value wins).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub top_p: Option<f32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub max_tokens: Option<u32>,
/// Reasoning switch for thinking models (Qwen3/3.5 …): "off" injects
/// enable_thinking=false into requests that don't set it themselves —
/// the model answers directly, skipping the <think> phase. Needs
/// cortiq ≥ 0.2.1. Empty = model/template default.
#[serde(default)]
pub thinking: String,
}
/// CMF-format model factory: import a HuggingFace model, convert it to a
@@ -179,6 +193,10 @@ impl CmfCfg {
threads: self.threads,
gpu: self.gpu,
o1: String::new(),
temperature: None,
top_p: None,
max_tokens: None,
thinking: String::new(),
}];
}
Vec::new()
+35 -2
View File
@@ -301,6 +301,35 @@ impl Pipeline {
Ok((decision, route_source, final_candidates))
}
/// Fill in the model's default generation params (from its Local-models row)
/// for anything the request left unset — an explicit request value wins.
fn apply_gen_defaults(req: &mut ChatRequest, cfg: &crate::config::Config, model_id: &str) {
if let Some(s) = cfg
.cmf
.effective_servers()
.into_iter()
.find(|s| s.id == model_id)
{
if req.params.temperature.is_none() {
req.params.temperature = s.temperature;
}
if req.params.top_p.is_none() {
req.params.top_p = s.top_p;
}
if req.params.max_tokens.is_none() {
req.params.max_tokens = s.max_tokens;
}
// reasoning switch: "off" → enable_thinking=false (cortiq ≥ 0.2.1
// renders the chat template with an empty <think> block); a client
// that sets enable_thinking itself wins.
if s.thinking == "off" && !req.params.passthrough.contains_key("enable_thinking") {
req.params
.passthrough
.insert("enable_thinking".into(), serde_json::Value::Bool(false));
}
}
}
async fn run_inner(&self, req: ChatRequest, state: &SharedState) -> Result<ChatResponse> {
let live = state.live();
let (decision, route_source, mut final_candidates) = self.resolve(&req, &live).await?;
@@ -341,7 +370,9 @@ impl Pipeline {
route_source
);
match provider.chat(req.clone()).await {
let mut attempt_req = req.clone();
Self::apply_gen_defaults(&mut attempt_req, &live.cfg, &model_id);
match provider.chat(attempt_req).await {
Ok(mut resp) => {
let cost =
provider.price(resp.usage.prompt_tokens, resp.usage.completion_tokens);
@@ -415,7 +446,9 @@ impl Pipeline {
model_id,
route_source
);
match provider.chat_stream(req.clone()).await {
let mut attempt_req = req.clone();
Self::apply_gen_defaults(&mut attempt_req, &live.cfg, &model_id);
match provider.chat_stream(attempt_req).await {
Ok(stream) => {
let info = RouteInfo {
task_label: decision.task_label.clone(),
+3
View File
@@ -45,6 +45,9 @@ impl OpenAiProvider {
if let Some(m) = req.params.max_tokens {
body["max_tokens"] = m.into();
}
if let Some(p) = req.params.top_p {
body["top_p"] = p.into();
}
if !req.tools.is_empty() {
body["tools"] = serde_json::Value::Array(req.tools.clone());
}
+7 -1
View File
@@ -264,7 +264,13 @@ export default {
"settings.cmf.pick": "select a model",
"settings.cmf.models": "Local models",
"settings.cmf.modelsHelp": "Each row is one model the gateway runs (its own cortiq serve on its own port) and registers in the pool. Add as many as you have .cmf files and free ports.",
"settings.cmf.rowHint": "id · .cmf file · port · threads · GPU · O(1). Applied on save: a removed row stops its server (memory freed), a new row starts one.",
"settings.cmf.rowHint": "id · .cmf file · port · threads · GPU · O(1) · T°/top-p/max tok. Applied on save: a removed row stops its server (memory freed), a new row starts one.",
"settings.cmf.thinkAuto": "thoughts: auto",
"settings.cmf.thinkOff": "thoughts: off",
"settings.cmf.thinkHelp": "Reasoning models (Qwen3/3.5) write out a thinking phase before the answer. Off = answer directly without it (faster, shorter; needs cortiq >= 0.2.1). A request that sets enable_thinking itself always wins.",
"settings.cmf.tempHelp": "Default temperature for this model (0 = deterministic, 0.7 = balanced, >1 = creative). Used when the request doesn't set one; a request value always wins. Empty = provider default.",
"settings.cmf.topPHelp": "Default nucleus sampling (top-p) for this model: only tokens within this cumulative probability are sampled (0.9 typical). Empty = provider default.",
"settings.cmf.maxTokHelp": "Default max output tokens for this model when the request doesn't set one. Protects against runaway long generations. Empty = provider default.",
"settings.cmf.o1Auto": "O(1): auto",
"settings.cmf.o1Help": "O(1) attention at serve time: auto — follow the hint recorded in the .cmf; off — force exact attention (fixes incoherent output after a too-aggressive --o1 conversion, no re-convert needed); all/deepN — force-enable on those layers.",
"settings.cmf.addServer": "+ Add local model",
+7 -1
View File
@@ -263,7 +263,13 @@ export default {
"settings.cmf.pick": "выберите модель",
"settings.cmf.models": "Локальные модели",
"settings.cmf.modelsHelp": "Каждая строка — отдельная модель: шлюз поднимает свой cortiq serve на своём порту и регистрирует её в пуле. Добавляйте столько, сколько есть .cmf-файлов и свободных портов.",
"settings.cmf.rowHint": "id · файл .cmf · порт · потоки · GPU · O(1). Применяется сразу при сохранении: удалённая строка останавливает сервер (память освобождается), новая — запускает.",
"settings.cmf.rowHint": "id · файл .cmf · порт · потоки · GPU · O(1) · T°/top-p/max tok. Применяется сразу при сохранении: удалённая строка останавливает сервер (память освобождается), новая — запускает.",
"settings.cmf.thinkAuto": "мысли: авто",
"settings.cmf.thinkOff": "мысли: выкл",
"settings.cmf.thinkHelp": "Рассуждающие модели (Qwen3/3.5) сначала пишут фазу размышлений. Выкл = отвечать сразу, без неё (быстрее и короче; нужен cortiq ≥ 0.2.1). Если запрос сам задал enable_thinking — он важнее.",
"settings.cmf.tempHelp": "Температура по умолчанию для этой модели (0 = детерминированно, 0.7 = баланс, >1 = креативно). Подставляется, если запрос её не задал; значение из запроса всегда важнее. Пусто = дефолт провайдера.",
"settings.cmf.topPHelp": "Nucleus-сэмплинг (top-p) по умолчанию: выбираются только токены в пределах этой суммарной вероятности (обычно 0.9). Пусто = дефолт провайдера.",
"settings.cmf.maxTokHelp": "Максимум выходных токенов по умолчанию, если запрос не задал свой. Защищает от бесконечных генераций. Пусто = дефолт провайдера.",
"settings.cmf.o1Auto": "O(1): авто",
"settings.cmf.o1Help": "O(1)-внимание при запуске: авто — использовать подсказку из .cmf; off — принудительно точное внимание (лечит бессвязный вывод после слишком агрессивной --o1 конвертации, без переконвертации); all/deepN — принудительно включить на этих слоях.",
"settings.cmf.addServer": "+ Добавить модель",
+3 -1
View File
@@ -283,7 +283,9 @@ function row(m, meta, reload) {
onClick: () => {
// local models may have a .cmf on disk — let the user decide its fate
const isLocal = m.managed || /127\.0\.0\.1|localhost/.test(m.base_url || "");
const fileCb = h("input", { type: "checkbox", checked: isLocal ? true : null });
// unchecked by default: deleting a pool entry should not silently
// cost the user a multi-GB re-download/conversion
const fileCb = h("input", { type: "checkbox" });
const body = h(
"div",
{},
+16 -2
View File
@@ -240,6 +240,14 @@ export async function renderSettings() {
...o1Opts.map((v) => h("option", { value: v, selected: (sv.o1 || "") === v ? true : null },
v === "" ? t("settings.cmf.o1Auto") : v)));
if (sv.o1 && !o1Opts.includes(sv.o1)) o1In.appendChild(h("option", { value: sv.o1, selected: true }, sv.o1));
// reasoning switch for thinking models (off → enable_thinking=false)
const thinkIn = h("select", { style: "width:118px", title: t("settings.cmf.thinkHelp") },
h("option", { value: "", selected: !sv.thinking ? true : null }, t("settings.cmf.thinkAuto")),
h("option", { value: "off", selected: sv.thinking === "off" ? true : null }, t("settings.cmf.thinkOff")));
// per-model generation defaults (applied when the request doesn't set them)
const tempIn = h("input", { type: "number", step: "0.1", min: 0, max: 2, value: sv.temperature ?? "", placeholder: "T° 0.7", style: "width:74px", title: t("settings.cmf.tempHelp") });
const topPIn = h("input", { type: "number", step: "0.05", min: 0, max: 1, value: sv.top_p ?? "", placeholder: "top-p", style: "width:70px", title: t("settings.cmf.topPHelp") });
const maxTokIn = h("input", { type: "number", min: 1, value: sv.max_tokens ?? "", placeholder: "max tok", style: "width:82px", title: t("settings.cmf.maxTokHelp") });
const checkBtn = h("button", { class: "btn small", type: "button" }, t("settings.cmf.checkPort"));
const removeBtn = h("button", { class: "btn small danger", type: "button", title: t("common.delete") }, "✕");
const st = h("span", { class: "small" });
@@ -264,8 +272,14 @@ export async function renderSettings() {
checkBtn.disabled = false;
});
const row = h("div", { class: "flex wrap", style: "gap:6px;align-items:center;margin:6px 0" },
idIn, modelSel, portIn, checkBtn, threadsIn, h("label", { class: "flex", style: "gap:4px" }, gpuIn, "GPU"), o1In, removeBtn, st);
const entry = { node: row, read: () => ({ id: idIn.value.trim() || autoId(modelSel.value), model: modelSel.value.trim(), port: parseInt(portIn.value) || 8090, threads: parseInt(threadsIn.value) || 0, gpu: gpuIn.checked, o1: o1In.value }) };
idIn, modelSel, portIn, checkBtn, threadsIn, h("label", { class: "flex", style: "gap:4px" }, gpuIn, "GPU"), o1In, thinkIn, tempIn, topPIn, maxTokIn, removeBtn, st);
const entry = { node: row, read: () => {
const v = { id: idIn.value.trim() || autoId(modelSel.value), model: modelSel.value.trim(), port: parseInt(portIn.value) || 8090, threads: parseInt(threadsIn.value) || 0, gpu: gpuIn.checked, o1: o1In.value, thinking: thinkIn.value };
if (tempIn.value !== "") v.temperature = parseFloat(tempIn.value);
if (topPIn.value !== "") v.top_p = parseFloat(topPIn.value);
if (maxTokIn.value !== "") v.max_tokens = parseInt(maxTokIn.value);
return v;
} };
removeBtn.addEventListener("click", () => { const i = serverRows.indexOf(entry); if (i >= 0) serverRows.splice(i, 1); row.remove(); });
serverRows.push(entry);
serversWrap.appendChild(row);