diff --git a/examples/gemini/streaming.ts b/examples/gemini/streaming.ts new file mode 100644 index 0000000000000000000000000000000000000000..6a6be26366b6dee056053f4804e6e3f49d049c5f --- /dev/null +++ b/examples/gemini/streaming.ts @@ -0,0 +1,25 @@ +import { gemini, GEMINI_MODEL } from "@llamaindex/google"; + +(async () => { + if (!process.env.GOOGLE_API_KEY) { + throw new Error("Please set the GOOGLE_API_KEY environment variable."); + } + const llm = gemini({ + model: GEMINI_MODEL.GEMINI_PRO_LATEST, + }); + const stream = await llm.chat({ + messages: [ + { content: "You want to talk in rhymes.", role: "system" }, + { + content: + "How much wood would a woodchuck chuck if a woodchuck could chuck wood?", + role: "user", + }, + ], + stream: true, + }); + for await (const chunk of stream) { + process.stdout.write(chunk.delta); + } + console.log("\n\ndone"); +})();