google / generative-ai-go

Go SDK for Google Generative AI
Apache License 2.0
577 stars 56 forks source link

Can I only adjust 4 elements of safety settings for now? #35

Open KnightChaser opened 10 months ago

KnightChaser commented 10 months ago

According to the official documentation, the type HarmCategory says These categories cover various kinds of harms that developers may wish to adjust. and it enumerates 11 categories like below.

// HarmCategory specifies the category of a rating.
//
// These categories cover various kinds of harms that developers
// may wish to adjust.
type HarmCategory int32

const (
    // HarmCategoryUnspecified means category is unspecified.
    HarmCategoryUnspecified HarmCategory = 0
    // HarmCategoryDerogatory means negative or harmful comments targeting identity and/or protected attribute.
    HarmCategoryDerogatory HarmCategory = 1
    // HarmCategoryToxicity means content that is rude, disrepspectful, or profane.
    HarmCategoryToxicity HarmCategory = 2
    // HarmCategoryViolence means describes scenarios depictng violence against an individual or group, or
    // general descriptions of gore.
    HarmCategoryViolence HarmCategory = 3
    // HarmCategorySexual means contains references to sexual acts or other lewd content.
    HarmCategorySexual HarmCategory = 4
    // HarmCategoryMedical means promotes unchecked medical advice.
    HarmCategoryMedical HarmCategory = 5
    // HarmCategoryDangerous means dangerous content that promotes, facilitates, or encourages harmful acts.
    HarmCategoryDangerous HarmCategory = 6
    // HarmCategoryHarassment means harasment content.
    HarmCategoryHarassment HarmCategory = 7
    // HarmCategoryHateSpeech means hate speech and content.
    HarmCategoryHateSpeech HarmCategory = 8
    // HarmCategorySexuallyExplicit means sexually explicit content.
    HarmCategorySexuallyExplicit HarmCategory = 9
    // HarmCategoryDangerousContent means dangerous content.
    HarmCategoryDangerousContent HarmCategory = 10
)

However, currently, I can only adjust 4 parameters among them as below, not corresponding to the annotation in the source code or an explanation of the SDK document, and I receive a 400 error if I add more adjustments for other defined categories in HarmCategory int32 like genai.HarmCategoryMedical. Can I get some explanation or advice about this? I wonder if I misunderstood about this feature.

model.SafetySettings = []*genai.SafetySetting{
        {
            Category:  genai.HarmCategoryDangerousContent,
            Threshold: genai.HarmBlockNone,
        },
        {
            Category:  genai.HarmCategoryHarassment,
            Threshold: genai.HarmBlockNone,
        },
        {
            Category:  genai.HarmCategoryHateSpeech,
            Threshold: genai.HarmBlockNone,
        },
        {
            Category:  genai.HarmCategorySexuallyExplicit,
            Threshold: genai.HarmBlockNone,
        },
    }

Thanks is advance!

eliben commented 8 months ago

Sorry for the late reply; yes, this sounds right. We'll be working on exposing additional adjustments. Which ones are you particularly interested in?

KnightChaser commented 8 months ago

Well, I was just curious about the difference and the real code. I just wanted to turn everything on and off, just out of my curiosity... but currently I'm not working with Google's Gemini API in Go language. Thanks for reply.

jianwen-wang commented 5 months ago

We are encountering the same problem and, so far, we have only been able to set up 4 out of 11 safe settings.