Skip to content
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
6 changes: 5 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# create your own API KEY at https://aistudio.google.com/apikey
#REACT_APP_GEMINI_API_KEY=''
REACT_APP_GEMINI_API_KEY=your_api_key_here
# Vertex AI (for WIP (Workload Identity Federation))
REACT_APP_USE_VERTEX_AI=false # set to true to use Vertex AI
REACT_APP_GOOGLE_CLOUD_PROJECT=your-project-id
REACT_APP_GOOGLE_CLOUD_LOCATION=us-central1
34 changes: 29 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,37 @@ import cn from "classnames";
import { LiveClientOptions } from "./types";

const API_KEY = process.env.REACT_APP_GEMINI_API_KEY as string;
if (typeof API_KEY !== "string") {
throw new Error("set REACT_APP_GEMINI_API_KEY in .env");
const USE_VERTEX_AI = process.env.REACT_APP_USE_VERTEX_AI === 'true';
const PROJECT_ID = process.env.REACT_APP_GOOGLE_CLOUD_PROJECT as string;
const LOCATION = process.env.REACT_APP_GOOGLE_CLOUD_LOCATION as string;


function createApiOptions(): LiveClientOptions {
if (USE_VERTEX_AI) {
// Vertex AI configuration (supports WIF)
if (!PROJECT_ID || !LOCATION) {
throw new Error(
"When using Vertex AI, set REACT_APP_GOOGLE_CLOUD_PROJECT and REACT_APP_GOOGLE_CLOUD_LOCATION in .env"
);
}

return {
vertexai: true,
project: PROJECT_ID,
location: LOCATION,
};
} else {
if (!API_KEY) {
throw new Error("set REACT_APP_GEMINI_API_KEY in .env");
}

return {
apiKey: API_KEY,
};
}
}

const apiOptions: LiveClientOptions = {
apiKey: API_KEY,
};
const apiOptions: LiveClientOptions = createApiOptions();

function App() {
// this video reference is used for displaying the active stream, whether that is the webcam or screen capture
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import {
} from "@google/genai";

/**
* the options to initiate the client, ensure apiKey is required
* The options to initiate the client, supporting either API key or Vertex AI.
*/
export type LiveClientOptions = GoogleGenAIOptions & { apiKey: string };
export type LiveClientOptions = GoogleGenAIOptions;

/** log types */
export type StreamingLog = {
Expand Down