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

Do not include the model name in the request #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ sealed interface Request

@Serializable
data class GenerateContentRequest(
val model: String,
val contents: List<Content>,
val model: String? = null,
@SerialName("safety_settings") val safetySettings: List<SafetySetting>? = null,
@SerialName("generation_config") val generationConfig: GenerationConfig? = null,
val tools: List<Tool>? = null,
) : Request

@Serializable
data class CountTokensRequest(val model: String, val contents: List<Content>) : Request
data class CountTokensRequest(val contents: List<Content>, val model: String? = null) : Request
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal fun prepareResponse(response: GenerateContentResponse) =
internal fun createRequest(vararg text: String): GenerateContentRequest {
val contents = text.map { Content(parts = listOf(TextPart(it))) }

return GenerateContentRequest("gemini", contents)
return GenerateContentRequest(contents, "gemini")
}

internal fun createResponse(text: String) = createResponses(text).single()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,13 @@ internal constructor(

private fun constructRequest(vararg prompt: Content) =
GenerateContentRequest(
modelName,
prompt.map { it.toInternal() },
safetySettings?.map { it.toInternal() },
generationConfig?.toInternal()
contents = prompt.map { it.toInternal() },
safetySettings = safetySettings?.map { it.toInternal() },
generationConfig = generationConfig?.toInternal()
)

private fun constructCountTokensRequest(vararg prompt: Content) =
CountTokensRequest(modelName, prompt.map { it.toInternal() })
CountTokensRequest(prompt.map { it.toInternal() })

private fun GenerateContentResponse.validate() = apply {
if (candidates.isEmpty() && promptFeedback == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ internal class GenerativeModelTests {
coEvery {
mockApiController.generateContent(
GenerateContentRequest_Common(
"gemini-pro-1.0",
contents = listOf(Content_Common(parts = listOf(TextPart_Common("Why's the sky blue?"))))
)
)
Expand Down Expand Up @@ -102,7 +101,6 @@ internal class GenerativeModelTests {
coEvery {
mockApiController.generateContent(
GenerateContentRequest_Common(
"gemini-pro-1.0",
contents = listOf(Content_Common(parts = listOf(TextPart_Common("Why's the sky blue?"))))
)
)
Expand All @@ -117,7 +115,6 @@ internal class GenerativeModelTests {
coEvery {
mockApiController.generateContentStream(
GenerateContentRequest_Common(
"gemini-pro-1.0",
contents = listOf(Content_Common(parts = listOf(TextPart_Common("Why's the sky blue?"))))
)
)
Expand Down
Loading