Repository navigation
Function calling support for on device sdk. - #8758
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for function calling in on-device content generation requests and responses across the 'firebase-ai-ondevice-interop', 'firebase-ai-ondevice', and 'firebase-ai' modules. It adds new classes such as 'FunctionCallPart', 'FunctionDeclaration', 'FunctionResponsePart', and 'FunctionSchema', along with corresponding converters and comprehensive unit tests. Feedback on the changes suggests ensuring that the 'nullable' property is correctly propagated during schema conversions in 'Schema.toInterop()' and 'JsonSchema<*>.toInterop()' to respect nullability constraints.
…nerativemodel/OnDeviceGenerativeModelProvider.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…nerativemodel/OnDeviceGenerativeModelProvider.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
7669591 to
2aad1ca
Compare
Tested at firebase/quickstart-android#2855
Description
Adds support for function calling when generating content using on-device and hybrid (
PREFER_ON_DEVICE) inference modes, following the ML Kit GenAI Prompt APIs.When function calling tools are supplied,
OnDeviceGenerativeModelProviderverifies that the underlying on-device model supports function calling viaisFunctionCallingAvailable(). If function calling is not supported by the on-device model or if unsupported non-function tools (such as Google Search or Code Execution) are configured, aFirebaseAIOnDeviceNotAvailableExceptionis raised, triggering automatic fallback to cloud inference inPREFER_ON_DEVICEmode.Summary of Changes
gradle/libs.versions.toml:genaiPromptto1.0.0-beta5andgenaiSchemato1.0.0-alpha2.ai-logic/firebase-ai-ondevice-interop:FunctionDeclarationandFunctionSchemainterop data structures.FunctionCallPartandFunctionResponseParttoPart.kt.functionCalls: List<FunctionCallPart>toCandidate.tools: List<FunctionDeclaration>?toGenerateContentRequest.suspend fun isFunctionCallingAvailable(): BooleantoGenerativeModel.api.txtandCHANGELOG.md.ai-logic/firebase-ai-ondevice:GenerativeModelImpl.isFunctionCallingAvailable()delegating to ML Kit'sgetAvailableFeatures().contains(Feature.FUNCTION_CALLING).Converters.ktforFunctionCallPart,FunctionResponsePart,FunctionDeclaration, andFunctionSchemato/from ML Kit equivalents.GenerateContentResponse.toInterop().api.txtandCHANGELOG.md.GenerativeModelImplTestandConvertersTest.ai-logic/firebase-ai:tools: List<Tool>? = nulltoOnDeviceConfigto allow configuring tools for on-device inference, defaulting to model-level tools when omitted.GenerativeModeltoOnDeviceGenerativeModelProvider.Candidate.fromInteropto convert interop function calls intoFunctionCallPartinstances.OnDeviceGenerativeModelProvider:onDeviceModel.isFunctionCallingAvailable()when function declarations are provided.FirebaseAIOnDeviceNotAvailableExceptionif non-function tools are passed to on-device inference or if function calling is unsupported.FunctionCallPartandFunctionResponsePartin conversation history.api.txtandCHANGELOG.md.OnDeviceGenerativeModelProviderTestscovering tool execution, candidate mapping, multi-turn history with function responses, streaming support, and cloud fallback behavior.Testing
./gradlew :ai-logic:firebase-ai-ondevice-interop:check./gradlew :ai-logic:firebase-ai-ondevice:check./gradlew :ai-logic:firebase-ai:check./gradlew spotlessCheck