-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#75] Fix: set default value for
role
in public Content class and b…
…uilder (#76) # Summary - Specify default value for `role` as a `"user"` in a public API class Content. - Added tests for the verification of conversion functions (_from public class to internal class and vice versa_). Fixes: #75 --------- Co-authored-by: Rodrigo Lazo <[email protected]>
- Loading branch information
1 parent
9bd6231
commit 5bb04e4
Showing
2 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...rativeai/src/test/java/com/google/ai/client/generativeai/internal/util/ConversionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.ai.client.generativeai.internal.util | ||
|
||
import com.google.ai.client.generativeai.internal.api.shared.Content | ||
import com.google.ai.client.generativeai.internal.api.shared.TextPart | ||
import com.google.ai.client.generativeai.type.content | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.Test | ||
|
||
class ConversionsTest { | ||
|
||
@Test | ||
fun `test content conversion toInternal (role not mentioned)`() { | ||
val content = content { text("test") }.toInternal() | ||
content.run { | ||
// default role should be a "user" | ||
role shouldBe "user" | ||
|
||
// only one part should be present | ||
parts.size shouldBe 1 | ||
parts[0].run { (this as TextPart).text shouldBe "test" } | ||
} | ||
} | ||
|
||
@Test | ||
fun `test content conversion toInternal (role mentioned)`() { | ||
val content = content(role = "model") { text("test") }.toInternal() | ||
content.run { | ||
// Role should be a "model" | ||
role shouldBe "model" | ||
|
||
// only one part should be present | ||
parts.size shouldBe 1 | ||
parts[0].run { (this as TextPart).text shouldBe "test" } | ||
} | ||
} | ||
|
||
@Test | ||
fun `test content conversion toPublic (role not mentioned)`() { | ||
val content = Content(parts = listOf(TextPart("test"))).toPublic() | ||
content.role shouldBe "user" | ||
} | ||
|
||
@Test | ||
fun `test content conversion toPublic (role mentioned)`() { | ||
val content = Content(role = "model", parts = listOf(TextPart("test"))).toPublic() | ||
content.role shouldBe "model" | ||
} | ||
} |