You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

genkitx-openai

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

genkitx-openai

Genkit AI framework plugin for OpenAI APIs.

0.5.3
Source
npmnpm
Version published
Maintainers
1
Created
Source

Firebase Genkit + OpenAI

OpenAI Plugin for Firebase Genkit

This Genkit plugin allows to use OpenAI models through their official APIs.

Installation

npm install genkitx-openai
# or
pnpm add genkitx-openai
# or
yarn add genkitx-openai

The plugin depends on Genkit core packages, so make sure to have them installed as well:

npm install @genkit-ai/core @genkit-ai/ai
# or
pnpm add @genkit-ai/core @genkit-ai/ai
# or
yarn add @genkit-ai/core @genkit-ai/ai

Example GPT-4o flow

import { generate } from '@genkit-ai/ai';
import { configureGenkit } from '@genkit-ai/core';
import { defineFlow, startFlowsServer } from '@genkit-ai/flow';
import { openAI, gpt4o } from 'genkitx-openai';
import * as z from 'zod';

configureGenkit({
  plugins: [
    // OpenAI API key is required and defaults to the OPENAI_API_KEY environment variable
    openAI({ apiKey: process.env.OPENAI_API_KEY }),
  ],
  logLevel: 'debug',
  enableTracingAndMetrics: true,
});

export const menuSuggestionFlow = defineFlow(
  {
    name: 'menuSuggestionFlow',
    inputSchema: z.string(),
    outputSchema: z.string(),
  },
  async (subject, streamingCallback) => {
    const llmResponse = await generate({
      prompt: `Suggest an item for the menu of a ${subject} themed restaurant`,
      model: gpt4o,
      streamingCallback: ({ content }) => {
        streamingCallback?.(content[0]?.text ?? '');
      },
    });

    return llmResponse.text();
  },
);

startFlowsServer();

Keywords

genkit

FAQs

Package last updated on 15 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts