Raw
1 //! Tauri command `chat_unload_model`: frees the chat model from memory.
2
3 use log::debug;
4
5 #[cfg(any(
6 target_os = "macos",
7 target_os = "ios",
8 target_os = "android",
9 target_os = "windows"
10 ))]
11 use {super::resolved_model_config, ed_agent_tauri::EdState, log::info, tauri::State};
12
13 /// Unload the chat model from memory to free resources.
14 #[cfg(any(
15 target_os = "macos",
16 target_os = "ios",
17 target_os = "android",
18 target_os = "windows"
19 ))]
20 #[tauri::command]
21 pub async fn chat_unload_model(state: State<'_, EdState>) -> Result<String, String> {
22 if state.ed().is_loaded().await {
23 let display_name = resolved_model_config().display_name();
24 // Ed reports the `Unloaded` transition.
25 state.ed().unload().await;
26 info!("Chat model unloaded: {}", display_name);
27 Ok(format!("Chat model {} unloaded.", display_name))
28 } else {
29 debug!("No chat model was loaded.");
30 Ok("No chat model was loaded.".to_string())
31 }
32 }
33
34 #[cfg(not(any(
35 target_os = "macos",
36 target_os = "ios",
37 target_os = "android",
38 target_os = "windows"
39 )))]
40 #[tauri::command]
41 pub async fn chat_unload_model() -> Result<String, String> {
42 debug!("Chat model is not supported on this platform.");
43 Ok("No chat model was loaded.".to_string())
44 }