Skip to content

Commit

Permalink
Merge pull request #798 from firebase/ch-vertexai-preview
Browse files Browse the repository at this point in the history
Add vertex preview
  • Loading branch information
hsubox76 authored May 13, 2024
2 parents a583d24 + 3d3ced4 commit efc1aca
Show file tree
Hide file tree
Showing 9 changed files with 1,307 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vertexai/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
34 changes: 34 additions & 0 deletions vertexai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Firebase SDK for Vertex AI Quickstart
=========================================

Introduction
------------

This is a sample app for the preview version of the Firebase Vertex AI SDK.
This will not run if you don't have access to the preview.

<!-- Introduction
------------
[Read more about Firebase SDK for Vertex AI ](https://firebase.google.com/docs/vertexai/) -->

Getting Started
---------------

1. Create your project on the [Firebase Console](https://console.firebase.google.com).
2. Enable Gemini in the console.
3. Create a ReCAPTCHA Enterprise key in the same project.
4. Enable App Check in the Firebase console with the ReCAPTCHA Enterprise site key you created.
5. Copy your Firebase project config and your ReCAPTCHA Enterprise site key into the appropriate places in `config.ts` in this directory.
6. In this directory, run `npm install`
7. In this directory, run `npm run dev`

<!-- Support
-------
- [Firebase Support](https://firebase.google.com/support/) -->

License
-------

© Google, 2024. Licensed under an [Apache-2](../LICENSE) license.
17 changes: 17 additions & 0 deletions vertexai/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const firebaseConfig = {
// Your web app's Firebase configuration here
// See https://firebase.google.com/docs/web/setup#add-sdks-initialize
apiKey: 'API_KEY',
authDomain: 'PROJECT_ID.firebaseapp.com',
databaseURL: 'https://PROJECT_ID.firebaseio.com',
projectId: 'PROJECT_ID',
storageBucket: 'PROJECT_ID.appspot.com',
messagingSenderId: 'SENDER_ID',
appId: 'APP_ID',
measurementId: 'G-MEASUREMENT_ID',
};

// Your ReCAPTCHA Enterprise site key (must be from the same project
// as the Firebase config above).
export const RECAPTCHA_ENTERPRISE_SITE_KEY =
"YOUR_SITE_KEY";
27 changes: 27 additions & 0 deletions vertexai/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<!--
Copyright (c) 2024 Google Inc.
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.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vertex AI for Firebase SDK Quickstart</title>
</head>
<body>
<div>Open browser's developer console to view console.log output.</div>
<script type="module" src="main.ts"></script>
</body>
</html>
48 changes: 48 additions & 0 deletions vertexai/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license
* 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.
*/

import { initializeApp } from 'firebase/app';
import { firebaseConfig, RECAPTCHA_ENTERPRISE_SITE_KEY } from './config';
import {
initializeAppCheck,
ReCaptchaEnterpriseProvider,
} from "firebase/app-check";
import { getVertexAI, getGenerativeModel } from "firebase/vertexai-preview";

async function main() {
const app = initializeApp(firebaseConfig);

// Initialize App Check
// This line can be removed if you do not want to enable App Check for
// your project. App Check is recommended to limit unauthorized usage.
initializeAppCheck(app, {
provider: new ReCaptchaEnterpriseProvider(RECAPTCHA_ENTERPRISE_SITE_KEY),
});

// Get VertexAI instance
const vertexAI = getVertexAI(app);
// Get a Gemini model
const model = getGenerativeModel(
vertexAI,
{ model: "gemini-1.5-pro-preview-0409" }
);
// Call generateContent with a string or Content(s)
const generateContentResult = await model.generateContent("what is a cat?");
console.log(generateContentResult.response.text());
}

main();
Loading

0 comments on commit efc1aca

Please sign in to comment.