release/windows-microsoft-store
rs 48 lines 1.35 KB
Raw
1 //! Tauri command `chat_unload_model`: frees the chat model from memory.
2
3 use {log::debug, tauri::AppHandle};
4
5 #[cfg(any(
6 target_os = "macos",
7 target_os = "ios",
8 target_os = "android",
9 target_os = "windows"
10 ))]
11 use {
12 super::{emit_chat_status, resolved_model_config, ENGINE},
13 crate::constants::ChatStatus,
14 log::info,
15 };
16
17 /// Unload the chat model from memory to free resources.
18 #[cfg(any(
19 target_os = "macos",
20 target_os = "ios",
21 target_os = "android",
22 target_os = "windows"
23 ))]
24 #[tauri::command]
25 pub async fn chat_unload_model(app: AppHandle) -> Result<String, String> {
26 if ENGINE.is_loaded().await {
27 let display_name = resolved_model_config().display_name();
28 ENGINE.unload_model().await;
29 info!("Chat model unloaded: {}", display_name);
30 emit_chat_status(&app, ChatStatus::Unloaded, None, None);
31 Ok(format!("Chat model {} unloaded.", display_name))
32 } else {
33 debug!("No chat model was loaded.");
34 Ok("No chat model was loaded.".to_string())
35 }
36 }
37
38 #[cfg(not(any(
39 target_os = "macos",
40 target_os = "ios",
41 target_os = "android",
42 target_os = "windows"
43 )))]
44 #[tauri::command]
45 pub async fn chat_unload_model(_app: AppHandle) -> Result<String, String> {
46 debug!("Chat model is not supported on this platform.");
47 Ok("No chat model was loaded.".to_string())
48 }