release/windows-microsoft-store
rs 56 lines 1.47 KB
Raw
1 //! Tauri command: `chat_get_status`
2 //!
3 //! Returns the current status of the chat model and conversation.
4
5 use super::ChatStatusResponse;
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, crate::constants::ChatStatus, onde::inference::EngineStatus};
14
15 /// Get the current status of the chat model and conversation.
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_get_status() -> ChatStatusResponse {
24 let info = ENGINE.info().await;
25 let status = match info.status {
26 EngineStatus::Ready => ChatStatus::Ready,
27 EngineStatus::Unloaded => ChatStatus::Unloaded,
28 EngineStatus::Loading => ChatStatus::Loading,
29 EngineStatus::Generating => ChatStatus::Ready,
30 EngineStatus::Error => ChatStatus::Error,
31 };
32 ChatStatusResponse {
33 status,
34 model_name: info.model_name,
35 approx_memory: info.approx_memory,
36 history_length: info.history_length as usize,
37 }
38 }
39
40 #[cfg(not(any(
41 target_os = "macos",
42 target_os = "ios",
43 target_os = "android",
44 target_os = "windows"
45 )))]
46 #[tauri::command]
47 pub async fn chat_get_status() -> ChatStatusResponse {
48 use crate::constants::ChatStatus;
49
50 ChatStatusResponse {
51 status: ChatStatus::Unloaded,
52 model_name: None,
53 approx_memory: None,
54 history_length: 0,
55 }
56 }