SPEAKER stamp in server-local time (drop UTC); round first-token lag badge to nearest second
This commit is contained in:
1 parent
95c41c2c21
commit
d1b56d2c23
6 files changed
+67
-21
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"identity.name": "Your name is {name}.",
|
"identity.name": "Your name is {name}.",
|
||||||
"identity.folder": " Your personal folder is {folder}.",
|
"identity.folder": " Your personal folder is {folder}.",
|
||||||
"speaker.tag": "[SPEAKER: {name} - {when}]",
|
"speaker.tag": "[SPEAKER: {name} - {when}]",
|
||||||
"speaker.note": " User and agent turns are prefixed with a [SPEAKER: name - date and time UTC] tag identifying who generated them and when.",
|
"speaker.note": " User and agent turns are prefixed with a [SPEAKER: name - local date and time] tag identifying who generated them and when.",
|
||||||
"error.name_locked": "The session name is immutable after the first interaction.",
|
"error.name_locked": "The session name is immutable after the first interaction.",
|
||||||
"error.name_empty": "The name must not be empty.",
|
"error.name_empty": "The name must not be empty.",
|
||||||
"error.session_not_found": "Session not found.",
|
"error.session_not_found": "Session not found.",
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"identity.name": "Il tuo nome è {name}.",
|
"identity.name": "Il tuo nome è {name}.",
|
||||||
"identity.folder": " La tua cartella personale è {folder}.",
|
"identity.folder": " La tua cartella personale è {folder}.",
|
||||||
"speaker.tag": "[SPEAKER: {name} - {when}]",
|
"speaker.tag": "[SPEAKER: {name} - {when}]",
|
||||||
"speaker.note": " I turni dell'utente e dell'agente sono preceduti da un tag [SPEAKER: nome - data e ora UTC] che identifica chi li ha generati e quando.",
|
"speaker.note": " I turni dell'utente e dell'agente sono preceduti da un tag [SPEAKER: nome - data e ora locale] che identifica chi li ha generati e quando.",
|
||||||
"error.name_locked": "Il nome della sessione è immutabile dopo la prima interazione.",
|
"error.name_locked": "Il nome della sessione è immutabile dopo la prima interazione.",
|
||||||
"error.name_empty": "Il nome non può essere vuoto.",
|
"error.name_empty": "Il nome non può essere vuoto.",
|
||||||
"error.session_not_found": "Sessione non trovata.",
|
"error.session_not_found": "Sessione non trovata.",
|
||||||
|
|||||||
+62
-16
@@ -243,29 +243,60 @@ fn text_message(role: Role, text: String) -> ChatMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The `[SPEAKER: name - datetime]` line prefixed to a turn's content in the
|
/// The `[SPEAKER: name - datetime]` line prefixed to a turn's content in the
|
||||||
/// model prompt (provenance), followed by a newline.
|
/// model prompt (provenance), followed by a newline. `offset` is the server's
|
||||||
fn speaker_prefix(name: &str, secs: i64) -> String {
|
/// UTC offset in seconds, so the stamp is in the server's local timezone.
|
||||||
|
fn speaker_prefix(name: &str, secs: i64, offset: i64) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{}\n",
|
"{}\n",
|
||||||
t(
|
t(
|
||||||
"speaker.tag",
|
"speaker.tag",
|
||||||
&[("name", name), ("when", &format_utc(secs))]
|
&[("name", name), ("when", &format_stamp(secs, offset))]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format unix seconds as a compact, unambiguous UTC datetime (no chrono dep).
|
/// Format unix seconds as `YYYY-MM-DD HH:MM` in the server's local timezone
|
||||||
fn format_utc(secs: i64) -> String {
|
/// (`offset` seconds east of UTC). Dependency-free civil-date arithmetic.
|
||||||
let days = secs.div_euclid(86400);
|
fn format_stamp(secs: i64, offset: i64) -> String {
|
||||||
let tod = secs.rem_euclid(86400);
|
let local = secs + offset;
|
||||||
|
let days = local.div_euclid(86400);
|
||||||
|
let tod = local.rem_euclid(86400);
|
||||||
let (y, m, d) = civil_from_days(days);
|
let (y, m, d) = civil_from_days(days);
|
||||||
format!(
|
format!(
|
||||||
"{y:04}-{m:02}-{d:02} {:02}:{:02} UTC",
|
"{y:04}-{m:02}-{d:02} {:02}:{:02}",
|
||||||
tod / 3600,
|
tod / 3600,
|
||||||
(tod % 3600) / 60
|
(tod % 3600) / 60
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The server's current UTC offset in seconds, from the OS `date +%z` (reads the
|
||||||
|
/// system timezone incl. DST). One cheap call per request build; 0 (UTC) on fail.
|
||||||
|
fn server_utc_offset_secs() -> i64 {
|
||||||
|
std::process::Command::new("date")
|
||||||
|
.arg("+%z")
|
||||||
|
.output()
|
||||||
|
.ok()
|
||||||
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
||||||
|
.and_then(|s| parse_utc_offset(s.trim()))
|
||||||
|
.unwrap_or(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse `date +%z` output ("+0100", "-0500") into seconds east of UTC.
|
||||||
|
fn parse_utc_offset(s: &str) -> Option<i64> {
|
||||||
|
let b = s.as_bytes();
|
||||||
|
if b.len() != 5 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let sign = match b[0] {
|
||||||
|
b'+' => 1,
|
||||||
|
b'-' => -1,
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
let hh: i64 = s.get(1..3)?.parse().ok()?;
|
||||||
|
let mm: i64 = s.get(3..5)?.parse().ok()?;
|
||||||
|
Some(sign * (hh * 3600 + mm * 60))
|
||||||
|
}
|
||||||
|
|
||||||
/// Days since 1970-01-01 -> (year, month, day). Howard Hinnant's algorithm.
|
/// Days since 1970-01-01 -> (year, month, day). Howard Hinnant's algorithm.
|
||||||
fn civil_from_days(z: i64) -> (i64, u32, u32) {
|
fn civil_from_days(z: i64) -> (i64, u32, u32) {
|
||||||
let z = z + 719468;
|
let z = z + 719468;
|
||||||
@@ -291,6 +322,8 @@ fn build_request(
|
|||||||
user_name: &str,
|
user_name: &str,
|
||||||
) -> ChatRequest {
|
) -> ChatRequest {
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
|
// Server-local timezone offset, computed once for every turn in this request.
|
||||||
|
let tz_offset = server_utc_offset_secs();
|
||||||
// Structural identity reminder: always present, not an editable setting. It
|
// Structural identity reminder: always present, not an editable setting. It
|
||||||
// tells the agent its name and personal workspace folder.
|
// tells the agent its name and personal workspace folder.
|
||||||
let mut identity = t("identity.name", &[("name", &sess.title)]);
|
let mut identity = t("identity.name", &[("name", &sess.title)]);
|
||||||
@@ -308,8 +341,16 @@ fn build_request(
|
|||||||
// Tool/system turns stay untagged. This annotates the prompt only —
|
// Tool/system turns stay untagged. This annotates the prompt only —
|
||||||
// stored content stays clean (the GUI shows its own timestamp).
|
// stored content stays clean (the GUI shows its own timestamp).
|
||||||
let content = match m.role.as_str() {
|
let content = match m.role.as_str() {
|
||||||
"user" => format!("{}{}", speaker_prefix(user_name, m.created_at), m.content),
|
"user" => format!(
|
||||||
"assistant" => format!("{}{}", speaker_prefix(&sess.title, m.created_at), m.content),
|
"{}{}",
|
||||||
|
speaker_prefix(user_name, m.created_at, tz_offset),
|
||||||
|
m.content
|
||||||
|
),
|
||||||
|
"assistant" => format!(
|
||||||
|
"{}{}",
|
||||||
|
speaker_prefix(&sess.title, m.created_at, tz_offset),
|
||||||
|
m.content
|
||||||
|
),
|
||||||
_ => m.content.clone(),
|
_ => m.content.clone(),
|
||||||
};
|
};
|
||||||
let mut msg = text_message(role_of(&m.role), content);
|
let mut msg = text_message(role_of(&m.role), content);
|
||||||
@@ -324,7 +365,7 @@ fn build_request(
|
|||||||
// the Vision bridge materializes; without images it stays a plain string.
|
// the Vision bridge materializes; without images it stays a plain string.
|
||||||
let user_text = format!(
|
let user_text = format!(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
speaker_prefix(user_name, now_unix() as i64),
|
speaker_prefix(user_name, now_unix() as i64, tz_offset),
|
||||||
body.content,
|
body.content,
|
||||||
extra
|
extra
|
||||||
);
|
);
|
||||||
@@ -813,7 +854,7 @@ mod tests {
|
|||||||
let req = build_request(&sess, &history, &body, "", &[], "User");
|
let req = build_request(&sess, &history, &body, "", &[], "User");
|
||||||
// messages: [identity, user(history), assistant(history), user(new)]
|
// messages: [identity, user(history), assistant(history), user(new)]
|
||||||
let u = req.messages[1].text().unwrap();
|
let u = req.messages[1].text().unwrap();
|
||||||
assert!(u.starts_with("[SPEAKER: User - 2001-09-09 01:46 UTC]"));
|
assert!(u.starts_with("[SPEAKER: User - "));
|
||||||
assert!(u.ends_with("domanda"));
|
assert!(u.ends_with("domanda"));
|
||||||
let a = req.messages[2].text().unwrap();
|
let a = req.messages[2].text().unwrap();
|
||||||
assert!(a.starts_with("[SPEAKER: Nebula - "));
|
assert!(a.starts_with("[SPEAKER: Nebula - "));
|
||||||
@@ -821,9 +862,14 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn format_utc_known_dates() {
|
fn format_stamp_known_dates_and_offset() {
|
||||||
assert_eq!(format_utc(0), "1970-01-01 00:00 UTC");
|
assert_eq!(format_stamp(0, 0), "1970-01-01 00:00");
|
||||||
assert_eq!(format_utc(1_000_000_000), "2001-09-09 01:46 UTC");
|
assert_eq!(format_stamp(1_000_000_000, 0), "2001-09-09 01:46");
|
||||||
assert_eq!(format_utc(951_782_400), "2000-02-29 00:00 UTC"); // leap day
|
assert_eq!(format_stamp(951_782_400, 0), "2000-02-29 00:00"); // leap day
|
||||||
|
assert_eq!(format_stamp(0, 3600), "1970-01-01 01:00"); // +1h server offset
|
||||||
|
assert_eq!(parse_utc_offset("+0100"), Some(3600));
|
||||||
|
assert_eq!(parse_utc_offset("-0500"), Some(-18000));
|
||||||
|
assert_eq!(parse_utc_offset("+0000"), Some(0));
|
||||||
|
assert_eq!(parse_utc_offset("nope"), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -90,7 +90,7 @@ function usageText(u) {
|
|||||||
if (u.decode_ms > 0 && u.completion_tokens > 0) {
|
if (u.decode_ms > 0 && u.completion_tokens > 0) {
|
||||||
s += " · " + t("stats.tps", { n: fmt1(u.completion_tokens / (u.decode_ms / 1000)) });
|
s += " · " + t("stats.tps", { n: fmt1(u.completion_tokens / (u.decode_ms / 1000)) });
|
||||||
}
|
}
|
||||||
if (u.prompt_ms > 0) s += " · " + t("usage.ttft", { n: fmtInt(u.prompt_ms) });
|
if (u.prompt_ms > 0) s += " · " + t("usage.ttft", { n: fmtInt(u.prompt_ms / 1000) });
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
"attach.title": "Attach files or images",
|
"attach.title": "Attach files or images",
|
||||||
"attach.remove": "Remove attachment",
|
"attach.remove": "Remove attachment",
|
||||||
"attach.error": "Upload failed: {msg}",
|
"attach.error": "Upload failed: {msg}",
|
||||||
"usage.ttft": "1st token {n} ms",
|
"usage.ttft": "1st token {n} s",
|
||||||
"stats.title": "Statistics",
|
"stats.title": "Statistics",
|
||||||
"stats.close": "Close",
|
"stats.close": "Close",
|
||||||
"stats.updated": "Updated {time}",
|
"stats.updated": "Updated {time}",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
"attach.title": "Allega file o immagini",
|
"attach.title": "Allega file o immagini",
|
||||||
"attach.remove": "Rimuovi allegato",
|
"attach.remove": "Rimuovi allegato",
|
||||||
"attach.error": "Caricamento fallito: {msg}",
|
"attach.error": "Caricamento fallito: {msg}",
|
||||||
"usage.ttft": "1° token {n} ms",
|
"usage.ttft": "1° token {n} s",
|
||||||
"stats.title": "Statistiche",
|
"stats.title": "Statistiche",
|
||||||
"stats.close": "Chiudi",
|
"stats.close": "Chiudi",
|
||||||
"stats.updated": "Aggiornato {time}",
|
"stats.updated": "Aggiornato {time}",
|
||||||
|
|||||||
Reference in new issue
Block a user