Reuse canonical chat context
This commit is contained in:
@@ -118,6 +118,7 @@ pub struct StoredMessage {
|
||||
pub reasoning: Option<String>,
|
||||
pub reasoning_complete: bool,
|
||||
pub content: String,
|
||||
pub model_content: Option<String>,
|
||||
pub system: bool,
|
||||
pub compaction: bool,
|
||||
pub compaction_tail_start: Option<i32>,
|
||||
@@ -136,6 +137,7 @@ struct NewMessage<'a> {
|
||||
reasoning: Option<&'a str>,
|
||||
reasoning_complete: bool,
|
||||
content: &'a str,
|
||||
model_content: Option<&'a str>,
|
||||
system: bool,
|
||||
compaction: bool,
|
||||
compaction_tail_start: Option<i32>,
|
||||
@@ -376,6 +378,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content: &content,
|
||||
model_content: None,
|
||||
system: true,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -422,6 +425,7 @@ impl Database {
|
||||
&mut self,
|
||||
session_id: i32,
|
||||
prompt: &str,
|
||||
model_prompt: Option<&str>,
|
||||
system_messages: &[String],
|
||||
reasoning: bool,
|
||||
) -> Result<Vec<StoredMessage>, String> {
|
||||
@@ -438,6 +442,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content,
|
||||
model_content: None,
|
||||
system: true,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -454,6 +459,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content: prompt,
|
||||
model_content: model_prompt,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -468,6 +474,7 @@ impl Database {
|
||||
reasoning: reasoning.then_some(""),
|
||||
reasoning_complete: !reasoning,
|
||||
content: "",
|
||||
model_content: None,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -500,6 +507,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content: result,
|
||||
model_content: None,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -517,6 +525,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content,
|
||||
model_content: None,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -535,6 +544,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content,
|
||||
model_content: None,
|
||||
system: true,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -551,6 +561,7 @@ impl Database {
|
||||
reasoning: reasoning.then_some(""),
|
||||
reasoning_complete: !reasoning,
|
||||
content: "",
|
||||
model_content: None,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -642,6 +653,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content: summary,
|
||||
model_content: None,
|
||||
system: true,
|
||||
compaction: true,
|
||||
compaction_tail_start: tail_start,
|
||||
@@ -659,6 +671,7 @@ impl Database {
|
||||
reasoning: None,
|
||||
reasoning_complete: true,
|
||||
content,
|
||||
model_content: None,
|
||||
system: false,
|
||||
compaction: false,
|
||||
compaction_tail_start: None,
|
||||
@@ -758,7 +771,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let session = database.create_session(project.id, "A2UI").unwrap();
|
||||
let first = database
|
||||
.start_chat_turn(session.id, "First", &[], false)
|
||||
.start_chat_turn(session.id, "First", None, &[], false)
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
@@ -785,7 +798,7 @@ mod tests {
|
||||
assert!(active.active_surface().is_none());
|
||||
|
||||
let second = database
|
||||
.start_chat_turn(session.id, "Second", &[], false)
|
||||
.start_chat_turn(session.id, "Second", None, &[], false)
|
||||
.unwrap()
|
||||
.pop()
|
||||
.unwrap();
|
||||
@@ -836,7 +849,13 @@ mod tests {
|
||||
let project = database.create_project("DS4", "/tmp/ds4-chat").unwrap();
|
||||
let session = database.create_session(project.id, "Chat").unwrap();
|
||||
let mut opening = database
|
||||
.start_chat_turn(session.id, "Question", &["Date context".into()], true)
|
||||
.start_chat_turn(
|
||||
session.id,
|
||||
"Question",
|
||||
Some("Question\n\nhidden metadata"),
|
||||
&["Date context".into()],
|
||||
true,
|
||||
)
|
||||
.unwrap();
|
||||
let assistant = opening.pop().unwrap();
|
||||
database
|
||||
@@ -875,6 +894,10 @@ mod tests {
|
||||
assert_eq!(messages.len(), 7);
|
||||
assert!(messages[0].system);
|
||||
assert_eq!(messages[1].content, "Question");
|
||||
assert_eq!(
|
||||
messages[1].model_content.as_deref(),
|
||||
Some("Question\n\nhidden metadata")
|
||||
);
|
||||
assert_eq!(messages[2].reasoning.as_deref(), Some("Reasoning"));
|
||||
assert!(messages[2].reasoning_complete);
|
||||
assert_eq!(messages[2].content, "Answer");
|
||||
@@ -956,7 +979,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
reopened
|
||||
.start_chat_turn(session.id, "After third compaction", &[], false)
|
||||
.start_chat_turn(session.id, "After third compaction", None, &[], false)
|
||||
.unwrap();
|
||||
drop(reopened);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user