π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix ensu desktop lint and darwin setup
Prateek Sunal5d538601404f
diff --git a/mobile/native/darwin/Packages/EnteCrypto/rust/tvos-crypto-ffi/Cargo.toml b/mobile/native/darwin/Packages/EnteCrypto/rust/tvos-crypto-ffi/Cargo.tomlindex 83db2111a7..b9cdf7e501 100644--- a/mobile/native/darwin/Packages/EnteCrypto/rust/tvos-crypto-ffi/Cargo.toml+++ b/mobile/native/darwin/Packages/EnteCrypto/rust/tvos-crypto-ffi/Cargo.toml@@ -7,4 +7,4 @@ edition = "2024"crate-type = ["staticlib", "cdylib"][dependencies]-ente-core = { path = "../../../../../rust/core" }+ente-core = { path = "../../../../../../../rust/core" }diff --git a/mobile/native/darwin/darwin.xcworkspace/xcshareddata/swiftpm/Package.resolved b/mobile/native/darwin/darwin.xcworkspace/xcshareddata/swiftpm/Package.resolvedindex d187fab45a..610ef04085 100644--- a/mobile/native/darwin/darwin.xcworkspace/xcshareddata/swiftpm/Package.resolved+++ b/mobile/native/darwin/darwin.xcworkspace/xcshareddata/swiftpm/Package.resolved@@ -9,6 +9,15 @@"version" : "5.7.0"}},+ {+ "identity" : "rive-ios",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/rive-app/rive-ios.git",+ "state" : {+ "revision" : "af1c45b2926ae0bdd84a3556909769a6573bb97a",+ "version" : "6.16.0"+ }+ },{"identity" : "swift-asn1","kind" : "remoteSourceControl",@@ -18,6 +27,15 @@"version" : "1.4.0"}},+ {+ "identity" : "swift-cmark",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/swiftlang/swift-cmark.git",+ "state" : {+ "revision" : "5d9bdaa4228b381639fff09403e39a04926e2dbe",+ "version" : "0.7.1"+ }+ },{"identity" : "swift-crypto","kind" : "remoteSourceControl",@@ -36,6 +54,15 @@"version" : "1.6.4"}},+ {+ "identity" : "swift-markdown",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/apple/swift-markdown.git",+ "state" : {+ "revision" : "7d9a5ce307528578dfa777d505496bd5f544ad94",+ "version" : "0.7.3"+ }+ },{"identity" : "swift-tagged","kind" : "remoteSourceControl",@@ -45,6 +72,15 @@"version" : "0.10.0"}},+ {+ "identity" : "swiftmath",+ "kind" : "remoteSourceControl",+ "location" : "https://github.com/mgriebling/SwiftMath.git",+ "state" : {+ "revision" : "fa8244ed032f4a1ade4cb0571bf87d2f1a9fd2d7",+ "version" : "1.7.3"+ }+ },{"identity" : "zipfoundation","kind" : "remoteSourceControl",diff --git a/rust/ensu/inference/src/api.rs b/rust/ensu/inference/src/api.rsindex 0778a73c76..2df2780ca0 100644--- a/rust/ensu/inference/src/api.rs+++ b/rust/ensu/inference/src/api.rs@@ -2,7 +2,8 @@ use llama_cpp_2::context::LlamaContext;use llama_cpp_2::context::params::LlamaContextParams;use llama_cpp_2::llama_backend::LlamaBackend;use llama_cpp_2::llama_batch::LlamaBatch;-use llama_cpp_2::model::{AddBos, LlamaChatMessage, LlamaChatTemplate, LlamaModel, Special};+use llama_cpp_2::TokenToStringError;+use llama_cpp_2::model::{AddBos, LlamaChatMessage, LlamaChatTemplate, LlamaModel};use llama_cpp_2::mtmd::{MtmdBitmap, MtmdContext, MtmdContextParams, MtmdInputText, mtmd_default_marker,};@@ -132,6 +133,22 @@ fn format_error(context: &str, err: impl std::fmt::Display) -> String {format!("{context}: {err}")}+fn token_piece_bytes(model: &LlamaModel, token: LlamaToken) -> Result<Vec<u8>, TokenToStringError> {+ match model.token_to_piece_bytes(token, 8, true, None) {+ Err(TokenToStringError::InsufficientBufferSpace(required)) => model.token_to_piece_bytes(+ token,+ (-required).try_into().expect("error buffer size is positive"),+ true,+ None,+ ),+ result => result,+ }+}++fn token_piece_string(model: &LlamaModel, token: LlamaToken) -> Option<String> {+ String::from_utf8(token_piece_bytes(model, token).ok()?).ok()+}+fn build_chat_prompt(model: &LlamaModel,messages: Vec<ChatMessage>,@@ -188,7 +205,7 @@ fn build_chat_prompt(}fn should_add_bos(model: &LlamaModel, prompt: &str) -> AddBos {- if let Ok(bos) = model.token_to_str(model.token_bos(), Special::Tokenize)+ if let Some(bos) = token_piece_string(model, model.token_bos())&& !bos.is_empty()&& prompt.starts_with(&bos){@@ -363,10 +380,8 @@ fn run_generation_loop(break;}- let bytes = ctx- .model- .token_to_bytes(token, Special::Tokenize)- .map_err(|err| format_error("Detokenize failed", err))?;+ let bytes =+ token_piece_bytes(&ctx.model, token).map_err(|err| format_error("Detokenize failed", err))?;let step = decoder.push_bytes(&bytes);if let Some(text) = step.text {@@ -689,10 +704,14 @@ pub fn tokenize(pub fn detokenize(model: &ModelHandle, tokens: Vec<i32>) -> Result<String, String> {let tokens = tokens.into_iter().map(LlamaToken::new).collect::<Vec<_>>();- model- .model()- .tokens_to_str(&tokens, Special::Tokenize)- .map_err(|err| format_error("Detokenize failed", err))+ let mut bytes = Vec::with_capacity(tokens.len() * 4);+ for token in tokens {+ bytes.extend_from_slice(+ &token_piece_bytes(model.model(), token)+ .map_err(|err| format_error("Detokenize failed", err))?,+ );+ }+ String::from_utf8(bytes).map_err(|err| format_error("Detokenize failed", err))}pub fn get_model_info(model: &ModelHandle) -> Result<ModelInfo, String> {@@ -700,14 +719,8 @@ pub fn get_model_info(model: &ModelHandle) -> Result<ModelInfo, String> {let bos_token = model_ref.token_bos();let eos_token = model_ref.token_eos();- let bos_token_str = model_ref- .token_to_str(bos_token, Special::Tokenize)- .ok()- .filter(|value| !value.is_empty());- let eos_token_str = model_ref- .token_to_str(eos_token, Special::Tokenize)- .ok()- .filter(|value| !value.is_empty());+ let bos_token_str = token_piece_string(model_ref, bos_token).filter(|value| !value.is_empty());+ let eos_token_str = token_piece_string(model_ref, eos_token).filter(|value| !value.is_empty());let chat_template = model_ref.chat_template(None)