From 8be84aeb5e8d8b4fe51762fe34150d662227184a Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Fri, 14 Mar 2025 09:25:09 +0700
Subject: [PATCH] chore: add gemini streaming example (#782)

---
 examples/gemini/streaming.ts | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 examples/gemini/streaming.ts

diff --git a/examples/gemini/streaming.ts b/examples/gemini/streaming.ts
new file mode 100644
index 000000000..6a6be2636
--- /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");
+})();
-- 
GitLab