Releases: EvanZhouDev/gemini-ai
v2.2.0
Customize your prompt in an all-new way with Safety Settings, System Instructions, and JSON Schemas!
Setting Safety Settings
Is Gemini saying something's unsafe while it isn't? This is the feature for you! Requested by @DisboardTetta
You can now set how "unsafe" a response has to get (in 4 dimensions/categories) before Gemini blocks it!
For example, here's how you disable all safety settings.
await gemini.ask("Hello!", {
safetySettings: {
hate: Gemini.SafetyThreshold.BLOCK_NONE,
sexual: Gemini.SafetyThreshold.BLOCK_NONE,
harassment: Gemini.SafetyThreshold.BLOCK_NONE,
dangerous: Gemini.SafetyThreshold.BLOCK_NONE,
},
});
You can also set safety settings on Chat.ask()
requests!
Learn more about Safety Settings here.
System Instructions
This one is for those who wanted Gemini to talk like Shakespeare consistently.
You can now set a system instruction for Gemini! This will give it insight as to how to speak, what format to output in, and more. Here's an example:
await gemini.ask("Hello!", {
systemInstruction: "Talk like Shakespeare"
});
You can also establish system instructions on createChat()
!
Learn more about System Instructions in the config for Gemini.ask()
.
Setting a JSON Schema
Ensure Gemini's replying the way you want to!
You can now allow Gemini to reply to you in a specific JSON schema! And with gemini-1.5-pro-latest
, you can use controlled generation/constrained decoding to strictly enforce that the content is completely the format that you want.
Here's an example!
await gemini.ask(
"List 5 popular cookie recipes.",
{
jsonSchema: {
type: Gemini.SchemaType.ARRAY,
items: {
type: Gemini.SchemaType.OBJECT,
properties: {
recipe_name: {
type: Gemini.SchemaType.STRING,
},
},
},
},
}
);
You can also set JSON schemas on Chat.ask()
requests!
Learn more about JSON Schemas here.
Other Things
Small but powerful... especially for developers!
- Streaming now mainly operates on
response.body.getReader().read()
, but with aAsyncIterator
fallback so that nearly allfetch
environments are supported. Learn more. (New in 2.1.1) - When streaming, Safety errors now show as they should, instead of a random Stream error.
- Error messages now are more detailed, and report where in the process that things went wrong
v2.1.0
Fixed two small issues that were bothering me!
Chat Message Format
This piece of code now works!
// "Continuing" a conversation:
import Gemini from "gemini-ai";
const gemini = new Gemini(API_KEY);
const chat = gemini.createChat();
console.log(await chat.ask("Hi!"));
// Creating a new chat, with existing messages
const newChat = gemini.createChat({
messages: chat.messages,
});
console.log(await newChat.ask("What's the last thing I said?"));
It's been since the release of the library that this wouldn't actually work. Essentially, Chat.messages
was in the format of actual Gemini Message
types, while createChat
only accepted [string, string][]
messages. Now, you can put in both [string, string][]
, or Message[]
.
Learn more about the new createChat()
types and continuing chats here.
Smarter File Uploads
Now, Gemini AI automatically does the following when deciding which files to upload via Google Files API:
- All videos are automatically uploaded via Files API (because Gemini wouldn't accept them otherwise)
- If all of your files combined are under 20MB (Google-set limit), all non-videos will be included as
inline_data
, which is the faster method - If all of your files combined are over 20MB, all files will be uploaded via File API
This truly ensures that all of your files get where they need to go, while emphasizing speed.
Learn more about media uploads here.
Other Things
- New stream-parsing method, that should support both
fetch
and thenode-fetch
polyfill. The original method only supports nativefetch
- Removed a TextDecoder polyfill originally used for Bun, due to new updates above
v2.0.0
Gemini AI v2 is a full rewrite, from the ground up, with a few new features and numerous changes to improve DX and efficiency.
Best of all, Gemini AI v2 is completely backward compatible. The only significant change in behavior is that configuration settings no longer error when giving a nonexistent field, to future-proof for API changes.
Here's a look at what v2 has to offer:
TypeScript
Thanks to @Mimikkk, @yoroshikun, and @kcoderhtml for the original TypeScript rewrite!
Gemini AI is now completely written in TypeScript, which means that types are built-in to the library. Check available configuration properties with your IDE's autocomplete, or even get completions for the raw API response when the format
is set to Gemini.JSON
.
Learn more about Typescript here.
File Upload Changes
You provide the file, Gemini AI optimizes uploading.
File uploads are now dynamically optimized. When the file is large (i.e. video/audio), it will automatically use Google's File API to upload it. When it's small, inline_data
is used to ensure maximum efficiency.
Learn more about uploading files here.
New Message Format
Let Gemini see images, hear audio, or watch videos... inline with your prompt.
You can now directly pass in an array of strings and buffers, and Gemini AI will receive them in order.
await gemini.ask([
"Between these two cookies, which one appears to be home-made, and which one looks store-bought? Cookie 1:",
fs.readFileSync("./cookie1.png"),
"Cookie 2",
fs.readFileSync("./cookie2.png"),
]);
Learn more about the new format here.
Other Things
- Ability to change the API version (Thank you to @yoroshikun for the original suggestion)
- Default model is now
gemini-1.5-flash-latest
- Various optimizations have been made for Gemini 1.5 models
- Streaming is now done through SSE, making it much more reliable
- Chat is now completely dependent on Gemini's ask() method, ensuring parity
- MIME types are now detected by the
file-type
library, making it much more accurate - Many more improvements have also been made under the hood!
Gemini AI v1.1
A powerful update for features missing in the original release!
Streaming
Get AI output as soon as it's available!
Making a streaming request is as simple as follows:
import Gemini from "gemini-ai";
const gemini = new Gemini(API_KEY);
gemini.ask("Hi!", {
stream: console.log,
});
It also works with Chat
!
Learn more about streaming here.
Proxy Support
Requested by @xhawk18
Install the undici
library on NPM, and add this to your Gemini config:
let gemini = new Gemini(API_KEY, {
// Other config here...
dispatcher: new ProxyAgent(PROXY_URL)
})
Learn more about proxies here
Other Things
Small but powerful... especially for developers!
Gemini AI v1
Welcome to the first stable release of Gemini AI!
This library seeks to make interacting with Google's newest Gemini models as easy as 3 lines of code. See the quickstart below!
Features
- 🌎 Multimodal: Interact with text, images, and more.
- 🌐 Contextual Conversations: Chat with Gemini, built in.
- 🧪 Parameter: Easily modify
temperature
,topP
, and more
Highlights
Gemini AI v1.0 compared to Google's own API
- ⚡ Native REST API: Have simplicity without compromises
- 🚀 Easy: Auto model selection based on context
- 🎯 Concise: 4x less code needed
Quickstart
Make a text request (gemini-pro
):
import Gemini from "gemini-ai";
const gemini = new Gemini(API_KEY);
console.log(await gemini.ask("Hi!"));
Chat with Gemini (gemini-pro
):
import fs from "fs";
const gemini = new Gemini(API_KEY);
const chat = gemini.createChat();
console.log(await chat.ask("Hi!"));
console.log(await chat.ask("What's the last thing I said?"));
Read the full docs at https://github.com/EvanZhouDev/gemini-ai.