use super::message::ChatMessage;
pub type ModelMemory = Vec<ChatMessage>;
pub trait ModelMemoryMethods {
fn join(&self, separator: &str) -> String;
fn content(&self, separator: &str) -> String;
fn role(&self, separator: &str) -> String;
}
impl ModelMemoryMethods for ModelMemory {
fn join(&self, separator: &str) -> String {
self.iter()
.map(|msg| {
format!(
r#"{{"role": "{}", "content": "{}"}}"#,
msg.role, msg.content
)
})
.collect::<Vec<String>>()
.join(separator)
}
fn content(&self, separator: &str) -> String {
self.iter()
.map(|msg| format!("{}", msg.content))
.collect::<Vec<String>>()
.join(separator)
}
fn role(&self, separator: &str) -> String {
self.iter()
.map(|msg| format!("{}", msg.role))
.collect::<Vec<String>>()
.join(separator)
}
}