@@ -110,23 +110,26 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
110110 val isLoadModel = updatedSettingsFields.isLoadModel
111111 if (isUpdated) {
112112 checkForClearChatHistory(updatedSettingsFields)
113- // Update media capabilities after settings are updated
114- setBackendMode(updatedSettingsFields.backendType)
115113
116114 if (isLoadModel) {
115+ // Update local copy BEFORE checking media capabilities
116+ val settingsWithLoadFlagCleared = updatedSettingsFields.copy(isLoadModel = false )
117+ currentSettingsFields = settingsWithLoadFlagCleared
118+ demoSharedPreferences.saveModuleSettings(settingsWithLoadFlagCleared)
119+
120+ // Update media capabilities after settings are updated
121+ setBackendMode(updatedSettingsFields.backendType)
122+
117123 loadLocalModelAndParameters(
118124 updatedSettingsFields.modelFilePath,
119125 updatedSettingsFields.tokenizerFilePath,
120126 updatedSettingsFields.dataPath,
121127 updatedSettingsFields.temperature.toFloat()
122128 )
123- // Save with isLoadModel = false and update local copy to match,
124- // preventing duplicate "To get started..." messages on subsequent calls
125- val settingsWithLoadFlagCleared = updatedSettingsFields.copy(isLoadModel = false )
126- demoSharedPreferences.saveModuleSettings(settingsWithLoadFlagCleared)
127- currentSettingsFields = settingsWithLoadFlagCleared
128129 } else {
129130 currentSettingsFields = updatedSettingsFields.copy()
131+ // Update media capabilities after settings are updated
132+ setBackendMode(updatedSettingsFields.backendType)
130133 if (module == null ) {
131134 addSystemMessage(systemPromptMessage)
132135 }
@@ -317,13 +320,13 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
317320 val processedImageList = getProcessedImagesForModel(_selectedImages )
318321 if (processedImageList.isNotEmpty()) {
319322 _messages .add(
320- Message (" Llava - Starting image Prefill ." , false , MessageType .SYSTEM , 0 )
323+ Message (" Starting image prefill ." , false , MessageType .SYSTEM , 0 )
321324 )
322325 executor.execute {
323326 android.os.Process .setThreadPriority(android.os.Process .THREAD_PRIORITY_MORE_FAVORABLE )
324327 ETLogging .getInstance().log(" Starting runnable prefill image" )
325328 val img = processedImageList[0 ]
326- ETLogging .getInstance().log(" Llava start prefill image" )
329+ ETLogging .getInstance().log(" Starting prefill image" )
327330 if (currentSettingsFields.modelType == ModelType .LLAVA_1_5 ) {
328331 module?.prefillImages(
329332 img.getInts(),
@@ -332,6 +335,7 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
332335 ModelUtils .VISION_MODEL_IMAGE_CHANNELS
333336 )
334337 } else if (currentSettingsFields.modelType == ModelType .GEMMA_3 ) {
338+ module?.prefillPrompt(PromptFormat .getGemmaPreImagePrompt())
335339 module?.prefillImages(
336340 img.getFloats(),
337341 img.width,
@@ -372,8 +376,11 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
372376 val rawPrompt = inputText
373377 val finalPrompt: String
374378
375- if (currentSettingsFields.modelType == ModelType .LLAVA_1_5 && shouldAddSystemPrompt) {
376- finalPrompt = PromptFormat .getLlavaFirstTurnUserPrompt()
379+ if (currentSettingsFields.modelType == ModelType .LLAVA_1_5 && _selectedImages .isNotEmpty()) {
380+ finalPrompt = PromptFormat .getLlavaMultimodalUserPrompt()
381+ .replace(PromptFormat .USER_PLACEHOLDER , rawPrompt)
382+ } else if (currentSettingsFields.modelType == ModelType .GEMMA_3 && _selectedImages .isNotEmpty()) {
383+ finalPrompt = PromptFormat .getGemmaMultimodalUserPrompt()
377384 .replace(PromptFormat .USER_PLACEHOLDER , rawPrompt)
378385 } else {
379386 finalPrompt = (if (shouldAddSystemPrompt) currentSettingsFields.getFormattedSystemPrompt() else " " ) +
0 commit comments