Skip to content

Commit

Permalink
Make "user" the default role. (#67)
Browse files Browse the repository at this point in the history
Instead of leaving it empty, we should default to "user".

---------

Co-authored-by: Daymon <[email protected]>
  • Loading branch information
rlazo and daymxn authored Feb 22, 2024
1 parent 3cb4420 commit 5df6d44
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .changes/branch-badge-dock-advertisement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"MAJOR","changes":["Make \"user\" the default role in all requests"]}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
* @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)
}

Expand All @@ -84,7 +84,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
* @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)
}

Expand Down Expand Up @@ -150,7 +150,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
* @throws InvalidStateException if the [Chat] instance has an active request.
*/
fun sendMessageStream(prompt: String): Flow<GenerateContentResponse> {
val content = content("user") { text(prompt) }
val content = content { text(prompt) }
return sendMessageStream(content)
}

Expand All @@ -162,7 +162,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList<Content>
* @throws InvalidStateException if the [Chat] instance has an active request.
*/
fun sendMessageStream(prompt: Bitmap): Flow<GenerateContentResponse> {
val content = content("user") { image(prompt) }
val content = content { image(prompt) }
return sendMessageStream(content)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal enum class HarmCategory {

typealias Base64 = String

@Serializable internal data class Content(val role: String? = null, val parts: List<Part>)
@Serializable internal data class Content(val role: String? = "user", val parts: List<Part>)

@Serializable(PartSerializer::class) internal sealed interface Part

Expand Down

0 comments on commit 5df6d44

Please sign in to comment.