सुरक्षा सेटिंग का इस्तेमाल करके, ऐसे जवाब मिलने की संभावना को कम किया जा सकता है जिन्हें नुकसान पहुंचाने वाला माना जा सकता है. सुरक्षा सेटिंग, डिफ़ॉल्ट रूप से ऐसे कॉन्टेंट को ब्लॉक कर देती हैं जिसके असुरक्षित होने की संभावना, सभी डाइमेंशन में मीडियम और/या ज़्यादा होती है.
|
इस पेज पर, 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 आउटपुट जनरेट करते समय किया जाता है. हालांकि, इसका इस्तेमाल क्लासिफ़िकेशन टास्क के लिए भी किया जा सकता है. जैसे, जब आपको मॉडल से खास लेबल या टैग इस्तेमाल कराने हों.