सुरक्षा सेटिंग का इस्तेमाल करके, ऐसे जवाब पाने की संभावना को कम किया जा सकता है जिन्हें नुकसान पहुंचाने वाला माना जा सकता है. डिफ़ॉल्ट रूप से, सुरक्षा सेटिंग सभी डाइमेंशन में, ऐसे कॉन्टेंट को ब्लॉक कर देती हैं जिसकी असुरक्षित कॉन्टेंट होने की संभावना मध्यम और/या ज़्यादा हो.
Gemini सुरक्षा सेटिंग पर जाएं Imagen सुरक्षा सेटिंग पर जाएं
Gemini मॉडल के लिए सुरक्षा सेटिंग
इस पेज पर, सेवा देने वाली कंपनी से जुड़ा कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
Swift
GenerativeModel
इंस्टेंस बनाते समय, SafetySettings
को कॉन्फ़िगर किया जाता है.
सुरक्षा सेटिंग का एक उदाहरण:
import FirebaseAI
// Initialize the Gemini Developer API backend service
// Create an `GenerativeModel` instance and add safety settings to its config
let model = FirebaseAI.firebaseAI(backend: .googleAI()).generativeModel(
modelName: "GEMINI_MODEL_NAME",
safetySettings: [
SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh)
]
)
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग वाला उदाहरण:
import FirebaseAI
let harassmentSafety = SafetySetting(harmCategory: .harassment, threshold: .blockOnlyHigh)
let hateSpeechSafety = SafetySetting(harmCategory: .hateSpeech, threshold: .blockMediumAndAbove)
// Initialize the Gemini Developer API backend service
// Create an `GenerativeModel` instance and add safety settings to its config
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
// Create a `GenerativeModel` instance and add safety settings to its config
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)
// Create a `GenerativeModel` instance and add safety settings to its config
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);
// Create an `GenerativeModel` instance and add safety settings to its config
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "IMAGEN_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);
// Create an `GenerativeModel` instance and add safety settings to its config
GenerativeModelFutures model = GenerativeModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.generativeModel(
/* modelName */ "IMAGEN_MODEL_NAME",
/* generationConfig is optional */ null,
List.of(harassmentSafety, hateSpeechSafety)
);
);
// ...
Web
GenerativeModel
इंस्टेंस बनाते समय, SafetySettings
को कॉन्फ़िगर किया जाता है.
सुरक्षा सेटिंग का एक उदाहरण:
import { HarmBlockThreshold, HarmCategory, getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// ...
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
const safetySettings = [
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH,
},
];
// Create a `GenerativeModel` instance and add safety settings to its config
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", safetySettings });
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग वाला उदाहरण:
import { HarmBlockThreshold, HarmCategory, getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";
// ...
// Initialize the Gemini Developer API backend service
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,
},
];
// Create a `GenerativeModel` instance and add safety settings to its config
const model = getGenerativeModel(ai, { model: "GEMINI_MODEL_NAME", safetySettings });
// ...
Dart
GenerativeModel
इंस्टेंस बनाते समय, SafetySettings
को कॉन्फ़िगर किया जाता है.
सुरक्षा सेटिंग का एक उदाहरण:
// ...
final safetySettings = [
SafetySetting(HarmCategory.harassment, HarmBlockThreshold.high)
];
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance and add safety settings to its config
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
safetySettings: safetySettings,
);
// ...
सुरक्षा से जुड़ी एक से ज़्यादा सेटिंग वाला उदाहरण:
// ...
final safetySettings = [
SafetySetting(HarmCategory.harassment, HarmBlockThreshold.high),
SafetySetting(HarmCategory.hateSpeech, HarmBlockThreshold.high),
];
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance and add safety settings to its config
final model = FirebaseAI.googleAI().generativeModel(
model: 'GEMINI_MODEL_NAME',
safetySettings: safetySettings,
);
// ...
Unity
GenerativeModel
इंस्टेंस बनाते समय, SafetySettings
को कॉन्फ़िगर किया जाता है.
सुरक्षा सेटिंग का एक उदाहरण:
// ...
// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance and add safety settings to its config
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);
// Initialize the Vertex AI Gemini API backend service
// Create a `GenerativeModel` instance and add safety settings to its config
var ai = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI());
var model = ai.GetGenerativeModel(
modelName: "GEMINI_MODEL_NAME",
safetySettings: new SafetySetting[] { harassmentSafety, hateSpeechSafety }
);
// ...
Imagen मॉडल के लिए सुरक्षा सेटिंग
इस पेज पर, सेवा देने वाली कंपनी से जुड़ा कॉन्टेंट और कोड देखने के लिए, Gemini API पर क्लिक करें. |
Google Cloud दस्तावेज़ में, Imagen मॉडल के लिए काम करने वाली सुरक्षा सेटिंग और उनकी उपलब्ध वैल्यू के बारे में जानें.
Swift
ImagenModel
इंस्टेंस बनाते समय, ImagenSafetySettings
को कॉन्फ़िगर किया जाता है.
import FirebaseAI
// Initialize the Gemini Developer API backend service
// Create an `ImagenModel` instance and add safety settings to its config
let model = FirebaseAI.firebaseAI(backend: .googleAI()).imagenModel(
modelName: "IMAGEN_MODEL_NAME",
safetySettings: ImagenSafetySettings(
safetyFilterLevel: .blockLowAndAbove,
personFilterLevel: .allowAdult
)
)
// ...
Kotlin
ImagenModel
इंस्टेंस बनाते समय, ImagenSafetySettings
को कॉन्फ़िगर किया जाता है.
// Initialize the Vertex AI Gemini API backend service
// Create an `ImagenModel` instance and add safety settings to its config
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).imagenModel(
modelName = "IMAGEN_MODEL_NAME",
safetySettings = ImagenSafetySettings(
safetyFilterLevel = ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
personFilterLevel = ImagenPersonFilterLevel.BLOCK_ALL
)
)
// ...
Java
ImagenModel
इंस्टेंस बनाते समय, ImagenSafetySettings
को कॉन्फ़िगर किया जाता है.
// Create an `ImagenModel` instance and add safety settings to its config
ImagenModelFutures model = ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(
/* modelName */ "IMAGEN_MODEL_NAME",
/* imageGenerationConfig */ null);
);
// ...
Web
ImagenModel
इंस्टेंस बनाते समय, ImagenSafetySettings
को कॉन्फ़िगर किया जाता है.
// ...
// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Create an `ImagenModel` instance and add safety settings to its config
const model = getImagenModel(
ai,
{
model: "IMAGEN_MODEL_NAME",
safetySettings: {
safetyFilterLevel: ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
personFilterLevel: ImagenPersonFilterLevel.ALLOW_ADULT,
}
}
);
// ...
Dart
ImagenModel
इंस्टेंस बनाते समय, ImagenSafetySettings
को कॉन्फ़िगर किया जाता है.
// ...
// Initialize the Gemini Developer API backend service
// Create an `ImagenModel` instance and add safety settings to its config
final model = FirebaseAI.googleAI().imagenModel(
model: 'IMAGEN_MODEL_NAME',
safetySettings: ImagenSafetySettings(
ImagenSafetyFilterLevel.blockLowAndAbove,
ImagenPersonFilterLevel.allowAdult,
),
);
// ...
Unity
फ़िलहाल, Unity में Imagen का इस्तेमाल नहीं किया जा सकता. हालांकि, जल्द ही इसकी सुविधा उपलब्ध होगी!
कॉन्टेंट जनरेशन को कंट्रोल करने के अन्य विकल्प
- प्रॉम्प्ट डिज़ाइन के बारे में ज़्यादा जानें, ताकि आप अपनी ज़रूरतों के हिसाब से आउटपुट जनरेट करने के लिए, मॉडल पर असर डाल सकें.
- मॉडल के जवाब जनरेट करने के तरीके को कंट्रोल करने के लिए, मॉडल पैरामीटर को कॉन्फ़िगर करें. Gemini मॉडल के लिए, इन पैरामीटर में ज़्यादा से ज़्यादा आउटपुट टोकन, तापमान, topK, और topP शामिल हैं. Imagen मॉडल के लिए, इनमें आसपेक्ट रेशियो, व्यक्ति जनरेशन, वॉटरमार्किंग वगैरह शामिल हैं.
- मॉडल के व्यवहार को कंट्रोल करने के लिए, सिस्टम के निर्देश सेट करें. यह सुविधा, एनोटेशन की तरह होती है. इसे मॉडल को असली उपयोगकर्ता से मिलने वाले निर्देशों से पहले जोड़ा जाता है.
- किसी खास आउटपुट स्कीमा की जानकारी देने के लिए, प्रॉम्प्ट के साथ रिस्पॉन्स स्कीमा पास करें. आम तौर पर, JSON आउटपुट जनरेट करने के लिए इस सुविधा का इस्तेमाल किया जाता है. हालांकि, इसका इस्तेमाल वर्गीकरण के टास्क के लिए भी किया जा सकता है. जैसे, जब आपको मॉडल को किसी खास लेबल या टैग का इस्तेमाल करना हो.