| 1 | //! Tauri command `chat_load_model`: loads the on-device chat model. |
| 2 | //! |
| 3 | //! Siti is fully offline: it loads the platform-default GGUF model directly. |
| 4 | //! There is no operator-assigned model and no app credentials involved. The |
| 5 | //! only network access is the one-time HuggingFace download of the model |
| 6 | //! weights into the shared App Group cache. |
| 7 | |
| 8 | #[cfg(any( |
| 9 | target_os = "macos", |
| 10 | target_os = "ios", |
| 11 | target_os = "android", |
| 12 | target_os = "windows" |
| 13 | ))] |
| 14 | use { |
| 15 | super::{fmt_duration, resolved_model_config, sampling_config, CHAT_SYSTEM_PROMPT}, |
| 16 | ed_agent_tauri::EdState, |
| 17 | log::{error, info}, |
| 18 | tauri::State, |
| 19 | }; |
| 20 | |
| 21 | /// Load the platform-default chat model into memory. Ed reports the |
| 22 | /// `Loading` -> `Ready`/`Error` transitions as `chat_status_changed`. |
| 23 | #[cfg(any( |
| 24 | target_os = "macos", |
| 25 | target_os = "ios", |
| 26 | target_os = "android", |
| 27 | target_os = "windows" |
| 28 | ))] |
| 29 | #[tauri::command] |
| 30 | pub async fn chat_load_model(state: State<'_, EdState>) -> Result<String, String> { |
| 31 | let config = resolved_model_config(); |
| 32 | let display_name = config.display_name(); |
| 33 | info!("chat_load_model: loading on-device model {}", display_name); |
| 34 | |
| 35 | let elapsed = config |
| 36 | .load( |
| 37 | state.ed(), |
| 38 | Some(CHAT_SYSTEM_PROMPT.to_string()), |
| 39 | Some(sampling_config()), |
| 40 | ) |
| 41 | .await |
| 42 | .map_err(|e| { |
| 43 | let msg = format!("Failed to load chat model: {}", e); |
| 44 | error!("{}", msg); |
| 45 | msg |
| 46 | })?; |
| 47 | |
| 48 | let msg = format!( |
| 49 | "Chat model {} loaded in {}", |
| 50 | display_name, |
| 51 | fmt_duration(elapsed) |
| 52 | ); |
| 53 | info!("{}", msg); |
| 54 | Ok(msg) |
| 55 | } |
| 56 | |
| 57 | #[cfg(not(any( |
| 58 | target_os = "macos", |
| 59 | target_os = "ios", |
| 60 | target_os = "android", |
| 61 | target_os = "windows" |
| 62 | )))] |
| 63 | #[tauri::command] |
| 64 | pub async fn chat_load_model() -> Result<String, String> { |
| 65 | log::debug!("Chat model is not supported on this platform."); |
| 66 | Err("Chat model is not supported on this platform.".to_string()) |
| 67 | } |