genkitx-azure-openai
    Preparing search index...

    Function onCallGenkit

    Implementation of onCallGenkit

    • Creates an Azure Functions handler for a Genkit flow.

      This function wraps a Genkit flow to create an Azure Functions HTTP handler that:

      • Handles CORS automatically
      • Supports ContextProvider for authentication/authorization
      • Provides proper error handling
      • Returns standardized response format
      • Supports streaming responses via ReadableStream

      Type Parameters

      • F extends Flow<ZodTypeAny, ZodTypeAny, ZodTypeAny>

      Parameters

      • flow: F

        The Genkit flow to wrap

      Returns CallableAzureFunction<F>

      A CallableAzureFunction with handler, flow, run, stream, and flowName

      import { genkit, z } from 'genkit';
      import { onCallGenkit, azureOpenAI, gpt4o } from 'genkitx-azure-openai';

      const ai = genkit({
      plugins: [azureOpenAI()],
      model: gpt4o,
      });

      const myFlow = ai.defineFlow(
      { name: 'myFlow', inputSchema: z.string(), outputSchema: z.string() },
      async (input) => {
      const { text } = await ai.generate({ prompt: input });
      return text;
      }
      );

      // Automatically registered as POST /api/myFlow (uses flow name)
      export const myFlowFn = onCallGenkit(myFlow);
      import { UserFacingError } from 'genkit';
      import type { ContextProvider } from 'genkit/context';

      interface AuthContext {
      auth: { user: { id: string; name: string } };
      }

      const authProvider: ContextProvider<AuthContext> = async (req) => {
      const token = req.headers['authorization'];
      if (!token) {
      throw new UserFacingError('UNAUTHENTICATED', 'Missing auth token');
      }
      const user = await verifyToken(token);
      return { auth: { user } };
      };

      // Registered as POST /api/myFlow (uses flow name)
      export const mySecureFlowFn = onCallGenkit(
      { contextProvider: authProvider },
      myFlow
      );
    • Creates an Azure Functions handler for a Genkit flow with options.

      Type Parameters

      • C extends ActionContext
      • F extends Flow<ZodTypeAny, ZodTypeAny, ZodTypeAny>

      Parameters

      • opts: AzureFunctionsOptions<C, FlowInput<F>> & { streaming: true }

        Configuration options for the Azure Functions handler

      • flow: F

        The Genkit flow to wrap

      Returns CallableAzureFunction<F>

      A CallableAzureFunction with handler, flow, run, stream, and flowName

    • Creates an Azure Functions handler for a Genkit flow.

      This function wraps a Genkit flow to create an Azure Functions HTTP handler that:

      • Handles CORS automatically
      • Supports ContextProvider for authentication/authorization
      • Provides proper error handling
      • Returns standardized response format
      • Supports streaming responses via ReadableStream

      Type Parameters

      • C extends ActionContext
      • F extends Flow<ZodTypeAny, ZodTypeAny, ZodTypeAny>

      Parameters

      Returns CallableAzureFunction<F>

      A CallableAzureFunction with handler, flow, run, stream, and flowName

      import { genkit, z } from 'genkit';
      import { onCallGenkit, azureOpenAI, gpt4o } from 'genkitx-azure-openai';

      const ai = genkit({
      plugins: [azureOpenAI()],
      model: gpt4o,
      });

      const myFlow = ai.defineFlow(
      { name: 'myFlow', inputSchema: z.string(), outputSchema: z.string() },
      async (input) => {
      const { text } = await ai.generate({ prompt: input });
      return text;
      }
      );

      // Automatically registered as POST /api/myFlow (uses flow name)
      export const myFlowFn = onCallGenkit(myFlow);
      import { UserFacingError } from 'genkit';
      import type { ContextProvider } from 'genkit/context';

      interface AuthContext {
      auth: { user: { id: string; name: string } };
      }

      const authProvider: ContextProvider<AuthContext> = async (req) => {
      const token = req.headers['authorization'];
      if (!token) {
      throw new UserFacingError('UNAUTHENTICATED', 'Missing auth token');
      }
      const user = await verifyToken(token);
      return { auth: { user } };
      };

      // Registered as POST /api/myFlow (uses flow name)
      export const mySecureFlowFn = onCallGenkit(
      { contextProvider: authProvider },
      myFlow
      );