feat: finalized support for chat
This commit is contained in:
@@ -262,6 +262,7 @@ pub struct Session {
|
||||
pub title: String,
|
||||
pub context_used: i32,
|
||||
pub context_limit: i32,
|
||||
pub last_tokens_per_second: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
@@ -483,13 +484,18 @@ impl Database {
|
||||
session_id: i32,
|
||||
used: u32,
|
||||
limit: u32,
|
||||
tokens_per_second: Option<f32>,
|
||||
) -> Result<(), String> {
|
||||
let used = i32::try_from(used).map_err(|_| "Used context is too large to save")?;
|
||||
let limit = i32::try_from(limit).map_err(|_| "Context limit is too large to save")?;
|
||||
if tokens_per_second.is_some_and(|speed| !speed.is_finite() || speed < 0.0) {
|
||||
return Err("Generation speed is invalid".into());
|
||||
}
|
||||
diesel::update(sessions::table.find(session_id))
|
||||
.set((
|
||||
sessions::context_used.eq(used),
|
||||
sessions::context_limit.eq(limit),
|
||||
sessions::last_tokens_per_second.eq(tokens_per_second),
|
||||
))
|
||||
.execute(&mut self.connection)
|
||||
.map(|_| ())
|
||||
@@ -669,7 +675,7 @@ mod tests {
|
||||
.update_message(assistant.id, Some("Reasoning"), true, "Answer")
|
||||
.unwrap();
|
||||
database
|
||||
.update_session_context(session.id, 1_234, 65_536)
|
||||
.update_session_context(session.id, 1_234, 65_536, Some(12.5))
|
||||
.unwrap();
|
||||
drop(database);
|
||||
|
||||
@@ -677,6 +683,7 @@ mod tests {
|
||||
let projects = reopened.load_projects().unwrap();
|
||||
assert_eq!(projects[0].sessions[0].context_used, 1_234);
|
||||
assert_eq!(projects[0].sessions[0].context_limit, 65_536);
|
||||
assert_eq!(projects[0].sessions[0].last_tokens_per_second, Some(12.5));
|
||||
let messages = reopened.load_messages(session.id).unwrap();
|
||||
assert_eq!(messages.len(), 2);
|
||||
assert!(messages[0].user);
|
||||
|
||||
Reference in New Issue
Block a user