|
1
|
//! # Onde |
|
2
|
//! |
|
3
|
//! **On-device inference for cross-platform apps.** |
|
4
|
//! |
|
5
|
//! Run LLMs, diffusion models, and speech-to-text locally — no cloud, |
|
6
|
//! no latency, no data leaving the device. |
|
7
|
//! |
|
8
|
//! Onde wraps [mistral.rs](https://github.com/EricLBuehler/mistral.rs) for |
|
9
|
//! LLM and image generation — with a unified API that handles model discovery, |
|
10
|
//! HuggingFace Hub downloads, cache management, and GPU acceleration |
|
11
|
//! across every platform. (Speech-to-text moved out of onde: apps depend on |
|
12
|
//! `transcribe-rs` directly.) |
|
13
|
//! |
|
14
|
//! Built by [Onde Inference](https://ondeinference.com) |
|
15
|
//! |
|
16
|
//! ## Modules |
|
17
|
//! |
|
18
|
//! - [`hf_cache`] — HuggingFace Hub cache inspection, repair, and model |
|
19
|
//! download with a framework-agnostic progress-callback API. |
|
20
|
//! - [`inference::models`] — Model ID constants and rich metadata (download |
|
21
|
//! size, display name, org, description) for all supported models. |
|
22
|
//! - [`inference::token`] — HuggingFace token resolution (build-time literal |
|
23
|
//! or on-disk cache; required on iOS where the filesystem is sandboxed). |
|
24
|
//! |
|
25
|
//! ## Re-exports |
|
26
|
//! |
|
27
|
//! `mistralrs`, `hf_hub`, and `mistralrs_core` are re-exported so that apps |
|
28
|
//! depending on `onde` do not need their own direct dependency on those crates. |
|
29
|
//! Access them as `onde::mistralrs`, `onde::hf_hub`, and `onde::mistralrs_core`. |
|
30
|
|
|
31
|
pub mod hf_cache; |
|
32
|
|
|
33
|
pub mod inference; |
|
34
|
pub mod pulse; |
|
35
|
|
|
36
|
static PANIC_HOOK_ONCE: std::sync::Once = std::sync::Once::new(); |
|
37
|
|
|
38
|
pub(crate) fn install_panic_hook_once() { |
|
39
|
PANIC_HOOK_ONCE.call_once(|| { |
|
40
|
std::panic::set_hook(Box::new(|panic_info| { |
|
41
|
let location = panic_info |
|
42
|
.location() |
|
43
|
.map(|loc| format!("{}:{}:{}", loc.file(), loc.line(), loc.column())) |
|
44
|
.unwrap_or_else(|| "<unknown>".to_string()); |
|
45
|
|
|
46
|
let message = if let Some(msg) = panic_info.payload().downcast_ref::<&str>() { |
|
47
|
(*msg).to_string() |
|
48
|
} else if let Some(msg) = panic_info.payload().downcast_ref::<String>() { |
|
49
|
msg.clone() |
|
50
|
} else { |
|
51
|
"<non-string panic payload>".to_string() |
|
52
|
}; |
|
53
|
|
|
54
|
log::error!("Rust panic at {}: {}", location, message); |
|
55
|
})); |
|
56
|
}); |
|
57
|
} |
|
58
|
|
|
59
|
uniffi::setup_scaffolding!(); |
|
60
|
|
|
61
|
// Re-export mistralrs for every platform that onde supports. |
|
62
|
// Apps use `onde::mistralrs::Model` etc. instead of declaring a direct dep. |
|
63
|
#[cfg(any( |
|
64
|
target_os = "macos", |
|
65
|
target_os = "ios", |
|
66
|
target_os = "tvos", |
|
67
|
target_os = "visionos", |
|
68
|
target_os = "watchos", |
|
69
|
target_os = "windows", |
|
70
|
target_os = "linux", |
|
71
|
target_os = "android" |
|
72
|
))] |
|
73
|
pub use mistralrs; |
|
74
|
|
|
75
|
// Re-exports needed for the GLOBAL_HF_CACHE workaround on sandboxed platforms. |
|
76
|
// On iOS/tvOS `~/.cache` is outside the container; on Android `dirs::home_dir()` |
|
77
|
// panics. All three need `hf_hub::Cache` + `mistralrs_core::GLOBAL_HF_CACHE`. |
|
78
|
#[cfg(any(target_os = "android", target_os = "ios", target_os = "tvos"))] |
|
79
|
pub use hf_hub; |
|
80
|
#[cfg(any(target_os = "android", target_os = "ios", target_os = "tvos"))] |
|
81
|
pub use mistralrs_core; |