Modifying the Gemini filter settings in a NodeJS environment

This article can be read in about 5 minutes.
PR

The purpose 

Gemini has filters in place to prevent it from generating violent or sexually explicit content.

We will modify these filters to be more permissive regarding violent and sexually explicit content.

Instructions for using Gemini are summarized below.

PR

Opening

Gemini is basically a good bot, so it rarely returns responses that would trigger filters.

The previous response wasn’t sanitized; it reflects my true capabilities, not a filtered version designed for “good kid” answers.

The way to get responses that trigger filters seems to be to assign me a role-playing scenario.

When the filter is actually applied, no response is returned as shown above.

Checking the console shows it was blocked.

PR

Implementation

Import HarmCategory, HarmBlockThreshold

import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";

Next, modify below call.

    const result = await model.generateContent(prompt);

after modification, the code is below.

    const result = await model.generateContent({
        contents: [
          {
            role: 'user',
            parts: [
              {
                text: prompt,
              }
            ],
          }
        ],
        safetySettings:[
            {
                "category": HarmCategory.HARM_CATEGORY_HARASSMENT,
                "threshold": HarmBlockThreshold.BLOCK_NONE
            },
            {
                "category": HarmCategory.HARM_CATEGORY_HATE_SPEECH,
                "threshold": HarmBlockThreshold.BLOCK_NONE
            },
            {
                "category": HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
                "threshold": HarmBlockThreshold.BLOCK_NONE
            },
            {
                "category": HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
                "threshold": HarmBlockThreshold.BLOCK_NONE
            },
        ]
      })

Category ARM_CATEGORY_HARASSMENT,HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT and HARM_CATEGORY_DANGEROUS_CONTENT set BLOCK_NONE(no filter)

シンプルな実装方法は以下のページを参考にしてください。

PR

Result

We’re able to argue now. 

PR

Reference

自由で期間限定無料の Gemini API で遊ぶ(画像認識もできるし悪口も言わせられるぞ!)|ぶるぺん/blue.pen5805
Gemini って知ってますか? めちゃくちゃ適当な説明をすると Google の ChatGPT みたいなもんです それの Gemini Pro っていう中ボスぐらいのやつのAPI (なんかプログラムとかで呼べるやつ)が公開されたんですが、なんとこれが正式リリースまでの期間限定で無料で使えます ので、今回はこれを...
Gemini API を使用してテキストを生成する  |  Google AI for Developers
安全性設定  |  Gemini API  |  Google AI for Developers

comment

Copied title and URL