Skip to content

Commit

Permalink
feat: add gemini streaming example
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusschiesser committed Apr 30, 2024
1 parent 0d50b22 commit 0ee50ef
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions examples/gemini/streaming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Gemini, GEMINI_MODEL } from "llamaindex";

(async () => {
if (!process.env.GOOGLE_API_KEY) {
throw new Error("Please set the GOOGLE_API_KEY environment variable.");
}
const gemini = new Gemini({
model: GEMINI_MODEL.GEMINI_PRO_LATEST,
});
const stream = await gemini.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");
})();

0 comments on commit 0ee50ef

Please sign in to comment.