Skip to content

Create the function declaration schema at construction time #6302

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

Merged
merged 3 commits into from
Sep 24, 2024
Merged
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 @@ -153,16 +153,7 @@ internal fun Tool.toInternal() =
com.google.firebase.vertexai.common.client.Tool(functionDeclarations.map { it.toInternal() })

internal fun FunctionDeclaration.toInternal() =
com.google.firebase.vertexai.common.client.FunctionDeclaration(
name,
description,
Schema(
properties = parameters.mapValues { it.value.toInternal() },
required = parameters.keys.minus(optionalParameters.toSet()).toList(),
type = "OBJECT",
nullable = false,
),
)
com.google.firebase.vertexai.common.client.FunctionDeclaration(name, "", schema.toInternal())

internal fun com.google.firebase.vertexai.type.Schema.toInternal(): Schema =
Schema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ class FunctionDeclaration(
val description: String,
val parameters: Map<String, Schema>,
val optionalParameters: List<String> = emptyList(),
)
) {
internal val schema: Schema =
Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,20 @@ internal constructor(
optionalProperties: List<String> = emptyList(),
description: String? = null,
nullable: Boolean = false,
) =
Schema(
): Schema {
if (!properties.keys.containsAll(optionalProperties)) {
throw IllegalArgumentException(
"All optional properties must be present in properties. Missing: ${optionalProperties.minus(properties.keys)}"
)
}
return Schema(
description = description,
nullable = nullable,
properties = properties,
required = properties.keys.minus(optionalProperties.toSet()).toList(),
type = "OBJECT",
)
}

/**
* Returns a schema for an array.
Expand Down
Loading