-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d50b22
commit 0ee50ef
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
})(); |