-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for constrain decoding (#5837)
Based on the changes made in google-gemini/generative-ai-android#103
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 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
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
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
42 changes: 42 additions & 0 deletions
42
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionCallingConfig.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,42 @@ | ||
/* | ||
* 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.firebase.vertexai.type | ||
|
||
/** | ||
* Contains configuration for function calling from the model. This can be used to force function | ||
* calling predictions or disable them. | ||
* | ||
* @param mode The function calling mode of the model | ||
*/ | ||
class FunctionCallingConfig(val mode: Mode) { | ||
enum class Mode { | ||
/** | ||
* The default behavior for function calling. The model calls functions to answer queries at its | ||
* discretion | ||
*/ | ||
AUTO, | ||
|
||
/** The model always predicts a provided function call to answer every query. */ | ||
ANY, | ||
|
||
/** | ||
* The model will never predict a function call to answer a query. This can also be achieved by | ||
* not passing any tools to the model. | ||
*/ | ||
NONE | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ToolConfig.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,33 @@ | ||
/* | ||
* 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.firebase.vertexai.type | ||
|
||
/** | ||
* Contains configuration for the function calling tools of the model. This can be used to change | ||
* when the model can predict function calls. | ||
* | ||
* @param functionCallingConfig The config for function calling | ||
*/ | ||
class ToolConfig(val functionCallingConfig: FunctionCallingConfig) { | ||
|
||
companion object { | ||
/** Shorthand to construct a ToolConfig that restricts the model from calling any functions */ | ||
fun never(): ToolConfig = ToolConfig(FunctionCallingConfig(FunctionCallingConfig.Mode.NONE)) | ||
/** Shorthand to construct a ToolConfig that restricts the model to always call some function */ | ||
fun always(): ToolConfig = ToolConfig(FunctionCallingConfig(FunctionCallingConfig.Mode.ANY)) | ||
} | ||
} |