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 aAsyncIteratorfallback so that nearly allfetchenvironments 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