1 //! Tauri command: `chat_clear_history`
2 //!
3 //! Clears the conversation history but keeps the model loaded in memory.
4
5 use log::debug;
6
7 #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
8 use {super::ENGINE, log::info};
9
10 /// Clear the conversation history but keep the model loaded.
11 #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
12 #[tauri::command]
13 pub async fn chat_clear_history() -> Result<String, String> {
14 if ENGINE.is_loaded().await {
15 let count = ENGINE.history().await.len();
16 ENGINE.clear_history().await;
17 info!("Chat history cleared ({} turns removed).", count);
18 Ok(format!("Chat history cleared ({} turns removed).", count))
19 } else {
20 debug!("No chat model loaded; nothing to clear.");
21 Ok("No chat model loaded.".to_string())
22 }
23 }
24
25 #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
26 #[tauri::command]
27 pub async fn chat_clear_history() -> Result<String, String> {
28 debug!("Siti chat is only supported on macOS, iOS, and Android for now.");
29 Ok("No chat model loaded.".to_string())
30 }