Skip to content

Commit a105587

Browse files
author
David Motsonashvili
committed
fix for issue with thought in parts sent as history for template chat
1 parent f761374 commit a105587

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/TemplateGenerativeModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ internal constructor(
128128
): TemplateGenerateContentRequest {
129129
return TemplateGenerateContentRequest(
130130
Json.parseToJsonElement(JSONObject(inputs).toString()).jsonObject,
131-
history?.let { it.map { it.toInternal() } }
131+
history?.let { it.map { it.toInternal(nullPartThought = true) } }
132132
)
133133
}
134134

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Content.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
8585
}
8686

8787
@OptIn(ExperimentalSerializationApi::class)
88-
internal fun toInternal() = Internal(this.role ?: "user", this.parts.map { it.toInternal() })
88+
internal fun toInternal(nullPartThought: Boolean = false) =
89+
Internal(this.role ?: "user", this.parts.map { it.toInternal(nullPartThought) })
8990

9091
@ExperimentalSerializationApi
9192
@Serializable

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Part.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,14 @@ internal object PartSerializer :
337337
}
338338
}
339339

340-
internal fun Part.toInternal(): InternalPart {
340+
internal fun Part.toInternal(nullThought: Boolean): InternalPart {
341+
val thought = if (nullThought) null else isThought
341342
return when (this) {
342-
is TextPart -> TextPart.Internal(text, isThought, thoughtSignature)
343+
is TextPart -> TextPart.Internal(text, thought, thoughtSignature)
343344
is ImagePart ->
344345
InlineDataPart.Internal(
345346
InlineData.Internal("image/jpeg", encodeBitmapToBase64Jpeg(image)),
346-
isThought,
347+
thought,
347348
thoughtSignature
348349
)
349350
is InlineDataPart ->
@@ -352,37 +353,37 @@ internal fun Part.toInternal(): InternalPart {
352353
mimeType,
353354
android.util.Base64.encodeToString(inlineData, BASE_64_FLAGS)
354355
),
355-
isThought,
356+
thought,
356357
thoughtSignature
357358
)
358359
is FunctionCallPart ->
359360
FunctionCallPart.Internal(
360361
FunctionCallPart.Internal.FunctionCall(name, args, id),
361-
isThought,
362+
thought,
362363
thoughtSignature
363364
)
364365
is FunctionResponsePart ->
365366
FunctionResponsePart.Internal(
366367
FunctionResponsePart.Internal.FunctionResponse(name, response, id),
367-
isThought,
368+
thought,
368369
thoughtSignature
369370
)
370371
is FileDataPart ->
371372
FileDataPart.Internal(
372373
FileDataPart.Internal.FileData(mimeType = mimeType, fileUri = uri),
373-
isThought,
374+
thought,
374375
thoughtSignature
375376
)
376377
is ExecutableCodePart ->
377378
ExecutableCodePart.Internal(
378379
ExecutableCodePart.Internal.ExecutableCode(language, code),
379-
isThought,
380+
thought,
380381
thoughtSignature
381382
)
382383
is CodeExecutionResultPart ->
383384
CodeExecutionResultPart.Internal(
384385
CodeExecutionResultPart.Internal.CodeExecutionResult(outcome, output),
385-
isThought,
386+
thought,
386387
thoughtSignature
387388
)
388389
else ->

0 commit comments

Comments
 (0)