Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.0"
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20"
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
id("kotlin-parcelize")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,7 @@ class PhotoReasoningViewModel(
) {
_uiState.value = PhotoReasoningUiState.Loading

// Get the system message
val systemMessageText = _systemMessage.value

// Create the prompt with system message if available
val prompt = if (systemMessageText.isNotBlank()) {
"System Message: $systemMessageText\n\nFOLLOW THE INSTRUCTIONS STRICTLY: $userInput"
} else {
"FOLLOW THE INSTRUCTIONS STRICTLY: $userInput"
}
val prompt = "FOLLOW THE INSTRUCTIONS STRICTLY: $userInput"

// Store the current user input and selected images
currentUserInput = userInput
Expand Down Expand Up @@ -542,6 +534,10 @@ class PhotoReasoningViewModel(
private fun rebuildChatHistory() {
// Convert the current chat messages to Content objects for the chat history
val history = mutableListOf<Content>()

if (_systemMessage.value.isNotBlank()) {
history.add(content(role = "user") { text(_systemMessage.value) })
}

// Group messages by participant to create proper conversation turns
var currentUserContent = ""
Expand Down Expand Up @@ -607,10 +603,13 @@ class PhotoReasoningViewModel(
_chatState.clearMessages()
_chatMessagesFlow.value = emptyList()

// Reset the chat with empty history
chat = generativeModel.startChat(
history = emptyList()
)
// Reset the chat with empty history or system message
val initialHistory = if (_systemMessage.value.isNotBlank()) {
listOf(content(role = "user") { text(_systemMessage.value) })
} else {
emptyList()
}
chat = generativeModel.startChat(history = initialHistory)

// Also clear from SharedPreferences if context is provided
context?.let {
Expand Down