सुरक्षा सेटिंग का इस्तेमाल करके, ऐसे जवाब मिलने की संभावना को कम किया जा सकता है जिन्हें नुकसान पहुंचाने वाला माना जा सकता है. डिफ़ॉल्ट रूप से, सुरक्षा सेटिंग ऐसे कॉन्टेंट को ब्लॉक करती हैं जिसके असुरक्षित होने की संभावना मध्यम और/या ज़्यादा होती है. ऐसा सभी डाइमेंशन के लिए किया जाता है.
|
इस पेज पर, सेवा देने वाली कंपनी के हिसाब से कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
Swift
GenerativeModel इंस्टेंस बनाते समय, आपको SafetySettings को कॉन्फ़िगर करना होता है.
सुरक्षा से जुड़ी एक सेटिंग का उदाहरण:
import FirebaseAILogic
// Specify the safety settings as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
safetySettings: [
SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh)
]
)
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग का उदाहरण:
import FirebaseAILogic
let harassmentSafety = SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh)
let hateSpeechSafety = SafetySetting(harmCategory: .hateSpeech, threshold: .blockMediumAndAbove)
// Specify the safety settings as part of creating the `GenerativeModel` instance.
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
safetySettings: [harassmentSafety, hateSpeechSafety]
)
// ...
Kotlin
GenerativeModel इंस्टेंस बनाते समय, आपको SafetySettings को कॉन्फ़िगर करना होता है.
सुरक्षा से जुड़ी एक सेटिंग का उदाहरण:
import com.google.firebase.vertexai.type.HarmBlockThreshold
import com.google.firebase.vertexai.type.HarmCategory
import com.google.firebase.vertexai.type.SafetySetting
// Specify the safety settings as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
safetySettings = listOf(
SafetySetting(HarmCategory.HARASSMENT, HarmBlockThreshold.ONLY_HIGH)
)
)
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग का उदाहरण:
import com.google.firebase.vertexai.type.HarmBlockThreshold
import com.google.firebase.vertexai.type.HarmCategory
import com.google.firebase.vertexai.type.SafetySetting
val harassmentSafety = SafetySetting(HarmCategory.HARASSMENT, HarmBlockThreshold.ONLY_HIGH)
val hateSpeechSafety = SafetySetting(HarmCategory.HATE_SPEECH, HarmBlockThreshold.MEDIUM_AND_ABOVE)
// Specify the safety settings as part of creating the `GenerativeModel` instance.
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(
modelName = "GEMINI_MODEL_NAME",
safetySettings = listOf(harassmentSafety, hateSpeechSafety)
)
// ...
Java
GenerativeModel इंस्टेंस बनाते समय, आपको SafetySettings को कॉन्फ़िगर करना होता है.
SafetySetting harassmentSafety = new SafetySetting(HarmCategory.HARASSMENT,
HarmBlockThreshold.ONLY_HIGH);
// Specify the safety settings as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "GEMINI_MODEL_NAME",
/* generationConfig is optional */ null,
Collections.singletonList(harassmentSafety)
);
);
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग का उदाहरण:
SafetySetting harassmentSafety = new SafetySetting(HarmCategory.HARASSMENT,
HarmBlockThreshold.ONLY_HIGH);
SafetySetting hateSpeechSafety = new SafetySetting(HarmCategory.HATE_SPEECH,
HarmBlockThreshold.MEDIUM_AND_ABOVE);
// Specify the safety settings as part of creating the `GenerativeModel` instance.
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "GEMINI_MODEL_NAME",
/* generationConfig is optional */ null,
List.of(harassmentSafety, hateSpeechSafety)
);
);
// ...
Web
GenerativeModel इंस्टेंस बनाते समय, आपको SafetySettings को कॉन्फ़िगर करना होता है.
सुरक्षा से जुड़ी एक सेटिंग का उदाहरण:
import { HarmBlockThreshold, HarmCategory, getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
];
// Specify the safety settings as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", safetySettings });
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग का उदाहरण:
import { HarmBlockThreshold, HarmCategory, getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
},
];
// Specify the safety settings as part of creating the `GenerativeModel` instance.
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", safetySettings });
// ...
Dart
GenerativeModel इंस्टेंस बनाते समय, आपको SafetySettings को कॉन्फ़िगर करना होता है.
सुरक्षा से जुड़ी एक सेटिंग का उदाहरण:
// ...
final safetySettings = [
SafetySetting(HarmCategory.harassment, HarmBlockThreshold.high)
];
// Specify the safety settings as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
safetySettings: safetySettings,
);
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग का उदाहरण:
// ...
final safetySettings = [
SafetySetting(HarmCategory.harassment, HarmBlockThreshold.high),
SafetySetting(HarmCategory.hateSpeech, HarmBlockThreshold.high),
];
// Specify the safety settings as part of creating the `GenerativeModel` instance.
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
safetySettings: safetySettings,
);
// ...
Unity
GenerativeModel इंस्टेंस बनाते समय, आपको SafetySettings को कॉन्फ़िगर करना होता है.
सुरक्षा से जुड़ी एक सेटिंग का उदाहरण:
// ...
// Specify the safety settings as part of creating the `GenerativeModel` instance.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
safetySettings: new SafetySetting[] {
new SafetySetting(HarmCategory.Harassment, SafetySetting.HarmBlockThreshold.OnlyHigh)
}
);
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग का उदाहरण:
// ...
var harassmentSafety = new SafetySetting(HarmCategory.Harassment, SafetySetting.HarmBlockThreshold.OnlyHigh);
var hateSpeechSafety = new SafetySetting(HarmCategory.HateSpeech, SafetySetting.HarmBlockThreshold.MediumAndAbove);
// Specify the safety settings as part of creating the `GenerativeModel` instance.
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
safetySettings: new SafetySetting[] { harassmentSafety, hateSpeechSafety }
);
// ...
कॉन्टेंट जनरेट करने की सुविधा को कंट्रोल करने के अन्य विकल्प
- प्रॉम्प्ट डिज़ाइन के बारे में ज़्यादा जानें, ताकि आप मॉडल को अपनी ज़रूरतों के हिसाब से आउटपुट जनरेट करने के लिए प्रभावित कर सकें.
- मॉडल के पैरामीटर कॉन्फ़िगर करें, ताकि यह कंट्रोल किया जा सके कि मॉडल कैसे जवाब जनरेट करता है. जैसे, ज़्यादा से ज़्यादा आउटपुट टोकन, बार-बार आउटपुट टोकन मिलने की संभावना वगैरह.
- मॉडल के व्यवहार को कंट्रोल करने के लिए, सिस्टम के निर्देश सेट करें. यह सुविधा, प्रस्तावना की तरह होती है. इसे मॉडल को असली उपयोगकर्ता से मिलने वाले निर्देशों के बारे में बताने से पहले जोड़ा जाता है.
- किसी खास आउटपुट स्कीमा के बारे में बताने के लिए, प्रॉम्प्ट के साथ जवाब का स्कीमा पास करें. इस सुविधा का इस्तेमाल, आम तौर पर JSON आउटपुट जनरेट करने के लिए किया जाता है. हालांकि, इसका इस्तेमाल क्लासिफ़िकेशन टास्क के लिए भी किया जा सकता है. जैसे, जब आपको मॉडल से किसी खास लेबल या टैग का इस्तेमाल करवाना हो.