Raw
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(
8 target_os = "macos",
9 target_os = "ios",
10 target_os = "android",
11 target_os = "windows"
12 ))]
13 use {super::ENGINE, log::info};
14
15 /// Clear the conversation history but keep the model loaded.
16 #[cfg(any(
17 target_os = "macos",
18 target_os = "ios",
19 target_os = "android",
20 target_os = "windows"
21 ))]
22 #[tauri::command]
23 pub async fn chat_clear_history() -> Result<String, String> {
24 if ENGINE.is_loaded().await {
25 let count = ENGINE.history().await.len();
26 ENGINE.clear_history().await;
27 info!("Chat history cleared ({} turns removed).", count);
28 Ok(format!("Chat history cleared ({} turns removed).", count))
29 } else {
30 debug!("No chat model loaded; nothing to clear.");
31 Ok("No chat model loaded.".to_string())
32 }
33 }
34
35 #[cfg(not(any(
36 target_os = "macos",
37 target_os = "ios",
38 target_os = "android",
39 target_os = "windows"
40 )))]
41 #[tauri::command]
42 pub async fn chat_clear_history() -> Result<String, String> {
43 debug!("Siti chat is not supported on this platform.");
44 Ok("No chat model loaded.".to_string())
45 }