openassistant: load gemma4 maml set, drop legacy model after download
- Commit
500cb1e0e5423a9b53f643a588cc5fdcfa70c237- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-26 21:54 UTC (1 month ago)
- Parents
7181e07
Diff
openassistant/src/main/java/com/vayunmathur/openassistant/util/AssistantViewModel.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/util/AssistantViewModel.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/util/AssistantViewModel.ktindex 1987da319f..2c43f83a93 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/util/AssistantViewModel.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/util/AssistantViewModel.kt@@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.vayunmathur.library.util.DataStoreUtils+import com.vayunmathur.library.downloadservice.ModelUrls import com.vayunmathur.openassistant.data.Conversation import com.vayunmathur.openassistant.data.Memory import com.vayunmathur.openassistant.data.Message@@ -208,16 +209,20 @@ class AssistantViewModel( }) } + /**+ * Deletes the retired single-file Gemma models (and their `.part` leftovers) at the root of+ * the external files dir, but only once the maml set in `gemma4/` is complete, so an+ * upgrading user never ends up with neither. `gemma4/` itself is a directory and is skipped.+ */ private fun cleanupLegacyModelFile() { val context = getApplication<Application>() viewModelScope.launch(Dispatchers.IO) { try {+ if (!ModelUrls.GemmaMaml.isDownloaded(context)) return@launch val externalDir = context.getExternalFilesDir(null) ?: return@launch- val legacyModelFiles = listOf("gemma4.litertlm", "gemma4-4b.litertlm")- for (name in legacyModelFiles) {- if (File(externalDir, name).delete()) {- Log.status(TAG, "Deleted legacy model file $name")- }+ val legacy = externalDir.listFiles { file -> file.isFile && file.name.startsWith("gemma4") }+ for (file in legacy.orEmpty()) {+ if (file.delete()) Log.status(TAG, "Deleted legacy model file ${file.name}") } } catch (expected: Exception) { Log.error(TAG, "Error cleaning up legacy model file", expected)
openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt
diff --git a/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt b/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.ktindex 397ee99bae..ceaf3af096 100644--- a/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt+++ b/openassistant/src/main/java/com/vayunmathur/openassistant/util/InferenceService.kt@@ -15,6 +15,7 @@ import androidx.core.app.NotificationCompat import androidx.core.content.IntentCompat import com.vayunmathur.library.util.SecureResultReceiver import com.vayunmathur.library.util.DataStoreUtils+import com.vayunmathur.library.downloadservice.ModelUrls import com.vayunmathur.openassistant.platform.AssistantTools import com.vayunmathur.openassistant.platform.ChatRequest import com.vayunmathur.openassistant.platform.ChatResult@@ -61,7 +62,6 @@ class InferenceService : Service() { private const val INTENT_QUEUE_TTL_MILLIS = 45000L private const val HISTORY_RECENCY_MILLIS = 1000L private const val DB_WRITE_INTERVAL_MILLIS = 100L- private const val MODEL_DIR = "gemma4" /** The system prompt used when the user has not set a custom one. */ val DEFAULT_SYSTEM_PROMPT = """@@ -434,7 +434,7 @@ class InferenceService : Service() { private suspend fun ensureEngineInitialized() = engineLock.withLock { if (engine != null) return@withLock- val dir = File(applicationContext.getExternalFilesDir(null), MODEL_DIR)+ val dir = ModelUrls.GemmaMaml.modelDir(applicationContext) val created = MamlChatEngine(dir) if (!created.load()) { created.close()