let index_to_remove = messages
.first()
.map(|m| if m.role == MessageRole::System { 1 } else { 0 })
.unwrap_or(0);
messages.remove(index_to_remove);
With
if messages.len() >= self.messages_number_limit as usize {
if let Some(index_to_remove) = messages.iter().position(|m| m.role != MessageRole::System) {
messages.remove(index_to_remove);
}
}
Added the following test: "test_chat_history_freed_if_limit_exceeded"
Fixes https://github.com/pepperoni21/ollama-rs/issues/73
Replaced
With
Added the following test: "test_chat_history_freed_if_limit_exceeded"