From 774d2333c1e16878e1118ebfaaa3a47aad1d2dd3 Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Thu, 22 Feb 2024 11:03:35 -0500 Subject: [PATCH 1/2] Make "user" the default role. Instead of leaving it empty, we should default to "user". --- .../main/java/com/google/ai/client/generativeai/Chat.kt | 8 ++++---- .../ai/client/generativeai/internal/api/shared/Types.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/Chat.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/Chat.kt index 2abe4b72..b536c244 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/Chat.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/Chat.kt @@ -73,7 +73,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @throws InvalidStateException if the [Chat] instance has an active request. */ suspend fun sendMessage(prompt: String): GenerateContentResponse { - val content = content("user") { text(prompt) } + val content = content { text(prompt) } return sendMessage(content) } @@ -84,7 +84,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @throws InvalidStateException if the [Chat] instance has an active request. */ suspend fun sendMessage(prompt: Bitmap): GenerateContentResponse { - val content = content("user") { image(prompt) } + val content = content { image(prompt) } return sendMessage(content) } @@ -150,7 +150,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @throws InvalidStateException if the [Chat] instance has an active request. */ fun sendMessageStream(prompt: String): Flow { - val content = content("user") { text(prompt) } + val content = content { text(prompt) } return sendMessageStream(content) } @@ -162,7 +162,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @throws InvalidStateException if the [Chat] instance has an active request. */ fun sendMessageStream(prompt: Bitmap): Flow { - val content = content("user") { image(prompt) } + val content = content { image(prompt) } return sendMessageStream(content) } diff --git a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/shared/Types.kt b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/shared/Types.kt index 3f15f807..8f7e2242 100644 --- a/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/shared/Types.kt +++ b/generativeai/src/main/java/com/google/ai/client/generativeai/internal/api/shared/Types.kt @@ -40,7 +40,7 @@ internal enum class HarmCategory { typealias Base64 = String -@Serializable internal data class Content(val role: String? = null, val parts: List) +@Serializable internal data class Content(val role: String? = "user", val parts: List) @Serializable(PartSerializer::class) internal sealed interface Part From d753c412829aaf7a80c98d51948b48bdff5c744a Mon Sep 17 00:00:00 2001 From: Rodrigo Lazo Paz Date: Thu, 22 Feb 2024 11:22:10 -0500 Subject: [PATCH 2/2] Add change entry --- .changes/branch-badge-dock-advertisement.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changes/branch-badge-dock-advertisement.json diff --git a/.changes/branch-badge-dock-advertisement.json b/.changes/branch-badge-dock-advertisement.json new file mode 100644 index 00000000..49e60811 --- /dev/null +++ b/.changes/branch-badge-dock-advertisement.json @@ -0,0 +1 @@ +{"type":"MAJOR","changes":["Make \"user\" the default role in all requests"]}