Skip to content

Commit a7514c4

Browse files
committed
AI - Ask a question closes #21.
Income metrics updates. Added Dow Jones Industrial Average to Performance chart.
1 parent 7034551 commit a7514c4

19 files changed

+1388
-210
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ Functions will automatically deploy with hosting deployments with `firebase depl
208208
firebase deploy --only functions
209209
```
210210
211+
The following secrets should be configured to prevent storing sensitive passwords and tokens in source control.
212+
213+
```bash
214+
# Change the value of an existing secret
215+
firebase functions:secrets:set GEMINI_API_KEY
216+
# View the value of a secret
217+
firebase functions:secrets:access GEMINI_API_KEY
218+
```
211219
212220
### Android Play Store
213221

src/robinhood_options_mobile/functions/package-lock.json

Lines changed: 27 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/robinhood_options_mobile/functions/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"logs": "firebase functions:log"
1212
},
1313
"engines": {
14-
"node": "18"
14+
"node": "22"
1515
},
1616
"main": "lib/index.js",
1717
"dependencies": {
18+
"@google-cloud/vertexai": "^1.9.3",
19+
"@google/generative-ai": "^0.24.0",
1820
"firebase-admin": "^12.6.0",
1921
"firebase-functions": "^6.1.1",
2022
"plaid": "^29.0.0"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// import * as functions from 'firebase-functions';
2+
import * as https from "firebase-functions/v2/https";
3+
import * as logger from "firebase-functions/logger";
4+
import {
5+
// DynamicRetrievalMode,
6+
GoogleGenerativeAI,
7+
} from "@google/generative-ai";
8+
import { VertexAI, type Tool } from "@google-cloud/vertexai";
9+
10+
export const generateContent = https.onCall({ secrets: ["GEMINI_API_KEY"] },
11+
async (request) => {
12+
logger.info(request.data, { structuredData: true });
13+
if (process.env.GEMINI_API_KEY == null) {
14+
throw new https.HttpsError(
15+
"unavailable", "GEMINI_API_KEY not found.");
16+
}
17+
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
18+
const model = genAI.getGenerativeModel(
19+
{
20+
model: "models/gemini-1.5-flash",
21+
tools: [
22+
{
23+
googleSearchRetrieval: {
24+
// dynamicRetrievalConfig: {
25+
// mode: DynamicRetrievalMode.MODE_DYNAMIC,
26+
// dynamicThreshold: 0.7,
27+
// },
28+
},
29+
},
30+
],
31+
},
32+
{ apiVersion: "v1beta" },
33+
);
34+
35+
// const prompt = "Who won Wimbledon this year?";
36+
const result = await model.generateContent(request.data.prompt);
37+
console.log(result);
38+
return result;
39+
});
40+
41+
export const generateContent2 = https.onCall({ secrets: ["GEMINI_API_KEY"] },
42+
async (request) => {
43+
logger.info(request.data, { structuredData: true });
44+
if (process.env.GEMINI_API_KEY == null) {
45+
throw new https.HttpsError(
46+
"unavailable", "GEMINI_API_KEY not found.");
47+
}
48+
const vertexAI = new VertexAI({
49+
project: "realizealpha", // process.env.GOOGLE_PROJECT_ID,
50+
location: "us-central1", // process.env.GOOGLE_VERTEXAI_LOCATION,
51+
});
52+
53+
const googleSearchTool = {
54+
googleSearch: {},
55+
} as Tool;
56+
57+
const model = vertexAI.getGenerativeModel({
58+
model: "gemini-2.0-flash-001",
59+
tools: [googleSearchTool],
60+
});
61+
62+
const { response } = await model.generateContent({
63+
contents: [{ role: "user", parts: [{ text: request.data.prompt }] }],
64+
});
65+
return response;
66+
});

src/robinhood_options_mobile/functions/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ initializeApp();
1616
import * as plaidfunc from "./plaid";
1717
import * as authfunc from "./auth";
1818
import * as messagingfunc from "./messaging";
19+
import * as gemini from "./gemini";
1920

2021
// Start writing functions
2122
// https://firebase.google.com/docs/functions/typescript
@@ -34,3 +35,5 @@ export const getInvestmentsTransactions =
3435
plaidfunc.getInvestmentsTransactions;
3536
export const changeUserRole = authfunc.changeUserRole;
3637
export const sendEachForMulticast = messagingfunc.sendEachForMulticast;
38+
export const generateContent = gemini.generateContent;
39+
export const generateContent2 = gemini.generateContent2;

0 commit comments

Comments
 (0)