MCPcopy Create free account
hub / github.com/evilsocket/cake / start_worker

Function start_worker

cake-mobile/src/lib.rs:233–323  ·  view source on GitHub ↗
(name: String, model: String, cluster_key: String)

Source from the content-addressed store, hash-verified

231/// Returns an error string if startup fails, or empty string on clean exit.
232#[uniffi::export]
233pub fn start_worker(name: String, model: String, cluster_key: String) -> String {
234 init_logging();
235
236 // Set up directories
237 #[cfg(target_os = "ios")]
238 {
239 let tmp = std::env::temp_dir();
240 let log_path = tmp.join("cake-mobile.log");
241 let _ = std::fs::remove_file(&log_path);
242 let _ = LOG_PATH.set(log_path);
243
244 let ios_home = tmp.join("cake-home");
245 let hf_cache = tmp.join("huggingface").join("hub");
246 let cake_cache = tmp.join("cake");
247 for dir in [&ios_home, &hf_cache, &cake_cache] {
248 if let Err(e) = std::fs::create_dir_all(dir) {
249 let msg = format!("failed to create dir {}: {}", dir.display(), e);
250 log_mobile(&format!("[cake-mobile] {msg}"));
251 return msg;
252 }
253 }
254 std::env::set_var("HOME", ios_home.to_string_lossy().as_ref());
255 std::env::set_var("HF_HUB_CACHE", hf_cache.to_string_lossy().as_ref());
256 }
257
258 #[cfg(target_os = "android")]
259 {
260 let cache_dir = get_cache_dir();
261 let hf_cache = cache_dir.join("huggingface").join("hub");
262 let cake_cache = cache_dir.join("cake");
263 let android_home = cache_dir.join("cake-home");
264 for dir in [&hf_cache, &cake_cache, &android_home] {
265 if let Err(e) = std::fs::create_dir_all(dir) {
266 let msg = format!("failed to create dir {}: {}", dir.display(), e);
267 log_mobile(&format!("[cake-mobile] {msg}"));
268 return msg;
269 }
270 }
271 std::env::set_var("HOME", android_home.to_string_lossy().as_ref());
272 std::env::set_var("HF_HUB_CACHE", hf_cache.to_string_lossy().as_ref());
273 }
274
275 log_mobile("[cake-mobile] start_worker called");
276 log_mobile(&format!("[cake-mobile] name: {name}"));
277 log_mobile(&format!("[cake-mobile] model: {model}"));
278 log_mobile(&format!("[cake-mobile] cluster_key: {}", if cluster_key.is_empty() { "(none)" } else { "(set)" }));
279
280 let address = "0.0.0.0:10128".to_string();
281 let use_cluster = !cluster_key.is_empty();
282
283 let (stop_tx, mut stop_rx) = tokio::sync::watch::channel(false);
284 *STOP_TX.lock().unwrap() = Some(stop_tx);
285
286 update_status("starting", "Initializing...", 0.0);
287 log_mobile("[cake-mobile] starting tokio runtime...");
288
289 let rt = tokio::runtime::Builder::new_multi_thread()
290 .enable_all()

Callers 1

cake_start_workerFunction · 0.85

Calls 7

init_loggingFunction · 0.85
log_mobileFunction · 0.85
get_cache_dirFunction · 0.85
update_statusFunction · 0.85
run_zero_config_workerFunction · 0.85
run_direct_workerFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected