|
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
|
use tauri::AppHandle; |
|
9
|
|
|
10
|
#[cfg(any( |
|
11
|
target_os = "macos", |
|
12
|
target_os = "ios", |
|
13
|
target_os = "android", |
|
14
|
target_os = "windows" |
|
15
|
))] |
|
16
|
use { |
|
17
|
super::{ |
|
18
|
emit_chat_status, fmt_duration, resolved_model_config, sampling_config, CHAT_SYSTEM_PROMPT, |
|
19
|
}, |
|
20
|
crate::constants::ChatStatus, |
|
21
|
log::{error, info}, |
|
22
|
}; |
|
23
|
|
|
24
|
/// Load the platform-default chat model into memory. |
|
25
|
#[cfg(any( |
|
26
|
target_os = "macos", |
|
27
|
target_os = "ios", |
|
28
|
target_os = "android", |
|
29
|
target_os = "windows" |
|
30
|
))] |
|
31
|
#[tauri::command] |
|
32
|
pub async fn chat_load_model(app: AppHandle) -> Result<String, String> { |
|
33
|
let config = resolved_model_config(); |
|
34
|
let display_name = config.display_name(); |
|
35
|
info!("chat_load_model: loading on-device model {}", display_name); |
|
36
|
emit_chat_status(&app, ChatStatus::Loading, Some(&display_name), None); |
|
37
|
|
|
38
|
let elapsed = config |
|
39
|
.load( |
|
40
|
Some(CHAT_SYSTEM_PROMPT.to_string()), |
|
41
|
Some(sampling_config()), |
|
42
|
) |
|
43
|
.await |
|
44
|
.map_err(|e| { |
|
45
|
let msg = format!("Failed to load chat model: {}", e); |
|
46
|
error!("{}", msg); |
|
47
|
emit_chat_status(&app, ChatStatus::Error, Some(&display_name), Some(&msg)); |
|
48
|
msg |
|
49
|
})?; |
|
50
|
|
|
51
|
let msg = format!( |
|
52
|
"Chat model {} loaded in {}", |
|
53
|
display_name, |
|
54
|
fmt_duration(elapsed) |
|
55
|
); |
|
56
|
info!("{}", msg); |
|
57
|
emit_chat_status(&app, ChatStatus::Ready, Some(&display_name), None); |
|
58
|
Ok(msg) |
|
59
|
} |
|
60
|
|
|
61
|
#[cfg(not(any( |
|
62
|
target_os = "macos", |
|
63
|
target_os = "ios", |
|
64
|
target_os = "android", |
|
65
|
target_os = "windows" |
|
66
|
)))] |
|
67
|
#[tauri::command] |
|
68
|
pub async fn chat_load_model(_app: AppHandle) -> Result<String, String> { |
|
69
|
log::debug!("Chat model is not supported on this platform."); |
|
70
|
Err("Chat model is not supported on this platform.".to_string()) |
|
71
|
} |