Skip to content

Commit 2fd52e0

Browse files
authored
[FirebaseAI] Handle unknown parts (#1263)
1 parent bde1dc9 commit 2fd52e0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

firebaseai/src/ModelContent.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ internal static ModelContent FromJson(Dictionary<string, object> jsonDict) {
316316
// Both role and parts are required keys
317317
return new ModelContent(
318318
jsonDict.ParseValue<string>("role", JsonParseOptions.ThrowEverything),
319-
jsonDict.ParseObjectList("parts", PartFromJson, JsonParseOptions.ThrowEverything));
319+
// Unknown parts are converted to null, which we then want to filter out here
320+
jsonDict.ParseObjectList("parts", PartFromJson, JsonParseOptions.ThrowEverything).Where(p => p is not null));
320321
}
321322

322323
private static InlineDataPart InlineDataPartFromJson(Dictionary<string, object> jsonDict) {
@@ -335,7 +336,10 @@ private static Part PartFromJson(Dictionary<string, object> jsonDict) {
335336
out var inlineDataPart)) {
336337
return inlineDataPart;
337338
} else {
338-
throw new NotSupportedException("Unable to parse given 'part' into a known Part.");
339+
#if FIREBASEAI_DEBUG_LOGGING
340+
UnityEngine.Debug.LogWarning($"Received unknown part, with keys: {string.Join(',', jsonDict.Keys)}");
341+
#endif
342+
return null;
339343
}
340344
}
341345
}

0 commit comments

Comments
 (0)