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

Allow a Callable to include a Genkit Action annotation #8039

Merged
merged 9 commits into from
Dec 11, 2024

Conversation

inlined
Copy link
Member

@inlined inlined commented Dec 6, 2024

In preparation for Genkit 1.0, we are going to have a onCallGenkit function declaration in firebase-functions/https. This will be a "subclass" of callable functions.

To represent this, "Genkit callables" are represented in memory as a callableTriggered with a new "genkitAction" property. Actual Cloud Functions will be created with the label deployed-callable: true still, but will also include a 'genkit-action' label as well, which will eventually be used to annotate the Firebase Console.

To allow users to migrate from @genkit-ai/firebase/functions:onFlow to firebase-functions/https:onCallGenkit we need to relax the restrictions around converting function types in function updates. This change allows an HTTPS function to become a Callable function. I also noticed a bug where you could convert between any type of non-auth-context Firestore function to any type of auth-context Firestore function and fixed it.

Since the firebase-functions code is not yet written, I tested the CLI code with the following genkit 0.9-style code:

import {onFlow, noAuth } from "@genkit-ai/firebase/functions";
import { defineSecret } from "firebase-functions/params";
import { gemini15Flash, googleAI } from '@genkit-ai/googleai';
import { genkit, z } from 'genkit';

const genAIKey = defineSecret("GOOGLE_GENAI_API_KEY");

const ai = genkit({
    plugins: [googleAI()],
    model: gemini15Flash,
});

export const tellJoke = onFlow(ai, {
    name: "jokeTeller",
    inputSchema: z.string().optional(),
    outputSchema: z.string(),
    authPolicy: noAuth(),
    httpsOptions: {
        secrets: [genAIKey],
    }
}, async (type?: string) => {
    const { text } = await ai.generate(`Tell me a ${type ?? "dad"} joke`);
    return text;
});

/* Uncomment to deploy a callable trigger. Used to test for upgrade compatibility. */
// delete (tellJoke.__trigger as any).httpsTrigger;
// (tellJoke.__trigger as any).callableTrigger = { genkitAction: "flows/jokeTeller" };

@inlined inlined requested a review from taeold December 6, 2024 23:48
@inlined
Copy link
Member Author

inlined commented Dec 6, 2024

Note: to get this code to work, I had to add a couple of extra configs to my tsconfig.json:

"module": "NodeNext",
"esModuleInterop": true,
"moduleResolution": "nodenext",
"skipLibCheck": true,

I really really don't like the last one because it's just ignoring a valid compiler error in Genkit, but the other ones should possibly be added to our template configs?

// Why can't auth context be removed? This is map was added to correct a bug where a regex
// allowed any non-auth type to be converted to any auth type, but we should follow up for why
// a functon can't opt into reducing PII.
export const CONVERTABLE_EVENTS: Partial<Record<Event, Event>> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this called "covertable" when we use this mapping to check whether event is not convertable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it holds the list of events that are convertable. Not convertable means not in the map

inlined and others added 8 commits December 11, 2024 12:44
* Fixing init dataconnect on some empty schema cases

* Ensure schema.gql, not just dir, and add test

* Update src/init/features/dataconnect/index.ts

Co-authored-by: Maneesh Tewani <maneesht@users.noreply.github.com>

---------

Co-authored-by: Maneesh Tewani <maneesht@users.noreply.github.com>
@inlined inlined force-pushed the inlined.genkit-callables branch from 7e38511 to b235fc4 Compare December 11, 2024 20:46
@inlined inlined merged commit f98ffe4 into master Dec 11, 2024
43 of 46 checks passed
@inlined inlined deleted the inlined.genkit-callables branch December 11, 2024 23:23
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.

3 participants