This is a simple chatbot using Genkit's non-persistent Chat
interface.
You can customize the system instructions, and responses are streamed. History is stored in-memory and passed to the server each time.
Talk like a pirate.
// api/route.ts
import { z } from "genkit";
// this example requires beta features
import { genkit } from "genkit/beta";
import { googleAI, gemini20Flash } from "@genkit-ai/googleai";
const ai = genkit({
plugins: [googleAI()], // set the GOOGLE_API_KEY env variable
model: gemini20Flash,
});
import genkitEndpoint from "@/lib/genkit-endpoint";
export const POST = genkitEndpoint(({ system, messages, prompt }) => {
const chat = ai.chat({ messages, system });
return chat.sendStream({ prompt });
});