Skip to content

Commit 161c967

Browse files
Fix: Reconstruct args as HashMap for FunctionCallPartDto mapping
Addresses a persistent and perplexing compilation type mismatch error in PhotoReasoningMappers.kt when mapping FunctionCallPartDto to the SDK's FunctionCallPart. Despite types appearing identical (Map<String, String?>?), the compiler continued to report a mismatch for the 'args' field. This commit modifies the `PartDto.toSdk()` function for the `FunctionCallPartDto` case. Instead of previous reconstruction methods, `this.args` (if not null) is now used to populate a new, explicitly created `HashMap<String, String?>`. This `HashMap` instance is then passed to the SDK's `FunctionCallPart` constructor. This change aims to provide a very concrete and standard `Map` implementation to the SDK, potentially resolving any subtle type incompatibilities or compiler inference issues that previous casting or `toMap()` reconstructions did not.
1 parent ce7d634 commit 161c967

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ fun PartDto.toSdk(): Part { // No context needed here as path is absolute
5656
}
5757
is BlobPartDto -> BlobPart(mimeType = this.mimeType, blob = this.data)
5858
is FunctionCallPartDto -> {
59-
val sdkArgs: Map<String, String?>? = this.args?.let { dtoArgs ->
60-
// Explicitly create a new map to ensure the compiler understands the type correctly.
61-
val newMap = mutableMapOf<String, String?>()
62-
dtoArgs.entries.forEach { entry -> // Iterate through entries
59+
val sdkArgs: HashMap<String, String?>? = this.args?.let { dtoArgs ->
60+
// Explicitly create a HashMap.
61+
val newMap = hashMapOf<String, String?>()
62+
dtoArgs.entries.forEach { entry ->
6363
newMap[entry.key] = entry.value
6464
}
65-
newMap.toMap() // Convert to immutable Map if constructor expects Map, or just newMap if MutableMap is fine.
66-
// Assuming FunctionCallPart constructor takes Map<String, String?>?
65+
newMap
6766
}
6867
FunctionCallPart(name = this.name, args = sdkArgs)
6968
}

0 commit comments

Comments
 (0)