Skip to content

Commit 61b480b

Browse files
committed
Fix
1 parent 69744c1 commit 61b480b

4 files changed

Lines changed: 8 additions & 53 deletions

File tree

llm/android/LlamaDemo/app/src/androidTest/java/com/example/executorchllamademo/UIWorkflowTest.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,10 @@ class UIWorkflowTest {
106106
return
107107
}
108108

109-
// Click Clear Chat History button
109+
// Click Clear Chat History button (clears immediately, no confirmation dialog)
110110
try {
111111
composeTestRule.onNodeWithText("Clear Chat History").performClick()
112112
composeTestRule.waitForIdle()
113-
114-
// Wait for confirmation dialog and click Yes
115-
composeTestRule.waitUntil(timeoutMillis = 2000) {
116-
composeTestRule.onAllNodesWithText("Delete Chat History")
117-
.fetchSemanticsNodes().isNotEmpty()
118-
}
119-
composeTestRule.onNodeWithText("Yes").performClick()
120-
composeTestRule.waitForIdle()
121113
Log.i(TAG, "Chat history cleared")
122114
} catch (e: Exception) {
123115
Log.d(TAG, "Could not clear chat history: ${e.message}")

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/screens/SettingsScreen.kt

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fun SettingsScreen(
327327

328328
// Clear Chat button
329329
Button(
330-
onClick = { viewModel.showClearChatDialog = true },
330+
onClick = { viewModel.confirmClearChat() },
331331
modifier = Modifier.fillMaxWidth(),
332332
colors = ButtonDefaults.buttonColors(containerColor = BtnEnabled),
333333
shape = RoundedCornerShape(8.dp)
@@ -347,7 +347,6 @@ fun SettingsScreen(
347347
DataPathDialog(viewModel)
348348
ModelTypeDialog(viewModel)
349349
LoadModelDialog(viewModel, onLoadModel, onBackPressed)
350-
ClearChatDialog(viewModel)
351350
ResetSystemPromptDialog(viewModel)
352351
ResetUserPromptDialog(viewModel)
353352
InvalidPromptDialog(viewModel)
@@ -574,38 +573,6 @@ private fun LoadModelDialog(
574573
}
575574
}
576575

577-
@Composable
578-
private fun ClearChatDialog(viewModel: SettingsViewModel) {
579-
if (viewModel.showClearChatDialog) {
580-
AlertDialog(
581-
onDismissRequest = { viewModel.showClearChatDialog = false },
582-
icon = {
583-
Icon(
584-
imageVector = Icons.Filled.Warning,
585-
contentDescription = null
586-
)
587-
},
588-
title = { Text("Delete Chat History") },
589-
text = { Text("Do you really want to delete chat history?") },
590-
confirmButton = {
591-
TextButton(
592-
onClick = {
593-
viewModel.confirmClearChat()
594-
viewModel.showClearChatDialog = false
595-
}
596-
) {
597-
Text("Yes")
598-
}
599-
},
600-
dismissButton = {
601-
TextButton(onClick = { viewModel.showClearChatDialog = false }) {
602-
Text("No")
603-
}
604-
}
605-
)
606-
}
607-
}
608-
609576
@Composable
610577
private fun ResetSystemPromptDialog(viewModel: SettingsViewModel) {
611578
if (viewModel.showResetSystemPromptDialog) {

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/ChatViewModel.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
6666
val selectedImages: List<Uri> = _selectedImages
6767

6868
// Dialog states
69-
var showSelectModelDialog by mutableStateOf(false)
7069
var showModelLoadErrorDialog by mutableStateOf(false)
7170
var modelLoadError by mutableStateOf("")
7271

@@ -103,13 +102,15 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
103102
demoSharedPreferences.addMessages(_messages.toList())
104103
}
105104

105+
private val systemPromptMessage = "To get started, select your desired model and tokenizer from the top right corner"
106+
106107
fun checkAndLoadSettings() {
107108
val gson = Gson()
108109
val settingsFieldsJSON = demoSharedPreferences.getSettings()
109110
if (settingsFieldsJSON.isNotEmpty()) {
110111
val updatedSettingsFields = gson.fromJson(settingsFieldsJSON, SettingsFields::class.java)
111112
if (updatedSettingsFields == null) {
112-
showSelectModelDialog = true
113+
addSystemMessage(systemPromptMessage)
113114
return
114115
}
115116
val isUpdated = currentSettingsFields != updatedSettingsFields
@@ -130,19 +131,19 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
130131
updatedSettingsFields.saveLoadModelAction(false)
131132
demoSharedPreferences.addSettings(updatedSettingsFields)
132133
} else if (module == null) {
133-
showSelectModelDialog = true
134+
addSystemMessage(systemPromptMessage)
134135
}
135136
} else {
136137
// Settings unchanged, but still update media capabilities for current settings
137138
setBackendMode(updatedSettingsFields.backendType)
138139
val modelPath = updatedSettingsFields.modelFilePath
139140
val tokenizerPath = updatedSettingsFields.tokenizerFilePath
140141
if (modelPath.isEmpty() || tokenizerPath.isEmpty()) {
141-
showSelectModelDialog = true
142+
addSystemMessage(systemPromptMessage)
142143
}
143144
}
144145
} else if (module == null) {
145-
showSelectModelDialog = true
146+
addSystemMessage(systemPromptMessage)
146147
}
147148
}
148149

@@ -463,10 +464,6 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), L
463464
}
464465
}
465466

466-
fun dismissSelectModelDialog() {
467-
showSelectModelDialog = false
468-
}
469-
470467
fun dismissModelLoadErrorDialog() {
471468
showModelLoadErrorDialog = false
472469
}

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/ui/viewmodel/SettingsViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class SettingsViewModel : ViewModel() {
3535
var showDataPathDialog by mutableStateOf(false)
3636
var showModelTypeDialog by mutableStateOf(false)
3737
var showLoadModelDialog by mutableStateOf(false)
38-
var showClearChatDialog by mutableStateOf(false)
3938
var showResetSystemPromptDialog by mutableStateOf(false)
4039
var showResetUserPromptDialog by mutableStateOf(false)
4140
var showInvalidPromptDialog by mutableStateOf(false)

0 commit comments

Comments
 (0)