Skip to content

Commit 3ac988f

Browse files
Reuse last chat input for auto-screenshot follow-ups
1 parent 3bd9ca8 commit 3ac988f

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

app/src/main/kotlin/com/google/ai/sample/feature/multimodal/PhotoReasoningViewModel.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,29 @@ class PhotoReasoningViewModel(
21612161
saveChatHistory(context)
21622162
}
21632163

2164-
private fun createGenericScreenshotPrompt(): String = ""
2164+
private fun createGenericScreenshotPrompt(): String {
2165+
val lastUserMessage = _chatState.getAllMessages()
2166+
.asReversed()
2167+
.firstOrNull { it.participant == PhotoParticipant.USER && it.text.isNotBlank() }
2168+
?.text
2169+
?.trim()
2170+
2171+
if (!lastUserMessage.isNullOrBlank()) {
2172+
return lastUserMessage
2173+
}
2174+
2175+
val persistedInput = _userInput.value.trim()
2176+
if (persistedInput.isNotBlank()) {
2177+
return persistedInput
2178+
}
2179+
2180+
val lastKnownInput = currentUserInput.trim()
2181+
if (lastKnownInput.isNotBlank()) {
2182+
return lastKnownInput
2183+
}
2184+
2185+
return ""
2186+
}
21652187

21662188
/**
21672189
* Update the system message

0 commit comments

Comments
 (0)