Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Drop the as-core binding aliases and sort llm provider imports

Manav Rathi32c4386e916b
diff --git a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/RustLlmProvider.kt b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/RustLlmProvider.kt
index 8a7a91ef6c..e5e1783e12 100644
--- a/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/RustLlmProvider.kt
+++ b/mobile/native/android/apps/ensu/app/src/main/java/io/ente/ensu/llm/RustLlmProvider.kt
@@ -5,31 +5,33 @@ import android.content.Context
import android.net.Uri
import android.os.Environment
import android.util.Log
-import io.ente.ensu.device.AndroidDeviceCapabilityProvider
-import io.ente.ensu.device.requireChatSupported
-import io.ente.ensu.llm.DownloadProgress
-import io.ente.ensu.llm.GenerationSummary
-import io.ente.ensu.llm.LlmMessage
-import io.ente.ensu.llm.LlmModelTarget
-import io.ente.ensu.format.formatBytes
+import io.ente.ensu.bindings.LlmChatMessage as NativeChatMessage
+import io.ente.ensu.bindings.LlmChatRequest
import io.ente.ensu.bindings.LlmContext
import io.ente.ensu.bindings.LlmContextParams
import io.ente.ensu.bindings.LlmException
-import io.ente.ensu.bindings.LlmChatRequest
import io.ente.ensu.bindings.LlmGenerationEvent
import io.ente.ensu.bindings.LlmGenerationEventCallback
+import io.ente.ensu.bindings.LlmGenerationSummary as NativeSummary
+import io.ente.ensu.bindings.LlmModel
import io.ente.ensu.bindings.LlmModelDownloadCallback
import io.ente.ensu.bindings.LlmModelDownloadProgress
import io.ente.ensu.bindings.LlmModelDownloadTarget
-import io.ente.ensu.bindings.LlmModel
import io.ente.ensu.bindings.LlmModelLoadParams
+import io.ente.ensu.bindings.Transcriber
import io.ente.ensu.bindings.llmCancel
import io.ente.ensu.bindings.llmDownloadModelFiles
import io.ente.ensu.bindings.llmInitBackend
import io.ente.ensu.bindings.uniffiEnsureInitialized
-import io.ente.ensu.bindings.Transcriber
-import io.ente.ensu.bindings.LlmChatMessage as NativeChatMessage
-import io.ente.ensu.bindings.LlmGenerationSummary as NativeSummary
+import io.ente.ensu.device.AndroidDeviceCapabilityProvider
+import io.ente.ensu.device.requireChatSupported
+import io.ente.ensu.format.formatBytes
+import java.io.File
+import java.io.IOException
+import java.util.concurrent.ConcurrentHashMap
+import java.util.concurrent.locks.ReentrantLock
+import kotlin.coroutines.coroutineContext
+import kotlin.math.max
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
@@ -40,12 +42,6 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import okhttp3.OkHttpClient
-import java.io.File
-import java.io.IOException
-import java.util.concurrent.ConcurrentHashMap
-import java.util.concurrent.locks.ReentrantLock
-import kotlin.coroutines.coroutineContext
-import kotlin.math.max
class RustLlmProvider(
context: Context,
diff --git a/rust/bindings/uniffi/ensu/src/db.rs b/rust/bindings/uniffi/ensu/src/db.rs
index 2d00e837c4..2c9445376e 100644
--- a/rust/bindings/uniffi/ensu/src/db.rs
+++ b/rust/bindings/uniffi/ensu/src/db.rs
@@ -1,4 +1,4 @@
-use ente_ensu::db as core;
+use ente_ensu::db;
use thiserror::Error;
use uuid::Uuid;
@@ -8,8 +8,8 @@ pub enum DbError {
Message(String),
}
-impl From<core::Error> for DbError {
- fn from(err: core::Error) -> Self {
+impl From<db::Error> for DbError {
+ fn from(err: db::Error) -> Self {
DbError::Message(err.to_string())
}
}
@@ -46,20 +46,20 @@ pub enum DbAttachmentKind {
Document,
}
-impl From<DbAttachmentKind> for core::AttachmentKind {
+impl From<DbAttachmentKind> for db::AttachmentKind {
fn from(value: DbAttachmentKind) -> Self {
match value {
- DbAttachmentKind::Image => core::AttachmentKind::Image,
- DbAttachmentKind::Document => core::AttachmentKind::Document,
+ DbAttachmentKind::Image => db::AttachmentKind::Image,
+ DbAttachmentKind::Document => db::AttachmentKind::Document,
}
}
}
-impl From<core::AttachmentKind> for DbAttachmentKind {
- fn from(value: core::AttachmentKind) -> Self {
+impl From<db::AttachmentKind> for DbAttachmentKind {
+ fn from(value: db::AttachmentKind) -> Self {
match value {
- core::AttachmentKind::Image => DbAttachmentKind::Image,
- core::AttachmentKind::Document => DbAttachmentKind::Document,
+ db::AttachmentKind::Image => DbAttachmentKind::Image,
+ db::AttachmentKind::Document => DbAttachmentKind::Document,
}
}
}
@@ -72,9 +72,9 @@ pub struct DbAttachmentMeta {
pub name: String,
}
-impl From<DbAttachmentMeta> for core::AttachmentMeta {
+impl From<DbAttachmentMeta> for db::AttachmentMeta {
fn from(value: DbAttachmentMeta) -> Self {
- core::AttachmentMeta {
+ db::AttachmentMeta {
id: value.id,
kind: value.kind.into(),
size: value.size,
@@ -83,8 +83,8 @@ impl From<DbAttachmentMeta> for core::AttachmentMeta {
}
}
-impl From<core::AttachmentMeta> for DbAttachmentMeta {
- fn from(value: core::AttachmentMeta) -> Self {
+impl From<db::AttachmentMeta> for DbAttachmentMeta {
+ fn from(value: db::AttachmentMeta) -> Self {
DbAttachmentMeta {
id: value.id,
kind: value.kind.into(),
@@ -108,10 +108,10 @@ pub struct DbMessage {
#[derive(uniffi::Object)]
pub struct EnsuDb {
- inner: core::Db<core::SqliteBackend>,
+ inner: db::Db<db::SqliteBackend>,
}
-fn to_session(session: core::Session) -> DbSession {
+fn to_session(session: db::Session) -> DbSession {
DbSession {
uuid: session.uuid.to_string(),
title: session.title,
@@ -123,14 +123,14 @@ fn to_session(session: core::Session) -> DbSession {
}
}
-fn to_message(message: core::Message) -> DbMessage {
+fn to_message(message: db::Message) -> DbMessage {
DbMessage {
uuid: message.uuid.to_string(),
session_uuid: message.session_uuid.to_string(),
parent_message_uuid: message.parent_message_uuid.map(|v| v.to_string()),
sender: match message.sender {
- core::Sender::SelfUser => DbSender::SelfUser,
- core::Sender::Other => DbSender::Other,
+ db::Sender::SelfUser => DbSender::SelfUser,
+ db::Sender::Other => DbSender::Other,
},
text: message.text,
attachments: message.attachments.into_iter().map(Into::into).collect(),
@@ -147,7 +147,7 @@ impl EnsuDb {
attachments_db_path: String,
key: Vec<u8>,
) -> Result<Self, DbError> {
- let inner = core::Db::open_sqlite_with_defaults(main_db_path, attachments_db_path, key)?;
+ let inner = db::Db::open_sqlite_with_defaults(main_db_path, attachments_db_path, key)?;
Ok(Self { inner })
}
diff --git a/rust/bindings/uniffi/ensu/src/image.rs b/rust/bindings/uniffi/ensu/src/image.rs
index 1c002a83fb..8f635010ad 100644
--- a/rust/bindings/uniffi/ensu/src/image.rs
+++ b/rust/bindings/uniffi/ensu/src/image.rs
@@ -1,4 +1,4 @@
-use ente_ensu::image as core;
+use ente_ensu::image;
use thiserror::Error;
#[derive(Debug, Error, uniffi::Error)]
@@ -9,5 +9,5 @@ pub enum ImageError {
#[uniffi::export]
pub fn compress_attachment_image(data: Vec<u8>) -> Result<Vec<u8>, ImageError> {
- core::compress_attachment_image(&data).map_err(|e| ImageError::Message(e.to_string()))
+ image::compress_attachment_image(&data).map_err(|e| ImageError::Message(e.to_string()))
}
diff --git a/rust/bindings/uniffi/ensu/src/llm.rs b/rust/bindings/uniffi/ensu/src/llm.rs
index cced8c864a..8109b3514b 100644
--- a/rust/bindings/uniffi/ensu/src/llm.rs
+++ b/rust/bindings/uniffi/ensu/src/llm.rs
@@ -1,5 +1,5 @@
use ente_ensu::download;
-use ente_ensu::llm as core;
+use ente_ensu::llm;
use std::sync::Arc;
use thiserror::Error;
@@ -107,26 +107,26 @@ pub enum LlmGenerationEvent {
#[derive(uniffi::Object)]
pub struct LlmModel {
- handle: core::ModelRef,
+ handle: llm::ModelRef,
}
#[uniffi::export]
impl LlmModel {
#[uniffi::constructor]
pub fn load(params: LlmModelLoadParams) -> Result<Arc<Self>, LlmError> {
- let handle = core::Model::load(params.into()).map_err(LlmError::from)?;
+ let handle = llm::Model::load(params.into()).map_err(LlmError::from)?;
Ok(Arc::new(Self { handle }))
}
pub fn new_context(&self, params: LlmContextParams) -> Result<Arc<LlmContext>, LlmError> {
- let handle = core::Context::new(&self.handle, params.into()).map_err(LlmError::from)?;
+ let handle = llm::Context::new(&self.handle, params.into()).map_err(LlmError::from)?;
Ok(Arc::new(LlmContext { handle }))
}
}
#[derive(uniffi::Object)]
pub struct LlmContext {
- handle: core::ContextRef,
+ handle: llm::ContextRef,
}
#[uniffi::export]
@@ -165,7 +165,7 @@ pub trait LlmModelDownloadCallback: Send + Sync {
fn is_cancelled(&self) -> bool;
}
-impl From<LlmModelLoadParams> for core::ModelLoadParams {
+impl From<LlmModelLoadParams> for llm::ModelLoadParams {
fn from(value: LlmModelLoadParams) -> Self {
Self {
model_path: value.model_path,
@@ -176,7 +176,7 @@ impl From<LlmModelLoadParams> for core::ModelLoadParams {
}
}
-impl From<LlmContextParams> for core::ContextParams {
+impl From<LlmContextParams> for llm::ContextParams {
fn from(value: LlmContextParams) -> Self {
Self {
context_size: value.context_size,
@@ -186,7 +186,7 @@ impl From<LlmContextParams> for core::ContextParams {
}
}
-impl From<LlmChatMessage> for core::ChatMessage {
+impl From<LlmChatMessage> for llm::ChatMessage {
fn from(value: LlmChatMessage) -> Self {
Self {
role: value.role,
@@ -195,7 +195,7 @@ impl From<LlmChatMessage> for core::ChatMessage {
}
}
-impl From<LlmChatRequest> for core::ChatRequest {
+impl From<LlmChatRequest> for llm::ChatRequest {
fn from(value: LlmChatRequest) -> Self {
Self {
messages: value.messages.into_iter().map(Into::into).collect(),
@@ -228,8 +228,8 @@ impl From<LlmModelDownloadTarget> for download::Target {
}
}
-impl From<core::GenerationSummary> for LlmGenerationSummary {
- fn from(value: core::GenerationSummary) -> Self {
+impl From<llm::GenerationSummary> for LlmGenerationSummary {
+ fn from(value: llm::GenerationSummary) -> Self {
Self {
job_id: value.job_id,
prompt_tokens: value.prompt_tokens,
@@ -260,10 +260,10 @@ impl From<download::Progress> for LlmModelDownloadProgress {
}
}
-impl From<core::GenerationEvent> for LlmGenerationEvent {
- fn from(value: core::GenerationEvent) -> Self {
+impl From<llm::GenerationEvent> for LlmGenerationEvent {
+ fn from(value: llm::GenerationEvent) -> Self {
match value {
- core::GenerationEvent::Text {
+ llm::GenerationEvent::Text {
job_id,
text,
token_id,
@@ -272,10 +272,10 @@ impl From<core::GenerationEvent> for LlmGenerationEvent {
text,
token_id,
},
- core::GenerationEvent::Done { summary } => Self::Done {
+ llm::GenerationEvent::Done { summary } => Self::Done {
summary: summary.into(),
},
- core::GenerationEvent::Error { job_id, message } => Self::Error { job_id, message },
+ llm::GenerationEvent::Error { job_id, message } => Self::Error { job_id, message },
}
}
}
@@ -292,15 +292,15 @@ struct CallbackSink {
callback: Box<dyn LlmGenerationEventCallback>,
}
-impl core::EventSink for CallbackSink {
- fn add(&mut self, event: core::GenerationEvent) {
+impl llm::EventSink for CallbackSink {
+ fn add(&mut self, event: llm::GenerationEvent) {
self.callback.on_event(event.into());
}
}
#[uniffi::export]
pub fn llm_init_backend() -> Result<(), LlmError> {
- core::init_backend().map_err(LlmError::from)
+ llm::init_backend().map_err(LlmError::from)
}
#[uniffi::export]
@@ -312,7 +312,7 @@ pub fn llm_download_model_files(
let progress_callback = Arc::clone(&callback);
let cancel_callback = Arc::clone(&callback);
let targets = targets.into_iter().map(Into::into).collect();
- core::download_model_files(
+ llm::download_model_files(
targets,
move |progress| progress_callback.on_progress(progress.into()),
move || cancel_callback.is_cancelled(),
@@ -322,5 +322,5 @@ pub fn llm_download_model_files(
#[uniffi::export]
pub fn llm_cancel(job_id: i64) {
- let _ = core::cancel(job_id);
+ let _ = llm::cancel(job_id);
}
diff --git a/rust/bindings/uniffi/ensu/src/transcription.rs b/rust/bindings/uniffi/ensu/src/transcription.rs
index 842e545b46..3fd70c8959 100644
--- a/rust/bindings/uniffi/ensu/src/transcription.rs
+++ b/rust/bindings/uniffi/ensu/src/transcription.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
use thiserror::Error;
-use ente_ensu::transcription as core;
+use ente_ensu::transcription;
#[derive(Debug, Error, uniffi::Error)]
pub enum TranscriptionError {
@@ -10,8 +10,8 @@ pub enum TranscriptionError {
Message(String),
}
-impl From<core::TranscriptionError> for TranscriptionError {
- fn from(value: core::TranscriptionError) -> Self {
+impl From<transcription::TranscriptionError> for TranscriptionError {
+ fn from(value: transcription::TranscriptionError) -> Self {
Self::Message(value.to_string())
}
}
@@ -31,10 +31,10 @@ pub enum TranscriptionModelEvent {
},
}
-impl From<core::ModelEvent> for TranscriptionModelEvent {
- fn from(value: core::ModelEvent) -> Self {
+impl From<transcription::ModelEvent> for TranscriptionModelEvent {
+ fn from(value: transcription::ModelEvent) -> Self {
match value {
- core::ModelEvent::DownloadProgress {
+ transcription::ModelEvent::DownloadProgress {
downloaded,
total,
percentage,
@@ -43,10 +43,10 @@ impl From<core::ModelEvent> for TranscriptionModelEvent {
total,
percentage,
},
- core::ModelEvent::ExtractionStarted => Self::ExtractionStarted,
- core::ModelEvent::ExtractionCompleted => Self::ExtractionCompleted,
- core::ModelEvent::DownloadComplete => Self::DownloadComplete,
- core::ModelEvent::DownloadError { message } => Self::DownloadError { message },
+ transcription::ModelEvent::ExtractionStarted => Self::ExtractionStarted,
+ transcription::ModelEvent::ExtractionCompleted => Self::ExtractionCompleted,
+ transcription::ModelEvent::DownloadComplete => Self::DownloadComplete,
+ transcription::ModelEvent::DownloadError { message } => Self::DownloadError { message },
}
}
}
@@ -58,7 +58,7 @@ pub trait TranscriptionModelEventCallback: Send + Sync {
#[derive(uniffi::Object)]
pub struct Transcriber {
- inner: core::Transcriber,
+ inner: transcription::Transcriber,
}
#[uniffi::export]
@@ -66,7 +66,7 @@ impl Transcriber {
#[uniffi::constructor]
pub fn new(models_dir: String) -> Arc<Self> {
Arc::new(Self {
- inner: core::Transcriber::new(models_dir),
+ inner: transcription::Transcriber::new(models_dir),
})
}