From f336ee0271041bd27b66e25c57d731a68901e67b Mon Sep 17 00:00:00 2001 From: Giorgio Garasto Date: Tue, 14 May 2024 09:31:38 +0200 Subject: [PATCH] docs: update descriptions & examples to latest genkit version --- plugins/anthropic/README.md | 35 ++++++++++++++++++++++++++--------- plugins/openai/README.md | 32 +++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/plugins/anthropic/README.md b/plugins/anthropic/README.md index 698fb98..63f817d 100644 --- a/plugins/anthropic/README.md +++ b/plugins/anthropic/README.md @@ -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 @@ -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(); ``` diff --git a/plugins/openai/README.md b/plugins/openai/README.md index 9136767..6186f55 100644 --- a/plugins/openai/README.md +++ b/plugins/openai/README.md @@ -1,5 +1,7 @@ # OpenAI Plugin for Firebase Genkit +This Genkit plugin allows to use OpenAI models through their official APIs. + ## Installation ```bash @@ -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(); ```