58 lines
1.7 KiB
Rust
58 lines
1.7 KiB
Rust
//! Session logs of turns with speakers, for the tests of deciding turns. Do not edit.
|
|
|
|
#![allow(dead_code)] // each test file uses a different part of this module
|
|
|
|
use std::path::Path;
|
|
|
|
use bxcore::{DataClass, LogRecord, SessionId, SessionStateReply};
|
|
|
|
use crate::logs::{assistant, at, result};
|
|
|
|
pub fn sid(s: &str) -> SessionId {
|
|
SessionId::new(s).unwrap()
|
|
}
|
|
|
|
pub fn clean() -> SessionStateReply {
|
|
SessionStateReply {
|
|
class: DataClass::Private,
|
|
untrusted: false,
|
|
}
|
|
}
|
|
|
|
pub fn spoken(content: &str, speaker: Option<&str>) -> LogRecord {
|
|
LogRecord::User {
|
|
time: at(1),
|
|
content: content.to_string(),
|
|
speaker: speaker.map(str::to_string),
|
|
}
|
|
}
|
|
|
|
/// A finished turn: the speaker's message and the reply.
|
|
pub fn finished(speaker: Option<&str>) -> Vec<LogRecord> {
|
|
vec![spoken("hello", speaker), assistant(2, Some("hi"), &[])]
|
|
}
|
|
|
|
/// A finished turn that read an untrusted page.
|
|
pub fn fetched(speaker: Option<&str>) -> Vec<LogRecord> {
|
|
vec![
|
|
spoken("read this page", speaker),
|
|
assistant(2, None, &[("fetch", "{}")]),
|
|
result(3, "the page", DataClass::Public, true),
|
|
assistant(4, Some("it says hello"), &[]),
|
|
]
|
|
}
|
|
|
|
/// A turn still running, or one that failed: no reply.
|
|
pub fn running(speaker: Option<&str>) -> Vec<LogRecord> {
|
|
vec![
|
|
spoken("look it up", speaker),
|
|
assistant(2, None, &[("fetch", "{}")]),
|
|
]
|
|
}
|
|
|
|
/// `sessions/<session>/0.jsonl` under `home`, the turns one after another.
|
|
pub fn write_turns(home: &Path, session: &str, turns: &[Vec<LogRecord>]) {
|
|
let records: Vec<LogRecord> = turns.iter().flatten().cloned().collect();
|
|
crate::logs::write_log(home, session, &records);
|
|
}
|