Skip to content
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

feat: add call gemini for v2 #1134

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: add call gemini for v2 #1134

wants to merge 5 commits into from

Conversation

HYACCCINT
Copy link

No description provided.

@HYACCCINT HYACCCINT requested a review from jhuleatt April 26, 2024 20:25
Node/call-gemini/functions/index.js Show resolved Hide resolved
Comment on lines 26 to 27
exports.callGemini = onCall({secrets: [geminiToken]}, async (request) => {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before calling Gemini, let's look for both appcheck and auth, but gate each with its own boolean parameter (https://firebase.google.com/docs/functions/config-env?gen=2nd#parameter_types) so devs can choose whether they want auth/app check or not.

Something like:

// ...imports

const appCheckRequired = defineBoolean("APP_CHECK_REQUIRED");
const authRequired = defineBoolean("AUTH_REQUIRED");

// ...other setup

exports.callGemini = onCall(
  {
    enforceAppCheck: appCheckRequired, // Reject requests with missing or invalid App Check tokens.
  },
  (request) => {
    if (authRequired.val() && !request.auth) {
      throw new HttpsError(
        "failed-precondition",
        "The function must be called while authenticated.",
      );
    }

    // ...call Gemini
  },
);

package.json Show resolved Hide resolved
@@ -15,3 +15,4 @@
packages:
- 'Node/**'
- 'Node-1st-gen/**'
- "!Node-1st-gen/image-maker/**"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove before merging

"@google/generative-ai": "^0.5.0",
"firebase-admin": "^11.9.0",
"firebase-functions": "^4.4.1",
"node-fetch": "^2.6.7"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is node-fetch needed for this sample?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants