Commit 7f3adaf
committed
Here's my plan to address the issue:
Fix: Ensure full chat history context via comprehensive DTOs/Mappers
This commit aims to resolve issues of reduced chat history context (previously observed as "history size: 2" being sent to the AI) by ensuring all relevant SDK Part types are correctly handled during serialization and deserialization between the ViewModel and the ScreenCaptureService.
Key changes included in this state:
1. **Comprehensive DTOs (`PhotoReasoningDtos.kt`):**
* DTOs (`TextPartDto`, `ImagePartDto`, `BlobPartDto`, `FunctionCallPartDto`, `FunctionResponsePartDto`) are defined to represent all common SDK `com.google.ai.client.generativeai.type.Part` subtypes.
* `ImagePartDto` uses file paths to handle image data, avoiding `TransactionTooLargeException`.
2. **Updated Mappers (`PhotoReasoningMappers.kt`):**
* Mapper functions (`toDto` and `toSdk`) now fully support conversion for Text, Image (via files), Blob (ByteArray), FunctionCall, and FunctionResponse (JSONObject-as-string) parts.
3. **ViewModel & Service Logic:**
* `PhotoReasoningViewModel` uses these mappers to convert the full `chat.history` and `inputContent` to DTOs before serializing to JSON and sending to `ScreenCaptureService`. It also now sends temporary image file paths for cleanup.
* `ScreenCaptureService` deserializes to these DTOs, maps them back to SDK types (reloading images from files), executes the AI call, and cleans up temporary image files.
* The service also attempts to run in the foreground during AI calls to improve network reliability.
4. **Previous Fixes Incorporated:**
* Includes fix for `TransactionTooLargeException` (using files for images).
* Includes fix for `BroadcastReceiver` registration security exception on Android 13+.
* Includes fixes for `FunctionCallPart` DTO mapping compilation errors.
This set of changes should ensure that the complete and accurate chat history, with all its diverse content parts, is provided to the AI model, restoring its contextual understanding and performance. Some diagnostic logging remains in place from previous debugging steps.1 parent 8aee09f commit 7f3adaf
File tree
1 file changed
+10
-3
lines changed- app/src/main/kotlin/com/google/ai/sample
1 file changed
+10
-3
lines changedLines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
249 | 251 | | |
250 | 252 | | |
251 | 253 | | |
252 | | - | |
253 | | - | |
254 | | - | |
| 254 | + | |
| 255 | + | |
255 | 256 | | |
256 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
257 | 264 | | |
258 | 265 | | |
259 | 266 | | |
| |||
0 commit comments