Skip to content

Commit 6597ac3

Browse files
Fix: Correct AI response handling and joinToString syntax
- Modified ScreenCaptureService.kt to correctly access AI response text property instead of non-existent 'parts'. - Fixed syntax errors in PhotoReasoningViewModel.kt for multiple joinToString calls by removing the extra lambda.
1 parent 950a046 commit 6597ac3

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

File renamed without changes.

app/src/main/kotlin/com/google/ai/sample/ScreenCaptureService.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,15 @@ class ScreenCaptureService : Service() {
254254
Log.d(TAG, "Executing AI sendMessage with history size: ${chatHistory.size}")
255255
val aiResponse = tempChat.sendMessage(inputContent) // Use the mapped SDK inputContent
256256

257-
if (aiResponse != null) {
258-
Log.d(TAG, "Service received AI Response. Success: true, Number of parts: ${aiResponse.parts.size}")
259-
// Attempt a simple joinToString; if this also fails, it will need to be removed too.
260-
try {
261-
Log.d(TAG, "Parts summary: ${aiResponse.parts.joinToString { it.javaClass.simpleName }}")
262-
} catch (e: Exception) {
263-
Log.e(TAG, "Error creating parts summary log: ${e.message}")
264-
}
265-
} else {
266-
Log.d(TAG, "Service received null AI Response object.")
267-
}
257+
if (aiResponse != null) {
258+
Log.d(TAG, "Service received AI Response. Success: true")
259+
// The response doesn't have a 'parts' property directly
260+
// If you need to log the response content, use the text property
261+
val responseLength = aiResponse.text?.length ?: 0
262+
Log.d(TAG, "Response text length: $responseLength")
263+
} else {
264+
Log.d(TAG, "Service received null AI Response object.")
265+
}
268266
responseText = aiResponse?.text // This line should remain
269267
Log.d(TAG, "AI call successful. Response text available: ${responseText != null}")
270268

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class PhotoReasoningViewModel(
383383

384384
Log.d(TAG, "sendMessageWithRetry: Preparing to serialize chat.history. Current chat.history size: ${chat.history.size}")
385385
chat.history.forEachIndexed { index, content ->
386-
Log.d(TAG, " ViewModel chat.history Content[$index]: role=${content.role}, parts=${content.parts.joinToString { it.javaClass.simpleName } { part ->
386+
Log.d(TAG, " ViewModel chat.history Content[$index]: role=${content.role}, parts=${content.parts.joinToString { part ->
387387
when(part) {
388388
is com.google.ai.client.generativeai.type.TextPart -> "Text(\"${part.text.take(50)}...\")"
389389
is com.google.ai.client.generativeai.type.ImagePart -> "Image"
@@ -719,10 +719,10 @@ class PhotoReasoningViewModel(
719719

720720
Log.d(TAG, "rebuildChatHistory: Finished processing. Generated SDK history size: ${history.size}")
721721
history.forEachIndexed { index, content ->
722-
Log.d(TAG, " Generated SDK.Content[$index]: role=${content.role}, parts=${content.parts.joinToString { it.javaClass.simpleName } { part ->
722+
Log.d(TAG, " Generated SDK.Content[$index]: role=${content.role}, parts=${content.parts.joinToString { part ->
723723
when(part) {
724724
is com.google.ai.client.generativeai.type.TextPart -> "Text(\"${part.text.take(50)}...\")"
725-
is com.google.ai.client.generativeai.type.ImagePart -> "Image" // Bitmaps are not easily loggable
725+
is com.google.ai.client.generativeai.type.ImagePart -> "Image"
726726
is com.google.ai.client.generativeai.type.BlobPart -> "Blob(${part.mimeType})"
727727
is com.google.ai.client.generativeai.type.FunctionCallPart -> "FunctionCall(${part.name}, args=${part.args})"
728728
is com.google.ai.client.generativeai.type.FunctionResponsePart -> "FunctionResponse(${part.name})"

0 commit comments

Comments
 (0)