This is a sample callable function that authenticates calling apps with App
Check and then sends queries to Gemini using the Vertex AI Gemini API. Vertex
AI model parameters are controlled using the Remote Config server
functionality provided by the Firebase Admin SDK for Node.js. Use the client
provided in client/ to access the function through basic web page.
- Read more about Remote Config for servers.
- Read more about App Check.
- Read more about the Vertex AI Node.js Client library.
Important: Vertex AI and Cloud Functions require a billing account. Review Vertex AI pricing and Firebase pricing before running this function. If you're new to Firebase and Google Cloud, check to see if you're eligible for a $300 credit and a Free Trial Cloud Billing account.
- Follow the instructions in client/README.md to create a Firebase project, enable ReCAPTCHA Enterprise, enable Firebase App Check, and add your Firebase config and ReCAPTCHA Enterprise key to the client config.
- Enable recommended Vertex AI APIs.
- Configure a Remote Config server template on the Firebase console. Use the template described in Use server side Remote Config with Cloud Functions and Vertex AI, which contains all of the parameters used in the function sample.
- Install dependencies:
cd functions && npm install - If you haven't already done so, install firebase-tools:
npm i firebase-tools@latest - Log into Firebase:
firebase login - Deploy the function. We recommend testing in the Firebase emulator.
- If testing in the emulator, verify that
testModeis set totrueinclient/main.ts, then start the client:cd public && npm run dev - Open the client app in a browser and enter a
prompt. To access the Vertex AI Gemini API, make sure that you have
set the
is_vertex_enabledboolean parameter in your Remote Config server template totrue.
© Google, 2024. Licensed under an Apache-2 license.