Skip to content

Bits for migrating to vertex #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ resource "google_project_service" "services" {

# generativelanguage.googleapis.com is designed for experimentation only. A low initial quota
# is set to protect the project. To use Gemini AI in a production environment, migrate to Vertex AI in
# Firebase. See prod.tf for more details.
# Firebase. See prod.tf.example for more details.
resource "google_service_usage_consumer_quota_override" "generativelanguage" {
project = var.project
service = "generativelanguage.googleapis.com"
Expand Down Expand Up @@ -149,7 +149,7 @@ resource "local_file" "environment_ts" {
{
project_id = data.google_project.project.project_id,
gemini_api_key = google_apikeys_key.generativelanguage.key_string,
debug_token = "" # Use local.uuid4 in when using Vertex AI in Firebase
debug_token = "" # TODO: Use local.uuid4 in when using Vertex AI in Firebase
}
))
filename = "${path.module}/src/environments/environments.ts"
Expand Down
12 changes: 7 additions & 5 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { initializeApp, provideFirebaseApp, getApp } from '@angular/fire/app';
import {
ReCaptchaEnterpriseProvider,
initializeAppCheck,
provideAppCheck,
} from '@angular/fire/app-check';
// TODO: Recommended to use together with Vertex AI
// import {
// ReCaptchaEnterpriseProvider,
// initializeAppCheck,
// provideAppCheck,
// } from '@angular/fire/app-check';
import { getAuth, provideAuth } from '@angular/fire/auth';
import { initializeFirestore, persistentLocalCache, persistentMultipleTabManager, provideFirestore } from '@angular/fire/firestore';
import { environment } from '../environments/environments';
Expand All @@ -36,6 +37,7 @@ export const appConfig: ApplicationConfig = {
provideFirebaseApp(() =>
initializeApp(environment.firebase),
),
// TODO
// Turn on app check for Vertex AI in Firebase
// provideAppCheck(() => {
// TODO: don't use debug token in prod
Expand Down
8 changes: 5 additions & 3 deletions src/app/services/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ import { GoogleGenerativeAIFetchError } from '@google/generative-ai';
import { v4 as uuidv4 } from 'uuid';
import { GoogleGenerativeAI } from '@google/generative-ai';
import { environment } from '../../environments/environments';
import { getVertexAI, getGenerativeModel } from 'firebase/vertexai-preview';
// TODO: import Vertex AI
// import { getVertexAI, getGenerativeModel } from 'firebase/vertexai-preview';

type Priority = 'none' | 'low' | 'medium' | 'high';

Expand Down Expand Up @@ -87,10 +88,11 @@ export class TaskService {
private firestore = inject(Firestore);
private auth = inject(Auth);

private vertexAI = getVertexAI(getApp());
// TODO: Use Vertex AI
// private vertexAI = getVertexAI(getApp());
// Caveat: the VertexAI model may take a while (~10s) to initialize after your
// first call to GenerateContent(). You may see a PERMISSION_DENIED error before then.
private prodModel = getGenerativeModel(this.vertexAI, MODEL_CONFIG);
// private prodModel = getGenerativeModel(this.vertexAI, MODEL_CONFIG);

private genAI = new GoogleGenerativeAI(environment.gemini_api_key);
private experimentModel = this.genAI.getGenerativeModel(MODEL_CONFIG);
Expand Down