Allow for prompt caching to work by using baibot_conversation_start_time_utc instead of baibot_now_utc

This patch introduces a new `baibot_conversation_start_time_utc`
variable which indicates the time the conversation got started.

Using `baibot_now_utc` is still possible, but given that the current
time is a moving target, its use is in conflict with prompt caching.

Because the new `baibot_conversation_start_time_utc` prompt variable
is a more reasonable default, we're now using it in all sample configs.
This commit is contained in:
Slavi Pantaleev
2024-10-03 11:48:14 +03:00
parent db9422740c
commit 85e66406dc
25 changed files with 159 additions and 25 deletions

View File

@@ -492,6 +492,7 @@ async fn handle_stage_text_generation(
.text_generation_model_id()
.unwrap_or("unknown-model".to_owned()),
chrono::Utc::now(),
conversation.start_time(),
);
let params = TextGenerationParams {

View File

@@ -46,6 +46,8 @@ mod tests {
#[test]
fn test_build_prompt() {
let timestamp = chrono::Utc::now();
let test_cases = vec![
// Simple case
TestCase {
@@ -59,6 +61,7 @@ mod tests {
messages: vec![Message {
author: Author::User,
message_text: "Must be blue".to_owned(),
timestamp,
}],
expected_prompt: "Generate a picture of a dog\nOther criteria:\n- Must be blue",
},
@@ -68,14 +71,17 @@ mod tests {
messages: vec![Message {
author: Author::User,
message_text: "Must be blue".to_owned(),
timestamp,
},
Message {
author: Author::Assistant,
message_text: "Whatever".to_owned(),
timestamp,
},
Message {
author: Author::User,
message_text: "Must be 3-legged.\nMust be flying.".to_owned(),
timestamp,
}],
expected_prompt: "Generate a picture of an elephant\nOther criteria:\n- Must be blue\n- Must be 3-legged.. Must be flying.",
},
@@ -85,18 +91,22 @@ mod tests {
messages: vec![Message {
author: Author::User,
message_text: "Must be blue".to_owned(),
timestamp,
},
Message {
author: Author::Assistant,
message_text: "Whatever".to_owned(),
timestamp,
},
Message {
author: Author::User,
message_text: "Again".to_owned(),
timestamp,
},
Message {
author: Author::User,
message_text: "again".to_owned(),
timestamp,
}],
expected_prompt: "Generate a picture of a grizzly bear\nOther criteria:\n- Must be blue",
},