Skip to content

Commit 3c842c7

Browse files
Revamp Schema declaration (#6258)
b/365820023 --------- Co-authored-by: rachelsaunders <[email protected]>
1 parent d0fa299 commit 3c842c7

File tree

8 files changed

+448
-426
lines changed

8 files changed

+448
-426
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/internal/util/conversions.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,16 @@ internal fun FunctionDeclaration.toInternal() =
159159
name,
160160
description,
161161
Schema(
162-
properties = getParameters().associate { it.name to it.toInternal() },
163-
required = getParameters().map { it.name },
162+
properties = parameters.mapValues { it.value.toInternal() },
163+
required = parameters.keys.minus(optionalParameters.toSet()).toList(),
164164
type = "OBJECT",
165+
nullable = false,
165166
),
166167
)
167168

168-
internal fun <T> com.google.firebase.vertexai.type.Schema<T>.toInternal(): Schema =
169+
internal fun com.google.firebase.vertexai.type.Schema.toInternal(): Schema =
169170
Schema(
170-
type.name,
171+
type,
171172
description,
172173
format,
173174
nullable,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.vertexai.type
18+
19+
/**
20+
* A declared function that a model can be given access to in order to gain info or complete tasks.
21+
*
22+
* ```
23+
* val getExchangeRate = FunctionDeclaration(
24+
* name = "getExchangeRate",
25+
* description = "Get the exchange rate for currencies between countries.",
26+
* parameters = mapOf(
27+
* "currencyFrom" to Schema.str("The currency to convert from."),
28+
* "currencyTo" to Schema.str("The currency to convert to.")
29+
* )
30+
* )
31+
* ```
32+
*
33+
* @param name The name of the function call, this should be clear and descriptive for the model.
34+
* @param description A description of what the function does and its output.
35+
* @param parameters A list of parameters that the function accepts.
36+
* @param optionalParameters A list of parameters that can be omitted.
37+
* @see Schema
38+
*/
39+
class FunctionDeclaration(
40+
val name: String,
41+
val description: String,
42+
val parameters: Map<String, Schema>,
43+
val optionalParameters: List<String> = emptyList(),
44+
)

0 commit comments

Comments
 (0)