diff --git a/docs/index.md b/docs/index.md index 2ac242d9a..2b6ca9d46 100644 --- a/docs/index.md +++ b/docs/index.md @@ -18,7 +18,7 @@ Genkit is a framework designed to help you build AI-powered applications and fea This documentation covers Genkit for Node.js. If you're a Go developer, see the [Genkit Go documentation](/docs/genkit-go/get-started-go). -You can deploy and run Genkit libraries anywhere Node.js is supported. It's designed to work with any generative AI model API or vector database. While we offer integrations for Firebase and Google Cloud, you can use Genkit independently of any Google services. +You can deploy and run Genkit libraries anywhere Node.js is supported. It's designed to work with many AI model providers and vector databases. While we offer integrations for Firebase and Google Cloud, you can use Genkit independently of any Google services. [Get started](/docs/genkit/get-started){: .button} @@ -65,11 +65,11 @@ See the following code samples for a concrete idea of how to use these capabilit ```javascript import { genkit } from 'genkit'; - import { googleAI, gemini15Flash } from '@genkit-ai/googleai'; + import { googleAI, gemini20Flash } from '@genkit-ai/googleai'; const ai = genkit({ plugins: [googleAI()], - model: gemini15Flash, // Set default model + model: gemini20Flash, // Set default model }); // Simple generation @@ -77,7 +77,7 @@ See the following code samples for a concrete idea of how to use these capabilit console.log(text); // Streamed generation - const { stream } = await ai.generateStream('Tell me a story'); + const { stream } = ai.generateStream('Tell me a story'); for await (const chunk of stream) { console.log(chunk.text); } @@ -87,11 +87,11 @@ See the following code samples for a concrete idea of how to use these capabilit ```javascript import { genkit, z } from 'genkit'; - import { googleAI, gemini15Flash } from '@genkit-ai/googleai'; + import { googleAI, gemini20Flash } from '@genkit-ai/googleai'; const ai = genkit({ plugins: [googleAI()], - model: gemini15Flash, + model: gemini20Flash, }); const { output } = await ai.generate({ @@ -110,15 +110,15 @@ See the following code samples for a concrete idea of how to use these capabilit console.log(output); ``` -- {Function calling} +- {Tool calling} ```javascript import { genkit, z } from 'genkit'; - import { googleAI, gemini15Flash } from '@genkit-ai/googleai'; + import { googleAI, gemini20Flash } from '@genkit-ai/googleai'; const ai = genkit({ plugins: [googleAI()], - model: gemini15Flash, + model: gemini20Flash, }); // Define tool to get current weather for a given location @@ -129,7 +129,9 @@ See the following code samples for a concrete idea of how to use these capabilit inputSchema: z.object({ location: z.string().describe('The location to get the current weather for') }), - outputSchema: z.string(), + outputSchema: z.object({ + weatherReport: z.string().describe('Weather report of a particular location') + }), }, async (input) => { // Here, we would typically make an API call or database query. For this @@ -149,12 +151,12 @@ See the following code samples for a concrete idea of how to use these capabilit - {Chat} ```javascript - import { genkit, z } from 'genkit'; - import { googleAI, gemini15Flash } from '@genkit-ai/googleai'; + import { genkit, z } from 'genkit/beta'; + import { googleAI, gemini20Flash } from '@genkit-ai/googleai'; const ai = genkit({ plugins: [googleAI()], - model: gemini15Flash, + model: gemini20Flash, }); const chat = ai.chat({ system: 'Talk like a pirate' }); @@ -169,52 +171,51 @@ See the following code samples for a concrete idea of how to use these capabilit - {Agents} ```javascript - import { genkit, z } from 'genkit'; - import { googleAI, gemini15Flash } from '@genkit-ai/googleai'; + import { genkit, z } from 'genkit/beta'; + import { googleAI, gemini20Flash } from '@genkit-ai/googleai'; const ai = genkit({ plugins: [googleAI()], - model: gemini15Flash, + model: gemini20Flash, }); - // Define prompts that represent specialist agents - const reservationAgent = ai.definePrompt( - { - name: 'reservationAgent', - description: 'Reservation Agent can help manage guest reservations', - tools: [reservationTool, reservationCancelationTool, reservationListTool], - - }, - `{% verbatim %}{{role "system"}}{% endverbatim %} Help guests make and manage reservations` - ); + // Define tools for your agents to use + const reservationTool = ai.defineTool( ... ); + const reservationCancelationTool = ai.defineTool( ... ); + const reservationListTool = ai.defineTool( ... ); - const menuInfoAgent = ... - const complaintAgent = ... + // Define prompts that represent specialist agents + const reservationAgent = ai.definePrompt({ + name: 'reservationAgent', + description: 'Reservation Agent can help manage guest reservations', + tools: [reservationTool, reservationCancelationTool, reservationListTool], + system: `Help guests make and manage reservations` + }); + const menuInfoAgent = ai.definePrompt( ... ); + const complaintAgent = ai.definePrompt( ... ); // Define a triage agent that routes to the proper specialist agent - const triageAgent = ai.definePrompt( - { - name: 'triageAgent', - description: 'Triage Agent', - tools: [reservationAgent, menuInfoAgent, complaintAgent], - }, - `{% verbatim %}{{role "system"}}{% endverbatim %} You are an AI customer service agent for Pavel's Cafe. - Greet the user and ask them how you can help. If appropriate, transfer to an - agent that can better handle the request. If you cannot help the customer with - the available tools, politely explain so.` - ); + const triageAgent = ai.definePrompt({ + name: 'triageAgent', + description: 'Triage Agent', + tools: [reservationAgent, menuInfoAgent, complaintAgent], + system: `You are an AI customer service agent for Pavel's Cafe. + Greet the user and ask them how you can help. If appropriate, transfer to an + agent that can better handle the request. If you cannot help the customer with + the available tools, politely explain so.` + }); - // Create a chat to enable multi-turn agent interactions + // Create a chat to enable conversational agent interactions const chat = ai.chat(triageAgent); - chat.send('I want a reservation at Pavel\'s Cafe for noon on Tuesday.' ); + chat.send('I want a reservation at Pavel\'s Cafe for noon on Tuesday.'); ``` - {Data retrieval} ```javascript import { genkit } from 'genkit'; - import { googleAI, gemini15Flash, textEmbedding004 } from '@genkit-ai/googleai'; + import { googleAI, gemini20Flash, textEmbedding004 } from '@genkit-ai/googleai'; import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore'; const ai = genkit({ @@ -227,7 +228,7 @@ See the following code samples for a concrete idea of how to use these capabilit }, ]), ], - model: gemini15Flash, + model: gemini20Flash, }); // Reference to a local vector database storing Genkit documentation diff --git a/docs/migrating-from-0.9.md b/docs/migrating-from-0.9.md index 79c8841ef..36b37839d 100644 --- a/docs/migrating-from-0.9.md +++ b/docs/migrating-from-0.9.md @@ -250,10 +250,10 @@ export const simpleFlow = ai.defineFlow( }, async (input, { context }) => { if (!context.auth) { - throw new Error('Authorization required.'); + throw new UserFacingError("UNAUTHORIZED", "Authorization required."); } if (input.uid !== context.auth.uid) { - throw new Error('You may only summarize your own profile data.'); + throw new UserFacingError("UNAUTHORIZED", "You may only summarize your own profile data."); } // Flow logic here... } diff --git a/docs/nextjs.md b/docs/nextjs.md index e9b1d4bfd..454f4e28b 100644 --- a/docs/nextjs.md +++ b/docs/nextjs.md @@ -64,12 +64,12 @@ For example: ```ts 'use server'; -import { gemini15Flash, googleAI } from "@genkit-ai/googleai"; +import { gemini20Flash, googleAI } from "@genkit-ai/googleai"; import { genkit, z } from "genkit"; const ai = genkit({ plugins: [googleAI()], - model: gemini15Flash, + model: gemini20Flash, }); export const menuSuggestionFlow = ai.defineFlow( @@ -79,10 +79,7 @@ export const menuSuggestionFlow = ai.defineFlow( outputSchema: z.string(), }, async (restaurantTheme) => { - const { text } = await ai.generate({ - model: gemini15Flash, - prompt: `Invent a menu item for a ${restaurantTheme} themed restaurant.`, - }); + const { text } = await ai.generate('Invent a menu item for a ${restaurantTheme} themed restaurant.'); return text; } );