# genkitx-openai-plugin

> Firebase Genkit AI framework plugin for OpenAI APIs.

Latest version **0.4.0** (published 2024-05-21) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install genkitx-openai-plugin
pnpm add genkitx-openai-plugin
yarn add genkitx-openai-plugin
bun add genkitx-openai-plugin
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2024-05-21 |
| First published | 2024-05-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 171.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 182 |
| Author | TheFireCo |
| Maintainers | epmatt, davidoort, thefirecompany |
| Keywords | genkit, genkit-plugin, genkit-embedder, genkit-model, openai, gpt-4, gpt, gpt-3.5, ai, genai, generative-ai |

## Links

- npm: https://www.npmjs.com/package/genkitx-openai-plugin
- Repository: https://github.com/TheFireCo/genkit-plugins
- Homepage: https://github.com/TheFireCo/genkit-plugins#readme
- Issues: https://github.com/TheFireCo/genkit-plugins/issues
- npm.io page: https://npm.io/package/genkitx-openai-plugin

## Dependencies (2)

- [zod](https://npm.io/package/zod.md) ^3.22.4
- [openai](https://npm.io/package/openai.md) ^4.28.4

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2024-05-21
- 0.3.0 — 2024-05-20
- 0.2.0 — 2024-05-18
- 0.1.3 — 2024-05-17
- 0.1.2 — 2024-05-16
- 0.1.0 — 2024-05-14
- 0.0.11 — 2024-05-14
- 0.0.10 — 2024-05-11
- 0.0.8 — 2024-05-10
- 0.0.7 — 2024-05-10

## README

> **This package is deprecated. Please use [genkitx-openai](https://www.npmjs.com/package/genkitx-openai) instead.**

<h1 align="center">
   Firebase Genkit <> OpenAI Plugin
</h1>

<h4 align="center">OpenAI Community Plugin for Google Firebase Genkit</h4>

<div align="center">
   <img alt="Github lerna version" src="https://img.shields.io/github/lerna-json/v/TheFireCo/genkit-plugins?label=version">
   <img alt="NPM Downloads" src="https://img.shields.io/npm/dw/genkitx-openai-plugin">
   <img alt="GitHub Org's stars" src="https://img.shields.io/github/stars/TheFireCo?style=social">
   <img alt="GitHub License" src="https://img.shields.io/github/license/TheFireCo/genkit-plugins">
   <img alt="Static Badge" src="https://img.shields.io/badge/yes-a?label=maintained">
</div>

<div align="center">
   <img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues/TheFireCo/genkit-plugins?color=blue">
   <img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues-pr/TheFireCo/genkit-plugins?color=blue">
   <img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/TheFireCo/genkit-plugins">
</div>

</br>

**`genkitx-openai-plugin`** is a community plugin for using OpenAI APIs with
[Firebase GenKit](https://github.com/firebase/genkit). Built by [**The Fire Company**](https://github.com/TheFireCo). 🔥

## Installation

Install the plugin in your project with your favorite package manager:

- `npm install genkitx-openai-plugin`
- `yarn add genkitx-openai-plugin`
- `pnpm add genkitx-openai-plugin`

## Usage

### Basic examples

The simplest way to call the text generation model is by using the helper function `generate`:

```typescript
// Basic usage of an LLM
const response = await generate({
  model: gpt4o, // model imported from genkitx-openai-plugin
  prompt: 'Tell me a joke.',
});

console.log(await response.text());
```

### Multi-modal prompt

```typescript
const response = await generate({
  model: gpt4o,
  prompt: [
    { text: 'What animal is in the photo?' },
    { media: { url: imageUrl } },
  ],
  config: {
    // control of the level of visual detail when processing image embeddings
    // Low detail level also decreases the token usage
    visualDetailLevel: 'low',
  },
});
console.log(await response.text());
```

### Within a flow

```typescript
// ...configure Genkit (as shown above)...

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

    return llmResponse.text();
  }
);
startFlowsServer();
```

### Tool use

```typescript
// ...configure Genkit (as shown above)...

const createReminder = defineTool(
  {
    name: 'createReminder',
    description: 'Use this to create reminders for things in the future',
    inputSchema: z.object({
      time: z
        .string()
        .describe('ISO timestamp string, e.g. 2024-04-03T12:23:00Z'),
      reminder: z.string().describe('the content of the reminder'),
    }),
    outputSchema: z.number().describe('the ID of the created reminder'),
  },
  (reminder) => Promise.resolve(3)
);

const result = generate({
  model: gpt4o,
  tools: [createReminder],
  prompt: `
  You are a reminder assistant.
  If you create a reminder, describe in text the reminder you created as a response.

  Query: I have a meeting with Anna at 3 for dinner - can you set a reminder for the time?
  `,
});

console.log(result.then((res) => res.text()));
```

For more detailed examples and the explanation of other functionalities, refer to the examples in the [official Github repo of the plugin](https://github.com/TheFireCo/genkit-plugins/blob/main/examples/README.md) or in the [official Genkit documentation](https://firebase.google.com/docs/genkit/get-started).

## Contributing

Want to contribute to the project? That's awesome! Head over to our [Contribution Guidelines](https://github.com/TheFireCo/genkit-plugins/blob/main/CONTRIBUTING.md).

## Need support?

> [!NOTE]  
> This repository depends on Google's Firebase Genkit. For issues and questions related to GenKit, please refer to instructions available in [GenKit's repository](https://github.com/firebase/genkit).

Reach out by opening a discussion on [Github Discussions](https://github.com/TheFireCo/genkit-plugins/discussions).

## Credits

This plugin is proudly maintained by the team at [**The Fire Company**](https://github.com/TheFireCo). 🔥

## License

This project is licensed under the [Apache 2.0 License](https://github.com/TheFireCo/genkit-plugins/blob/main/LICENSE).

[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202%2E0-lightgrey.svg)](https://github.com/TheFireCo/genkit-plugins/blob/main/LICENSE)

---
_Source: https://npm.io/package/genkitx-openai-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
