Skip to content

Commit 950a046

Browse files
Fix: Resolve import conflicts and simplify logging for build stability
This commit addresses persistent compilation errors by: 1. **ScreenCaptureService.kt:** * Resolving a potential duplicate/conflicting import for `TextPart`. * Drastically simplifying the diagnostic logging for AI responses. Instead of iterating through each `Part` (which caused "Unresolved reference: parts" and lambda errors), it now only logs the total number of parts in the `aiResponse`. This minimizes the chance of complex syntax errors. 2. **PhotoReasoningViewModel.kt (User Intervention Reminder):** * This commit relies on you having manually removed or commented out the problematic detailed logging loops (the `forEachIndexed` blocks containing `content.parts.joinToString { part -> when(part)... }`) in the `rebuildChatHistory` and `sendMessageWithRetry` methods. These loops were causing "Only one lambda expression is allowed outside a parenthesized argument list" errors, and my attempts to fix them automatically were unsuccessful. The primary goal of this commit is to achieve a stable, compilable build so that the underlying fix for chat history truncation (the comprehensive DTO/Mapper system) can be tested by you. Key logs for history *sizes* remain.
1 parent a9341cd commit 950a046

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.google.ai.client.generativeai.type.FunctionCallPart // For logging AI
3232
import com.google.ai.client.generativeai.type.FunctionResponsePart // For logging AI response
3333
import com.google.ai.client.generativeai.type.BlobPart // For logging AI response
3434
import com.google.ai.client.generativeai.type.TextPart // For logging AI response
35-
import com.google.ai.client.generativeai.type.TextPart // For logging AI response
35+
// Removed duplicate TextPart import
3636
import com.google.ai.sample.feature.multimodal.dtos.ContentDto
3737
import com.google.ai.sample.feature.multimodal.dtos.toSdk
3838
import kotlinx.coroutines.CoroutineScope
@@ -254,29 +254,18 @@ 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-
// Corrected logging for aiResponse structure
258-
if (aiResponse != null && aiResponse.parts.isNotEmpty()) {
259-
Log.d(TAG, "Service received AI Response. Number of parts: ${aiResponse.parts.size}")
260-
Log.d(TAG, "Parts summary: ${aiResponse.parts.joinToString { part -> part.javaClass.simpleName }}")
261-
262-
aiResponse.parts.filterIsInstance<com.google.ai.client.generativeai.type.FunctionCallPart>().forEach { fcp ->
263-
Log.d(TAG, " AI sent FunctionCallPart: name='${fcp.name}', args='${fcp.args}'")
264-
}
265-
aiResponse.parts.filterIsInstance<com.google.ai.client.generativeai.type.FunctionResponsePart>().forEach { frp ->
266-
Log.d(TAG, " AI sent FunctionResponsePart: name='${frp.name}', response='${frp.response.toString().take(100)}...'")
267-
}
268-
aiResponse.parts.filterIsInstance<com.google.ai.client.generativeai.type.BlobPart>().forEach { bp ->
269-
Log.d(TAG, " AI sent BlobPart: mimeType='${bp.mimeType}', dataSize=${bp.blob.size}")
270-
}
271-
aiResponse.parts.filterIsInstance<com.google.ai.client.generativeai.type.TextPart>().forEach { tp ->
272-
Log.d(TAG, " AI sent TextPart: text='${tp.text.take(100)}...'")
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}")
273264
}
274-
} else if (aiResponse != null) {
275-
Log.d(TAG, "Service received AI Response with zero parts.")
276265
} else {
277-
Log.d(TAG, "Service received null AI Response object.") // Should be caught by exception ideally
266+
Log.d(TAG, "Service received null AI Response object.")
278267
}
279-
responseText = aiResponse?.text // Existing line
268+
responseText = aiResponse?.text // This line should remain
280269
Log.d(TAG, "AI call successful. Response text available: ${responseText != null}")
281270

282271
} catch (e: Exception) {

0 commit comments

Comments
 (0)