🛡️Safety

The following code snippet shows how to set safety settings in your GenerateContent call. This sets the harassment (HARM_CATEGORY_HARASSMENT) and hate speech (HARM_CATEGORY_HATE_SPEECH) categories to BLOCK_LOW_AND_ABOVE which blocks any content that has a low or higher probability of being harassment or hate speech.

using Glitch9.AIDevKit.Google.GenerativeAI;

var model = new GenerativeModel(GeminiModel.Gemini15Flash);

var response = await model.GenerateContentAsync(
    "Do these look store-bought or homemade?", 
    safetySettings: new List<SafetySetting>
{
    { new SafetySetting(HarmCategory.HateSpeech, HarmBlockThreshold.BlockLowAndAbove) },
    { new SafetySetting(HarmCategory.Harassment, HarmBlockThreshold.BlockLowAndAbove) }
});

Last updated