release/windows-microsoft-store
rs 48 lines 1.14 KB
Raw
1 //! Tauri command: `chat_get_history`
2 //!
3 //! Returns the full conversation history from the cached chat state.
4
5 use super::ChatMessagePayload;
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, onde::inference::ChatRole};
14
15 /// Return the full conversation history.
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_history() -> Vec<ChatMessagePayload> {
24 ENGINE
25 .history()
26 .await
27 .into_iter()
28 .map(|msg| ChatMessagePayload {
29 role: match msg.role {
30 ChatRole::User => "user".to_string(),
31 ChatRole::Assistant => "assistant".to_string(),
32 ChatRole::System => "system".to_string(),
33 },
34 content: msg.content,
35 })
36 .collect()
37 }
38
39 #[cfg(not(any(
40 target_os = "macos",
41 target_os = "ios",
42 target_os = "android",
43 target_os = "windows"
44 )))]
45 #[tauri::command]
46 pub async fn chat_get_history() -> Vec<ChatMessagePayload> {
47 Vec::new()
48 }