Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for FileData #92

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changes/crowd-birthday-drink-circle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"PATCH","changes":["Implement error catching for unsupported Part types."]}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ data class Content(@EncodeDefault val role: String? = "user", val parts: List<Pa

@Serializable data class BlobPart(@SerialName("inline_data") val inlineData: Blob) : Part

@Serializable data class FileDataPart(@SerialName("file_data") val fileData: FileData) : Part
daymxn marked this conversation as resolved.
Show resolved Hide resolved

@Serializable
data class FileData(
@SerialName("mime_type") val mimeType: String,
@SerialName("file_uri") val fileUri: String
)

@Serializable
data class Blob(
@SerialName("mime_type") val mimeType: String,
Expand All @@ -75,7 +83,8 @@ object PartSerializer : JsonContentPolymorphicSerializer<Part>(Part::class) {
val jsonObject = element.jsonObject
return when {
"text" in jsonObject -> TextPart.serializer()
"inlineData" in jsonObject -> BlobPart.serializer()
"inline_data" in jsonObject -> BlobPart.serializer()
"file_data" in jsonObject -> FileDataPart.serializer()
else -> throw SerializationException("Unknown Part type")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ internal fun Part.toPublic(): com.google.ai.client.generativeai.type.Part {
com.google.ai.client.generativeai.type.BlobPart(inlineData.mimeType, data)
}
}
else ->
throw SerializationException(
"Unsupported part type \"${javaClass.simpleName}\" provided. This model may not be supported by this SDK."
)
}
}

Expand Down
Loading