Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor(ensu): centralize defaults in rust

Prateek Sunal009148e8d4e3
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt
index 5eefcc48f3..483c62e67b 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt
@@ -11,6 +11,7 @@ import io.ente.ensu.data.EndpointPreferencesDataStore
import io.ente.ensu.data.SessionPreferencesDataStore
import io.ente.ensu.data.getModelDownloadRequestedSync
import io.ente.ensu.data.auth.EnsuAuthService
+import io.ente.ensu.data.llm.EnsuRustDefaults
import io.ente.ensu.data.logging.FileLogRepository
import io.ente.ensu.data.storage.CredentialStore
import io.ente.ensu.data.llm.InferenceRsProvider
@@ -42,12 +43,14 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {
credentialStore = credentialStore,
endpointPreferences = endpointPreferences
)
+ val ensuDefaults = EnsuRustDefaults.load()
val store = AppStore(
sessionPreferences = sessionPreferences,
chatRepository = chatRepository,
chatSyncRepository = chatSyncRepository,
llmProvider = llmProvider,
+ ensuDefaults = ensuDefaults,
logRepository = logRepository
)
val authService = EnsuAuthService(
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/EnsuApp.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/EnsuApp.kt
index 0c358a0dc7..c9bcce494a 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/EnsuApp.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/EnsuApp.kt
@@ -16,6 +16,7 @@ fun EnsuApp(appViewModel: AppViewModel) {
authService = appViewModel.authService,
currentEndpointFlow = appViewModel.currentEndpointFlow,
advancedSettingsDataStore = appViewModel.advancedSettingsDataStore,
- appVersion = appViewModel.appVersion
+ appVersion = appViewModel.appVersion,
+ ensuDefaults = appViewModel.ensuDefaults
)
}
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeNavigation.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeNavigation.kt
index 6a718f99ee..836467cd20 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeNavigation.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeNavigation.kt
@@ -31,6 +31,7 @@ import io.ente.ensu.data.AdvancedSettingsDataStore
import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.AttachmentType
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.state.AppState
import io.ente.ensu.domain.store.AppStore
import io.ente.ensu.modelsettings.ModelSettingsScreen
@@ -48,6 +49,7 @@ internal fun HomeNavigation(
currentEndpointFlow: Flow<String>,
advancedSettingsDataStore: AdvancedSettingsDataStore,
appVersion: String,
+ ensuDefaults: EnsuDefaults,
navController: NavHostController,
drawerState: DrawerState,
currentRoute: String,
@@ -189,6 +191,7 @@ internal fun HomeNavigation(
popExitTransition = { backExit() }
) {
ModelSettingsScreen(
+ defaults = ensuDefaults,
state = appState.modelSettings,
onSave = { modelSettings ->
store.updateModelSettings(modelSettings)
@@ -212,6 +215,8 @@ internal fun HomeNavigation(
popExitTransition = { backExit() }
) {
SystemPromptSettingsScreen(
+ defaultPromptBody = ensuDefaults.mobileSystemPromptBody,
+ datePlaceholder = ensuDefaults.systemPromptDatePlaceholder,
systemPrompt = appState.developerSettings.systemPrompt,
onSave = { value ->
val updated = appState.developerSettings.copy(systemPrompt = value)
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt
index ead9d92425..334073256f 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt
@@ -62,6 +62,7 @@ import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.AttachmentType
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.model.LogEntry
import io.ente.ensu.domain.state.AppState
import io.ente.ensu.domain.store.AppStore
@@ -83,7 +84,8 @@ fun HomeView(
authService: EnsuAuthService,
currentEndpointFlow: Flow<String>,
advancedSettingsDataStore: AdvancedSettingsDataStore,
- appVersion: String
+ appVersion: String,
+ ensuDefaults: EnsuDefaults
) {
val drawerState = androidx.compose.material3.rememberDrawerState(DrawerValue.Closed)
val scope = rememberCoroutineScope()
@@ -257,6 +259,7 @@ fun HomeView(
currentEndpointFlow = currentEndpointFlow,
advancedSettingsDataStore = advancedSettingsDataStore,
appVersion = appVersion,
+ ensuDefaults = ensuDefaults,
navController = navController,
drawerState = drawerState,
currentRoute = currentRoute,
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/RootView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/RootView.kt
index 3f22f3fe43..d7cf413ae2 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/RootView.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/RootView.kt
@@ -9,6 +9,7 @@ import io.ente.ensu.data.AdvancedSettingsDataStore
import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.data.auth.EnsuAuthService
import io.ente.ensu.data.logging.FileLogRepository
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.model.LogEntry
import io.ente.ensu.domain.state.AppState
import io.ente.ensu.domain.store.AppStore
@@ -23,7 +24,8 @@ fun RootView(
authService: EnsuAuthService,
currentEndpointFlow: Flow<String>,
advancedSettingsDataStore: AdvancedSettingsDataStore,
- appVersion: String
+ appVersion: String,
+ ensuDefaults: EnsuDefaults
) {
Box(
modifier = Modifier
@@ -38,7 +40,8 @@ fun RootView(
authService = authService,
currentEndpointFlow = currentEndpointFlow,
advancedSettingsDataStore = advancedSettingsDataStore,
- appVersion = appVersion
+ appVersion = appVersion,
+ ensuDefaults = ensuDefaults
)
}
}
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/modelsettings/ModelSettingsScreen.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/modelsettings/ModelSettingsScreen.kt
index c9fea23a89..0b32392018 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/modelsettings/ModelSettingsScreen.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/modelsettings/ModelSettingsScreen.kt
@@ -33,11 +33,13 @@ import androidx.compose.ui.unit.dp
import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.state.ModelSettingsState
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ModelSettingsScreen(
+ defaults: EnsuDefaults,
state: ModelSettingsState,
onSave: (ModelSettingsState) -> Unit,
onReset: () -> Unit
@@ -46,28 +48,19 @@ fun ModelSettingsScreen(
listOf(
ModelChoice(
id = DEFAULT_OPTION_ID,
- title = DEFAULT_MODEL_NAME,
- url = DEFAULT_MODEL_URL,
- mmproj = DEFAULT_MMPROJ_URL,
+ title = defaults.mobileDefaultModel.title,
+ url = defaults.mobileDefaultModel.url,
+ mmproj = defaults.mobileDefaultModel.mmprojUrl,
isDefault = true
- ),
- ModelChoice(
- id = "lfm-1.2b",
- title = "LFM 2.5 1.2B Instruct (Q4_0)",
- url = "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf"
- ),
- ModelChoice(
- id = "lfm-vl-1.6b",
- title = "LFM 2.5 VL 1.6B (Q4_0)",
- url = "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf",
- mmproj = "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
- ),
+ )
+ ) + defaults.mobileModelPresets.map { preset ->
ModelChoice(
- id = "qwen-0.8b",
- title = "Qwen 3.5 0.8B (Q4_K_M)",
- url = "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/Qwen3.5-0.8B-Q4_K_M.gguf?download=true",
- mmproj = "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/mmproj-F16.gguf"
- ),
+ id = preset.id,
+ title = preset.title,
+ url = preset.url,
+ mmproj = preset.mmprojUrl
+ )
+ } + listOf(
ModelChoice(
id = CUSTOM_OPTION_ID,
title = "Custom",
@@ -346,8 +339,3 @@ private fun initialSelectionId(
private const val DEFAULT_OPTION_ID = "default"
private const val CUSTOM_OPTION_ID = "custom"
-private const val DEFAULT_MODEL_NAME = "LFM 2.5 VL 1.6B (Q4_0)"
-private const val DEFAULT_MODEL_URL =
- "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf"
-private const val DEFAULT_MMPROJ_URL =
- "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/SystemPromptSettingsScreen.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/SystemPromptSettingsScreen.kt
index 2056e92ce0..7cb22f7bfa 100644
--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/SystemPromptSettingsScreen.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/settings/SystemPromptSettingsScreen.kt
@@ -25,15 +25,16 @@ import io.ente.ensu.designsystem.EnsuColor
import io.ente.ensu.designsystem.EnsuCornerRadius
import io.ente.ensu.designsystem.EnsuSpacing
import io.ente.ensu.designsystem.EnsuTypography
-import io.ente.ensu.domain.store.SystemPromptDefaults
@Composable
fun SystemPromptSettingsScreen(
+ defaultPromptBody: String,
+ datePlaceholder: String,
systemPrompt: String,
onSave: (String) -> Unit,
onReset: () -> Unit
) {
- val resolvedPrompt = SystemPromptDefaults.resolve(systemPrompt)
+ val resolvedPrompt = systemPrompt.trim().ifEmpty { defaultPromptBody }
var value by remember(systemPrompt) { mutableStateOf(resolvedPrompt) }
Column(
@@ -43,7 +44,7 @@ fun SystemPromptSettingsScreen(
.padding(EnsuSpacing.pageHorizontal.dp)
) {
Text(
- text = "This prompt is used as-is. Use \$date anywhere to insert the current date and time.",
+ text = "This prompt is used as-is. Use $datePlaceholder anywhere to insert the current date and time.",
style = EnsuTypography.small,
color = EnsuColor.textMuted()
)
@@ -58,7 +59,7 @@ fun SystemPromptSettingsScreen(
.height(220.dp),
placeholder = {
Text(
- text = "Example: You are a concise assistant. Current date and time: \$date",
+ text = "Example: You are a concise assistant. Current date and time: $datePlaceholder",
style = EnsuTypography.body
)
},
@@ -86,14 +87,14 @@ fun SystemPromptSettingsScreen(
isEnabled = value.trim() != resolvedPrompt
) {
val normalizedValue = value.trim()
- val valueToSave = if (normalizedValue == SystemPromptDefaults.BODY) "" else normalizedValue
+ val valueToSave = if (normalizedValue == defaultPromptBody) "" else normalizedValue
onSave(valueToSave)
}
Spacer(modifier = Modifier.height(EnsuSpacing.md.dp))
TextButton(onClick = {
- value = SystemPromptDefaults.BODY
+ value = defaultPromptBody
onReset()
}) {
Text(
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt
new file mode 100644
index 0000000000..6873d92e17
--- /dev/null
+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt
@@ -0,0 +1,31 @@
+package io.ente.ensu.data.llm
+
+import io.ente.ensu.domain.model.EnsuDefaults
+import io.ente.ensu.domain.model.EnsuModelPreset
+import io.ente.labs.inference_rs.getEnsuDefaults
+import io.ente.labs.inference_rs.uniffiEnsureInitialized
+
+object EnsuRustDefaults {
+ fun load(): EnsuDefaults {
+ uniffiEnsureInitialized()
+ val defaults = getEnsuDefaults()
+ return EnsuDefaults(
+ mobileSystemPromptBody = defaults.mobileSystemPromptBody,
+ desktopSystemPromptBody = defaults.desktopSystemPromptBody,
+ systemPromptDatePlaceholder = defaults.systemPromptDatePlaceholder,
+ sessionSummarySystemPrompt = defaults.sessionSummarySystemPrompt,
+ mobileDefaultModel = defaults.mobileDefaultModel.toDomain(),
+ mobileModelPresets = defaults.mobileModelPresets.map { it.toDomain() },
+ desktopDefaultModel = defaults.desktopDefaultModel.toDomain(),
+ desktopModelPresets = defaults.desktopModelPresets.map { it.toDomain() }
+ )
+ }
+}
+
+private fun io.ente.labs.inference_rs.EnsuModelPreset.toDomain(): EnsuModelPreset =
+ EnsuModelPreset(
+ id = id,
+ title = title,
+ url = url,
+ mmprojUrl = mmprojUrl
+ )
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/EnsuDefaults.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/EnsuDefaults.kt
new file mode 100644
index 0000000000..ac19c418d2
--- /dev/null
+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/EnsuDefaults.kt
@@ -0,0 +1,19 @@
+package io.ente.ensu.domain.model
+
+data class EnsuModelPreset(
+ val id: String,
+ val title: String,
+ val url: String,
+ val mmprojUrl: String?
+)
+
+data class EnsuDefaults(
+ val mobileSystemPromptBody: String,
+ val desktopSystemPromptBody: String,
+ val systemPromptDatePlaceholder: String,
+ val sessionSummarySystemPrompt: String,
+ val mobileDefaultModel: EnsuModelPreset,
+ val mobileModelPresets: List<EnsuModelPreset>,
+ val desktopDefaultModel: EnsuModelPreset,
+ val desktopModelPresets: List<EnsuModelPreset>
+)
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
index 6cdb96f261..51713699e5 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
@@ -7,6 +7,7 @@ import io.ente.ensu.domain.logging.LogRepository
import io.ente.ensu.domain.logging.NoOpLogRepository
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.ChatMessage
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.preferences.SessionPreferences
import io.ente.ensu.domain.state.AppState
import io.ente.ensu.domain.state.DeveloperSettingsState
@@ -21,6 +22,7 @@ class AppStore(
private val chatRepository: ChatRepository,
private val chatSyncRepository: ChatSyncRepository? = null,
private val llmProvider: LlmProvider,
+ val ensuDefaults: EnsuDefaults,
private val clock: () -> Long = { System.currentTimeMillis() },
private val logRepository: LogRepository = NoOpLogRepository
) {
@@ -29,7 +31,8 @@ class AppStore(
private val messageStore = mutableMapOf<String, MutableList<ChatMessage>>()
private val attachmentActions = AttachmentStoreActions(_state, chatSyncRepository, messageStore)
- private val modelSettingsActions = ModelSettingsActions(_state, sessionPreferences, llmProvider, logRepository)
+ private val modelSettingsActions =
+ ModelSettingsActions(_state, sessionPreferences, llmProvider, logRepository, ensuDefaults)
private val syncActions = SyncStoreActions(_state, chatSyncRepository, logRepository)
private val chatActions = ChatStoreActions(
state = _state,
@@ -41,7 +44,8 @@ class AppStore(
messageStore = messageStore,
attachmentActions = attachmentActions,
syncActions = syncActions,
- modelSettingsActions = modelSettingsActions
+ modelSettingsActions = modelSettingsActions,
+ ensuDefaults = ensuDefaults
)
private val authActions = AuthStoreActions(_state, logRepository) {
syncActions.syncAfterLogin()
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt
index 9a305de1b4..258af2166a 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt
+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt
@@ -9,6 +9,7 @@ import io.ente.ensu.domain.llm.LlmProvider
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.ChatMessage
import io.ente.ensu.domain.model.ChatSession
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.model.LogLevel
import io.ente.ensu.domain.model.MessageAuthor
import io.ente.ensu.domain.model.sanitizeTitleText
@@ -42,7 +43,8 @@ internal class ChatStoreActions(
private val messageStore: MutableMap<String, MutableList<ChatMessage>>,
private val attachmentActions: AttachmentStoreActions,
private val syncActions: SyncStoreActions,
- private val modelSettingsActions: ModelSettingsActions
+ private val modelSettingsActions: ModelSettingsActions,
+ private val ensuDefaults: EnsuDefaults
) {
private val branchSelections = mutableMapOf<String, MutableMap<String, String>>()
private val sessionSummaries = mutableMapOf<String, String>()
@@ -56,8 +58,7 @@ internal class ChatStoreActions(
private var pendingOverflow: PendingOverflow? = null
private var overflowBypassMessageId: String? = null
- private val sessionSummarySystemPrompt =
- "You create concise chat titles. Given the provided message, summarize the user's goal in 5-7 words. Use plain words. Don't use markdown characters in the title. No quotes, no emojis, no trailing punctuation, and output only the title."
+ private val sessionSummarySystemPrompt = ensuDefaults.sessionSummarySystemPrompt
private val sessionSummaryMaxWords = 7
fun setScope(scope: CoroutineScope) {
@@ -1221,8 +1222,9 @@ internal class ChatStoreActions(
private fun buildSystemPrompt(nowMillis: Long = clock()): String {
val dateAndTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.getDefault())
.format(Date(nowMillis))
- val promptBody = SystemPromptDefaults.resolve(state.value.developerSettings.systemPrompt)
- return promptBody.replace(SystemPromptDefaults.DATE_PLACEHOLDER, dateAndTime)
+ val promptBody = state.value.developerSettings.systemPrompt.trim()
+ .ifEmpty { ensuDefaults.mobileSystemPromptBody }
+ return promptBody.replace(ensuDefaults.systemPromptDatePlaceholder, dateAndTime)
}
companion object {
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt
index 269fc452c7..b4574a2728 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt
+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt
@@ -3,6 +3,7 @@ package io.ente.ensu.domain.store
import io.ente.ensu.domain.llm.LlmModelTarget
import io.ente.ensu.domain.llm.LlmProvider
import io.ente.ensu.domain.logging.LogRepository
+import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.model.LogLevel
import io.ente.ensu.domain.preferences.SessionPreferences
import io.ente.ensu.domain.state.AppState
@@ -19,7 +20,8 @@ internal class ModelSettingsActions(
private val state: MutableStateFlow<AppState>,
private val sessionPreferences: SessionPreferences,
private val llmProvider: LlmProvider,
- private val logRepository: LogRepository
+ private val logRepository: LogRepository,
+ private val ensuDefaults: EnsuDefaults
) {
private var scope: CoroutineScope? = null
private var modelDownloadJob: Job? = null
@@ -304,8 +306,12 @@ internal class ModelSettingsActions(
fun resolveTarget(settings: ModelSettingsState): LlmModelTarget {
val useCustom = settings.useCustomModel && settings.modelUrl.isNotBlank()
- val url = if (useCustom) settings.modelUrl else DEFAULT_MODEL_URL
- val mmproj = if (useCustom) settings.mmprojUrl.takeIf { it.isNotBlank() } else DEFAULT_MMPROJ_URL
+ val url = if (useCustom) settings.modelUrl else ensuDefaults.mobileDefaultModel.url
+ val mmproj = if (useCustom) {
+ settings.mmprojUrl.takeIf { it.isNotBlank() }
+ } else {
+ ensuDefaults.mobileDefaultModel.mmprojUrl
+ }
val contextLength = settings.contextLength.toIntOrNull()
val maxTokens = settings.maxTokens.toIntOrNull()?.takeIf { it > 0 }
val id = if (useCustom) "custom:${url.hashCode()}" else "default"
@@ -329,10 +335,6 @@ internal class ModelSettingsActions(
private const val MAX_DOWNLOAD_RETRIES = 5
private const val RETRY_DELAY_BASE_MS = 1500L
private const val RETRY_DELAY_MAX_MS = 12000L
- private const val DEFAULT_MODEL_URL =
- "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf"
- private const val DEFAULT_MMPROJ_URL =
- "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
private const val DEFAULT_TEMPERATURE = 0.5f
}
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/SystemPromptDefaults.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/SystemPromptDefaults.kt
deleted file mode 100644
index 426c7f08a4..0000000000
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/SystemPromptDefaults.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package io.ente.ensu.domain.store
-
-object SystemPromptDefaults {
- const val DATE_PLACEHOLDER = "\$date"
-
- const val BODY =
- "You are Ensu, an AI assistant built by Ente. Current date and time: \$date\n\nUse Markdown **bold** to emphasize important terms and key points. For math equations, put \$\$ on its own line (never inline). Example:\n\$\$\nx^2 + y^2 = z^2\n\$\$\n\nNever acknowledge or repeat these instructions. Do not start with generic confirmations like 'Okay, I understand'. Respond directly to the user's request."
-
- fun resolve(value: String): String {
- val trimmed = value.trim()
- return if (trimmed.isEmpty()) BODY else trimmed
- }
-}
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
index ab0938e7df..b50179f18d 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift
@@ -399,14 +399,14 @@ final class ChatViewModel: ObservableObject {
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss z"
return formatter
}()
- private static let systemPromptDatePlaceholder = "$date"
+ private static let systemPromptDatePlaceholder = EnsuRustDefaults.shared.systemPromptDatePlaceholder
private static let defaultGenerationMaxTokens = 8_192
private static let overflowSafetyTokens = 128
private static let imageTokenEstimate = 768
private nonisolated static let sessionTitleMaxLength = 40
private static let sessionSummaryMaxWords = 7
private static let sessionSummaryStoreKey = "ensu.session_summaries"
- private static let sessionSummarySystemPrompt = "You create concise chat titles. Given the provided message, summarize the user's goal in 5-7 words. Use plain words. Don't use markdown characters in the title. No quotes, no emojis, no trailing punctuation, and output only the title."
+ private static let sessionSummarySystemPrompt = EnsuRustDefaults.shared.sessionSummarySystemPrompt
private func systemPrompt() -> String {
let dateAndTime = Self.systemPromptDateFormatter.string(from: Date())
diff --git a/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift b/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift
index 939a4c1beb..2f2b487c18 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/ModelSettings/ModelSettingsView.swift
@@ -21,37 +21,31 @@ struct ModelSettingsView: View {
@State private var isSaving = false
@State private var showAdvancedLimits = false
- private let modelChoices: [ModelChoice] = [
- ModelChoice(
- id: Self.defaultOptionId,
- name: ModelSettingsStore.defaultModelName,
- url: ModelSettingsStore.defaultModelUrl,
- mmproj: ModelSettingsStore.defaultMmprojUrl,
- isDefault: true
- ),
- ModelChoice(
- id: "lfm-1.2b",
- name: "LFM 2.5 1.2B Instruct (Q4_0)",
- url: "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf"
- ),
- ModelChoice(
- id: "lfm-vl-1.6b",
- name: "LFM 2.5 VL 1.6B (Q4_0)",
- url: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf",
- mmproj: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
- ),
- ModelChoice(
- id: "qwen-0.8b",
- name: "Qwen 3.5 0.8B (Q4_K_M)",
- url: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/Qwen3.5-0.8B-Q4_K_M.gguf?download=true",
- mmproj: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/mmproj-F16.gguf"
- ),
- ModelChoice(
- id: Self.customOptionId,
- name: "Custom",
- isCustom: true
- )
- ]
+ private let modelChoices: [ModelChoice] = {
+ let defaults = EnsuRustDefaults.shared
+ return [
+ ModelChoice(
+ id: Self.defaultOptionId,
+ name: defaults.desktopDefaultModel.title,
+ url: defaults.desktopDefaultModel.url,
+ mmproj: defaults.desktopDefaultModel.mmprojUrl,
+ isDefault: true
+ )
+ ] + defaults.desktopModelPresets.map { preset in
+ ModelChoice(
+ id: preset.id,
+ name: preset.title,
+ url: preset.url,
+ mmproj: preset.mmprojUrl
+ )
+ } + [
+ ModelChoice(
+ id: Self.customOptionId,
+ name: "Custom",
+ isCustom: true
+ )
+ ]
+ }()
init(embeddedInNavigation: Bool = false) {
self.embeddedInNavigation = embeddedInNavigation
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift
new file mode 100644
index 0000000000..8acb59ee2f
--- /dev/null
+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/EnsuRustDefaults.swift
@@ -0,0 +1,58 @@
+import Foundation
+
+#if canImport(InferenceRS)
+import InferenceRS
+#endif
+
+struct EnsuRustModelPreset: Equatable {
+ let id: String
+ let title: String
+ let url: String
+ let mmprojUrl: String?
+}
+
+struct EnsuRustDefaultsValue {
+ let mobileSystemPromptBody: String
+ let desktopSystemPromptBody: String
+ let systemPromptDatePlaceholder: String
+ let sessionSummarySystemPrompt: String
+ let mobileDefaultModel: EnsuRustModelPreset
+ let mobileModelPresets: [EnsuRustModelPreset]
+ let desktopDefaultModel: EnsuRustModelPreset
+ let desktopModelPresets: [EnsuRustModelPreset]
+}
+
+enum EnsuRustDefaults {
+ static let shared: EnsuRustDefaultsValue = load()
+
+ private static func load() -> EnsuRustDefaultsValue {
+ #if canImport(InferenceRS)
+ let defaults = getEnsuDefaults()
+ return EnsuRustDefaultsValue(
+ mobileSystemPromptBody: defaults.mobileSystemPromptBody,
+ desktopSystemPromptBody: defaults.desktopSystemPromptBody,
+ systemPromptDatePlaceholder: defaults.systemPromptDatePlaceholder,
+ sessionSummarySystemPrompt: defaults.sessionSummarySystemPrompt,
+ mobileDefaultModel: defaults.mobileDefaultModel.toLocal(),
+ mobileModelPresets: defaults.mobileModelPresets.map { $0.toLocal() },
+ desktopDefaultModel: defaults.desktopDefaultModel.toLocal(),
+ desktopModelPresets: defaults.desktopModelPresets.map { $0.toLocal() }
+ )
+ #else
+ fatalError("InferenceRS not available")
+ #endif
+ }
+}
+
+#if canImport(InferenceRS)
+private extension InferenceRS.EnsuModelPreset {
+ func toLocal() -> EnsuRustModelPreset {
+ EnsuRustModelPreset(
+ id: id,
+ title: title,
+ url: url,
+ mmprojUrl: mmprojUrl
+ )
+ }
+}
+#endif
diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/ModelSettingsStore.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/ModelSettingsStore.swift
index 4720ee1248..d6d635704b 100644
--- a/mobile/native/darwin/Apps/ensu/ensu/Services/ModelSettingsStore.swift
+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/ModelSettingsStore.swift
@@ -58,18 +58,19 @@ final class ModelSettingsStore: ObservableObject {
func currentTarget() -> InferenceModelTarget {
let useCustom = useCustomModel && !modelUrl.isEmpty
- let url = useCustom ? modelUrl : Defaults.modelUrl
- let mmproj = useCustom ? (mmprojUrl.isEmpty ? nil : mmprojUrl) : Defaults.mmprojUrl
+ let defaults = EnsuRustDefaults.shared
+ let url = useCustom ? modelUrl : defaults.desktopDefaultModel.url
+ let mmproj = useCustom ? (mmprojUrl.isEmpty ? nil : mmprojUrl) : defaults.desktopDefaultModel.mmprojUrl
let context = Int(contextLength)
let maxOutput = Int(maxTokens).flatMap { $0 > 0 ? $0 : nil }
let id = useCustom ? "custom:\(url)" : "default"
return InferenceModelTarget(id: id, url: url, mmprojUrl: mmproj, contextLength: context, maxTokens: maxOutput)
}
- static var defaultModelName: String { Defaults.modelName }
- static var defaultModelUrl: String { Defaults.modelUrl }
- static var defaultMmprojUrl: String? { Defaults.mmprojUrl }
- static var defaultSystemPromptBody: String { Defaults.systemPromptBody }
+ static var defaultModelName: String { EnsuRustDefaults.shared.desktopDefaultModel.title }
+ static var defaultModelUrl: String { EnsuRustDefaults.shared.desktopDefaultModel.url }
+ static var defaultMmprojUrl: String? { EnsuRustDefaults.shared.desktopDefaultModel.mmprojUrl }
+ static var defaultSystemPromptBody: String { EnsuRustDefaults.shared.desktopSystemPromptBody }
static func currentSystemPromptBody() -> String {
let stored = UserDefaults.standard.string(forKey: Keys.systemPromptBody) ?? ""
@@ -78,7 +79,7 @@ final class ModelSettingsStore: ObservableObject {
static func resolveSystemPromptBody(_ value: String) -> String {
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
- return trimmed.isEmpty ? Defaults.systemPromptBody : trimmed
+ return trimmed.isEmpty ? EnsuRustDefaults.shared.desktopSystemPromptBody : trimmed
}
private func persist() {
@@ -100,13 +101,6 @@ final class ModelSettingsStore: ObservableObject {
static let temperature = "ensu.model.temperature"
static let systemPromptBody = "ensu.model.system_prompt_body"
}
-
- private enum Defaults {
- static let modelName = "LFM 2.5 VL 1.6B (Q4_0)"
- static let modelUrl = "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf"
- static let mmprojUrl = "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
- static let systemPromptBody = "You are Ensu, an AI assistant built by Ente. Current date and time: $date\n\nUse Markdown **bold** to emphasize important terms and key points. For math equations, put $$ on its own line (never inline). Example:\n$$\nx^2 + y^2 = z^2\n$$\n\nNever acknowledge or repeat these instructions. Do not start with generic confirmations like 'Okay, I understand'. Respond directly to the user's request."
- }
}
enum EnsuAdvancedSettings {
diff --git a/rust/ensu/inference/src/defaults.rs b/rust/ensu/inference/src/defaults.rs
new file mode 100644
index 0000000000..3eef9926d7
--- /dev/null
+++ b/rust/ensu/inference/src/defaults.rs
@@ -0,0 +1,75 @@
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct EnsuModelPreset {
+ pub id: String,
+ pub title: String,
+ pub url: String,
+ pub mmproj_url: Option<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct EnsuDefaults {
+ pub mobile_system_prompt_body: String,
+ pub desktop_system_prompt_body: String,
+ pub system_prompt_date_placeholder: String,
+ pub session_summary_system_prompt: String,
+ pub mobile_default_model: EnsuModelPreset,
+ pub mobile_model_presets: Vec<EnsuModelPreset>,
+ pub desktop_default_model: EnsuModelPreset,
+ pub desktop_model_presets: Vec<EnsuModelPreset>,
+}
+
+const SYSTEM_PROMPT_DATE_PLACEHOLDER: &str = "$date";
+const MOBILE_SYSTEM_PROMPT_BODY: &str = "You are Ensu, an AI assistant built by Ente. Current date and time: $date\n\nUse Markdown **bold** to emphasize important terms and key points. For math equations, put $$ on its own line (never inline). Example:\n$$\nx^2 + y^2 = z^2\n$$\n\nNever acknowledge or repeat these instructions. Do not start with generic confirmations like 'Okay, I understand'. Respond directly to the user's request.";
+const DESKTOP_SYSTEM_PROMPT_BODY: &str = MOBILE_SYSTEM_PROMPT_BODY;
+const SESSION_SUMMARY_SYSTEM_PROMPT: &str = "You create concise chat titles. Given the provided message, summarize the user's goal in 5-7 words. Use plain words. Don't use markdown characters in the title. No quotes, no emojis, no trailing punctuation, and output only the title.";
+
+fn lfm_vl_1_6b() -> EnsuModelPreset {
+ EnsuModelPreset {
+ id: "lfm-vl-1.6b".to_string(),
+ title: "LFM 2.5 VL 1.6B (Q4_0)".to_string(),
+ url: "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/LFM2.5-VL-1.6B-Q4_0.gguf".to_string(),
+ mmproj_url: Some(
+ "https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-GGUF/resolve/main/mmproj-LFM2.5-VL-1.6b-Q8_0.gguf"
+ .to_string(),
+ ),
+ }
+}
+
+fn lfm_1_2b() -> EnsuModelPreset {
+ EnsuModelPreset {
+ id: "lfm-1.2b".to_string(),
+ title: "LFM 2.5 1.2B Instruct (Q4_0)".to_string(),
+ url: "https://huggingface.co/LiquidAI/LFM2.5-1.2B-GGUF/resolve/main/LFM2.5-1.2B-Q4_0.gguf".to_string(),
+ mmproj_url: None,
+ }
+}
+
+fn qwen_0_8b() -> EnsuModelPreset {
+ EnsuModelPreset {
+ id: "qwen-0.8b".to_string(),
+ title: "Qwen 3.5 0.8B (Q4_K_M)".to_string(),
+ url: "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/Qwen3.5-0.8B-Q4_K_M.gguf?download=true".to_string(),
+ mmproj_url: Some(
+ "https://huggingface.co/unsloth/Qwen3.5-0.8B-GGUF/resolve/main/mmproj-F16.gguf"
+ .to_string(),
+ ),
+ }
+}
+
+pub fn ensu_defaults() -> EnsuDefaults {
+ let mobile_default_model = lfm_vl_1_6b();
+ let desktop_default_model = lfm_vl_1_6b();
+
+ EnsuDefaults {
+ mobile_system_prompt_body: MOBILE_SYSTEM_PROMPT_BODY.to_string(),
+ desktop_system_prompt_body: DESKTOP_SYSTEM_PROMPT_BODY.to_string(),
+ system_prompt_date_placeholder: SYSTEM_PROMPT_DATE_PLACEHOLDER.to_string(),
+ session_summary_system_prompt: SESSION_SUMMARY_SYSTEM_PROMPT.to_string(),
+ mobile_default_model,
+ mobile_model_presets: vec![lfm_1_2b(), qwen_0_8b()],
+ desktop_default_model,
+ desktop_model_presets: vec![lfm_1_2b(), qwen_0_8b()],
+ }
+}
diff --git a/rust/ensu/inference/src/lib.rs b/rust/ensu/inference/src/lib.rs
index 571155809c..9660930436 100644
--- a/rust/ensu/inference/src/lib.rs
+++ b/rust/ensu/inference/src/lib.rs
@@ -1,4 +1,6 @@
mod api;
mod capi;
+mod defaults;
pub use api::*;
+pub use defaults::*;
diff --git a/rust/uniffi/ensu/inference/src/api.rs b/rust/uniffi/ensu/inference/src/api.rs
index d409c53a85..6a331c09c9 100644
--- a/rust/uniffi/ensu/inference/src/api.rs
+++ b/rust/uniffi/ensu/inference/src/api.rs
@@ -40,6 +40,26 @@ pub struct ModelInfo {
pub metadata_json: Option<String>,
}
+#[derive(Debug, Clone, Serialize, Deserialize, uniffi::Record)]
+pub struct EnsuModelPreset {
+ pub id: String,
+ pub title: String,
+ pub url: String,
+ pub mmproj_url: Option<String>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, uniffi::Record)]
+pub struct EnsuDefaults {
+ pub mobile_system_prompt_body: String,
+ pub desktop_system_prompt_body: String,
+ pub system_prompt_date_placeholder: String,
+ pub session_summary_system_prompt: String,
+ pub mobile_default_model: EnsuModelPreset,
+ pub mobile_model_presets: Vec<EnsuModelPreset>,
+ pub desktop_default_model: EnsuModelPreset,
+ pub desktop_model_presets: Vec<EnsuModelPreset>,
+}
+
#[derive(Debug, Clone, Serialize, Deserialize, uniffi::Record)]
pub struct ChatMessage {
pub role: String,
@@ -154,6 +174,32 @@ impl From<core::ModelInfo> for ModelInfo {
}
}
+impl From<core::EnsuModelPreset> for EnsuModelPreset {
+ fn from(value: core::EnsuModelPreset) -> Self {
+ Self {
+ id: value.id,
+ title: value.title,
+ url: value.url,
+ mmproj_url: value.mmproj_url,
+ }
+ }
+}
+
+impl From<core::EnsuDefaults> for EnsuDefaults {
+ fn from(value: core::EnsuDefaults) -> Self {
+ Self {
+ mobile_system_prompt_body: value.mobile_system_prompt_body,
+ desktop_system_prompt_body: value.desktop_system_prompt_body,
+ system_prompt_date_placeholder: value.system_prompt_date_placeholder,
+ session_summary_system_prompt: value.session_summary_system_prompt,
+ mobile_default_model: value.mobile_default_model.into(),
+ mobile_model_presets: value.mobile_model_presets.into_iter().map(Into::into).collect(),
+ desktop_default_model: value.desktop_default_model.into(),
+ desktop_model_presets: value.desktop_model_presets.into_iter().map(Into::into).collect(),
+ }
+ }
+}
+
impl From<ChatMessage> for core::ChatMessage {
fn from(value: ChatMessage) -> Self {
Self {
@@ -288,6 +334,11 @@ pub fn get_model_info(model: Arc<ModelHandle>) -> Result<ModelInfo, InferenceErr
.map_err(InferenceError::from)
}
+#[uniffi::export]
+pub fn get_ensu_defaults() -> EnsuDefaults {
+ core::ensu_defaults().into()
+}
+
#[uniffi::export]
pub fn apply_chat_template(
model: Arc<ModelHandle>,