Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit

Permalink
docs: update descriptions & examples to latest genkit version
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabolus committed May 14, 2024
1 parent b12ca73 commit f336ee0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
35 changes: 26 additions & 9 deletions plugins/anthropic/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Anthropic AI Plugin for Firebase Genkit

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

If you want to use Anthropic AI models through Google Vertex AI, please refer
to the [official Vertex AI plugin](https://www.npmjs.com/package/@genkit-ai/vertexai).

## Installation

```bash
Expand All @@ -23,27 +28,39 @@ yarn add @genkit-ai/core @genkit-ai/ai
## Example Claude 3 Haiku flow

```ts
import { generate } from '@genkit-ai/ai/generate';
import { flow } from '@genkit-ai/flow';
import { claude3Haiku } from './plugins/anthropic';
import { generate } from '@genkit-ai/ai';
import { configureGenkit } from '@genkit-ai/core';
import { defineFlow, startFlowsServer } from '@genkit-ai/flow';
import { anthropic, claude3Haiku } from 'genkitx-anthropic';
import * as z from 'zod';

export const anthropicStoryFlow = flow(
configureGenkit({
plugins: [
// Anthropic API key is required and defaults to the ANTHROPIC_API_KEY environment variable
anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }),
],
logLevel: 'debug',
enableTracingAndMetrics: true,
});

export const menuSuggestionFlow = defineFlow(
{
name: 'anthropicStoryFlow',
input: z.string(),
output: z.string(),
streamType: z.string(),
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: claude3Haiku,
prompt: `Tell me a story about a ${subject}`,
streamingCallback: ({ content }) => {
streamingCallback?.(content[0]?.text ?? '');
},
});

return llmResponse.text();
},
);

startFlowsServer();
```
32 changes: 23 additions & 9 deletions plugins/openai/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# OpenAI Plugin for Firebase Genkit

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

## Installation

```bash
Expand All @@ -23,27 +25,39 @@ yarn add @genkit-ai/core @genkit-ai/ai
## Example GPT-4 Turbo flow

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

export const openaiStoryFlow = flow(
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: 'openaiStoryFlow',
input: z.string(),
output: z.string(),
streamType: z.string(),
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: gpt4Turbo,
prompt: `Tell me a story about a ${subject}`,
streamingCallback: ({ content }) => {
streamingCallback?.(content[0]?.text ?? '');
},
});

return llmResponse.text();
},
);

startFlowsServer();
```

0 comments on commit f336ee0

Please sign in to comment.