summaryrefslogtreecommitdiffstats
path: root/src/config/conversation.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-10 07:13:22 +0800
committersigoden <sigoden@gmail.com>2023-03-10 07:13:22 +0800
commit899c4af9ea4dedd295a909f6ddc968b20157a505 (patch)
treee58cf09678b12c99d87778420ebb3b591d9ee89c /src/config/conversation.rs
parentff00426c2c9d7d16de9221644e4f276f7e24d74a (diff)
downloadaichat-899c4af9ea4dedd295a909f6ddc968b20157a505.tar.gz
fix: forbid .clear role in middle of conversation
Diffstat (limited to 'src/config/conversation.rs')
-rw-r--r--src/config/conversation.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/config/conversation.rs b/src/config/conversation.rs
index 7fe843d..93382a3 100644
--- a/src/config/conversation.rs
+++ b/src/config/conversation.rs
@@ -33,6 +33,13 @@ impl Conversation {
Ok(())
}
+ pub fn can_clear_role(&self) -> Result<()> {
+ if self.messages.is_empty() {
+ return Ok(());
+ }
+ bail!("Error: Cannot perform this action in the middle of conversation")
+ }
+
pub fn update_tokens(&mut self) {
self.tokens = num_tokens_from_messages(&self.build_emssages(""));
}