-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #798 from firebase/ch-vertexai-preview
Add vertex preview
- Loading branch information
Showing
9 changed files
with
1,307 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
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,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. |
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,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"; |
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,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> |
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,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(); |
Oops, something went wrong.