feat: select playground reasoning effort with compatible fallback (#1096)
This commit is contained in:
@ -46,6 +46,7 @@ pub(super) async fn page(State(state): State<Arc<AppState>>, headers: HeaderMap)
|
||||
format!(
|
||||
"<section class=\"card\" id=\"chat\">\
|
||||
<div class=\"zeile\"><label>Modell <select id=\"chat-modell\">{options}</select></label>\
|
||||
<label>Denkstufe <select id=\"chat-denkstufe\"><option value=\"\">Engine-Voreinstellung</option><option value=\"none\">aus</option><option value=\"low\">niedrig</option><option value=\"medium\" selected>mittel</option><option value=\"high\">hoch</option></select></label>\
|
||||
<label>Max. Tokens <input id=\"chat-max\" type=\"number\" min=\"1\" max=\"{MAX_TOKENS_LIMIT}\" value=\"{DEFAULT_MAX_TOKENS}\"></label>\
|
||||
<span class=\"rechts\"><button class=\"sm\" type=\"button\" id=\"chat-neu\">Neuer Chat</button></span></div>\
|
||||
<div class=\"verlauf\" id=\"chat-verlauf\" aria-live=\"polite\"></div>\
|
||||
@ -95,13 +96,20 @@ pub(crate) fn build_request(input: &Value) -> Result<Value, &'static str> {
|
||||
.and_then(Value::as_u64)
|
||||
.unwrap_or(DEFAULT_MAX_TOKENS)
|
||||
.clamp(1, MAX_TOKENS_LIMIT);
|
||||
Ok(json!({
|
||||
let mut request = json!({
|
||||
"model": model,
|
||||
"messages": clean,
|
||||
"max_tokens": max_tokens,
|
||||
"stream": true,
|
||||
"stream_options": { "include_usage": true },
|
||||
}))
|
||||
});
|
||||
if let Some(effort) = input.get("reasoning_effort") {
|
||||
if !matches!(effort.as_str(), Some("none" | "low" | "medium" | "high")) {
|
||||
return Err("Die Denkstufe ist ungültig.");
|
||||
}
|
||||
request["reasoning_effort"] = effort.clone();
|
||||
}
|
||||
Ok(request)
|
||||
}
|
||||
|
||||
pub(super) async fn send(
|
||||
@ -210,6 +218,7 @@ const CHAT_JS: &str = r#"(function () {
|
||||
var senden = document.getElementById("chat-senden");
|
||||
var modell = document.getElementById("chat-modell");
|
||||
var max = document.getElementById("chat-max");
|
||||
var denkstufe = document.getElementById("chat-denkstufe");
|
||||
var messages = [];
|
||||
var laufend = null;
|
||||
|
||||
@ -232,6 +241,7 @@ const CHAT_JS: &str = r#"(function () {
|
||||
senden.disabled = an;
|
||||
stopp.hidden = !an;
|
||||
modell.disabled = an;
|
||||
denkstufe.disabled = an;
|
||||
}
|
||||
|
||||
function sekunden(seit) {
|
||||
@ -248,6 +258,7 @@ const CHAT_JS: &str = r#"(function () {
|
||||
var denken = null;
|
||||
var gesamt = "";
|
||||
var usage = null;
|
||||
var denkstufeIgnoriert = false;
|
||||
var beginn = Date.now();
|
||||
var erstes = null;
|
||||
var abbruch = new AbortController();
|
||||
@ -292,6 +303,7 @@ const CHAT_JS: &str = r#"(function () {
|
||||
if (!denken) { antwort.el.remove(); }
|
||||
}
|
||||
var teile = [];
|
||||
if (denkstufeIgnoriert) { teile.push("Denkstufe nicht unterstützt, Engine-Voreinstellung verwendet"); }
|
||||
if (abgebrochen) { teile.push("abgebrochen"); }
|
||||
if (erstes !== null) { teile.push("erstes Stück nach " + ((erstes - beginn) / 1000).toFixed(1).replace(".", ",") + " s"); }
|
||||
teile.push("gesamt " + sekunden(beginn));
|
||||
@ -332,9 +344,10 @@ const CHAT_JS: &str = r#"(function () {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
headers: { "content-type": "application/json", "x-csrf-token": csrf },
|
||||
body: JSON.stringify({ model: modell.value, max_tokens: parseInt(max.value, 10) || undefined, messages: messages }),
|
||||
body: JSON.stringify({ model: modell.value, max_tokens: parseInt(max.value, 10) || undefined, reasoning_effort: denkstufe.value || undefined, messages: messages }),
|
||||
signal: abbruch.signal
|
||||
}).then(function (r) {
|
||||
denkstufeIgnoriert = r.headers.get("x-nexus-reasoning-effort") === "ignored";
|
||||
if (!r.ok) {
|
||||
return r.text().then(function (t) {
|
||||
var meldung = "Fehler " + r.status;
|
||||
@ -381,6 +394,7 @@ const CHAT_JS: &str = r#"(function () {
|
||||
document.getElementById("chat-neu").addEventListener("click", function () {
|
||||
if (laufend) { laufend.abort(); }
|
||||
messages = [];
|
||||
denkstufe.value = "medium";
|
||||
verlauf.textContent = "";
|
||||
status.textContent = "";
|
||||
text.focus();
|
||||
@ -393,6 +407,27 @@ const CHAT_JS: &str = r#"(function () {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn denkstufe_ist_optional_und_nur_bekannte_werte_sind_erlaubt() {
|
||||
let base = json!({"model":"m", "messages":[{"role":"user","content":"x"}]});
|
||||
assert!(
|
||||
build_request(&base)
|
||||
.unwrap()
|
||||
.get("reasoning_effort")
|
||||
.is_none()
|
||||
);
|
||||
for effort in ["none", "low", "medium", "high"] {
|
||||
let mut input = base.clone();
|
||||
input["reasoning_effort"] = json!(effort);
|
||||
assert_eq!(build_request(&input).unwrap()["reasoning_effort"], effort);
|
||||
}
|
||||
for effort in [json!("max"), json!(null), json!(7)] {
|
||||
let mut input = base.clone();
|
||||
input["reasoning_effort"] = effort;
|
||||
assert!(build_request(&input).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn anfrage_enthaelt_nur_bekannte_felder_und_ist_immer_ein_stream() {
|
||||
let request = build_request(&json!({
|
||||
|
||||
Reference in New Issue
Block a user