Ustawienia bezpieczeństwa pozwalają dostosować prawdopodobieństwo otrzymania odpowiedzi, które mogą być uznane za szkodliwe. Domyślnie ustawienia bezpieczeństwa blokują treści, które ze średnim lub wysokim prawdopodobieństwem są niebezpieczne. Dotyczy to wszystkich wymiarów.
Przejdź do Gemini ustawień bezpieczeństwa Przejdź do Imagen ustawień bezpieczeństwa (Wycofane)
Ustawienia bezpieczeństwa modeli Gemini
|
Kliknij dostawcę Gemini API, aby wyświetlić na tej stronie treści i kod specyficzne dla dostawcy. |
Swift
Konfigurujesz
SafetySettings
podczas tworzenia instancji GenerativeModel.
Przykład z 1 ustawieniem bezpieczeństwa:
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)
]
)
// ...
Przykład z kilkoma ustawieniami bezpieczeństwa:
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
Konfigurujesz
SafetySettings
podczas tworzenia instancji GenerativeModel.
Przykład z 1 ustawieniem bezpieczeństwa:
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)
)
)
// ...
Przykład z kilkoma ustawieniami bezpieczeństwa:
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
Konfigurujesz
SafetySettings
podczas tworzenia instancji GenerativeModel.
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)
);
);
// ...
Przykład z kilkoma ustawieniami bezpieczeństwa:
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
Konfigurujesz
SafetySettings
podczas tworzenia instancji GenerativeModel.
Przykład z 1 ustawieniem bezpieczeństwa:
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 });
// ...
Przykład z kilkoma ustawieniami bezpieczeństwa:
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
Konfigurujesz
SafetySettings
podczas tworzenia instancji GenerativeModel.
Przykład z 1 ustawieniem bezpieczeństwa:
// ...
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,
);
// ...
Przykład z kilkoma ustawieniami bezpieczeństwa:
// ...
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
Konfigurujesz
SafetySettings
podczas tworzenia instancji GenerativeModel.
Przykład z 1 ustawieniem bezpieczeństwa:
// ...
// 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)
}
);
// ...
Przykład z kilkoma ustawieniami bezpieczeństwa:
// ...
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 }
);
// ...
Ustawienia bezpieczeństwa modeli Imagen
|
Kliknij dostawcę Gemini API, aby wyświetlić na tej stronie treści i kod specyficzne dla dostawcy. |
Więcej informacji o wszystkich obsługiwanych ustawieniach bezpieczeństwa i ich dostępnych wartościach w przypadku modeli Imagen znajdziesz w dokumentacji Google Cloud.
Swift
Konfigurujesz
ImagenSafetySettings
podczas tworzenia instancji ImagenModel.
import FirebaseAILogic
// Specify the safety settings as part of creating the `ImagenModel` instance
let model = FirebaseAI.firebaseAI(backend: .googleAI()).imagenModel(
modelName: "IMAGEN_MODEL_NAME",
safetySettings: ImagenSafetySettings(
safetyFilterLevel: .blockLowAndAbove,
personFilterLevel: .allowAdult
)
)
// ...
Kotlin
Konfigurujesz
ImagenSafetySettings
podczas tworzenia instancji ImagenModel.
// Specify the safety settings as part of creating the `ImagenModel` instance
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
Konfigurujesz
ImagenSafetySettings
podczas tworzenia instancji ImagenModel.
// Specify the safety settings as part of creating the `ImagenModel` instance
ImagenModelFutures model = ImagenModelFutures.from(
FirebaseAI.getInstance(GenerativeBackend.googleAI())
.imagenModel(
/* modelName */ "IMAGEN_MODEL_NAME",
/* imageGenerationConfig */ null);
);
// ...
Web
Konfigurujesz
ImagenSafetySettings
podczas tworzenia instancji ImagenModel.
// ...
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });
// Specify the safety settings as part of creating the `ImagenModel` instance
const model = getImagenModel(
ai,
{
model: "IMAGEN_MODEL_NAME",
safetySettings: {
safetyFilterLevel: ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
personFilterLevel: ImagenPersonFilterLevel.ALLOW_ADULT,
}
}
);
// ...
Dart
Konfigurujesz
ImagenSafetySettings
podczas tworzenia instancji ImagenModel.
// ...
// Specify the safety settings as part of creating the `ImagenModel` instance
final model = FirebaseAI.googleAI().imagenModel(
model: 'IMAGEN_MODEL_NAME',
safetySettings: ImagenSafetySettings(
ImagenSafetyFilterLevel.blockLowAndAbove,
ImagenPersonFilterLevel.allowAdult,
),
);
// ...
Unity
Konfigurujesz
ImagenSafetySettings
podczas tworzenia instancji ImagenModel.
using Firebase.AI;
// Specify the safety settings as part of creating the `ImagenModel` instance
var model = FirebaseAI.GetInstance(FirebaseAI.Backend.GoogleAI()).GetImagenModel(
modelName: "IMAGEN_MODEL_NAME",
safetySettings: new ImagenSafetySettings(
safetyFilterLevel: ImagenSafetySettings.SafetyFilterLevel.BlockLowAndAbove,
personFilterLevel: ImagenSafetySettings.PersonFilterLevel.AllowAdult
)
);
// ...
Inne opcje kontrolowania generowania treści
- Dowiedz się więcej o projektowaniu promptów aby wpływać na model i generować dane wyjściowe dostosowane do Twoich potrzeb.
- Skonfiguruj parametry modelu aby kontrolować sposób generowania odpowiedzi przez model. W przypadku modeli Gemini parametry te obejmują maksymalną liczbę tokenów wyjściowych, prawdopodobieństwo powtórzenia tokenów wyjściowych itp. W przypadku modeli Imagen obejmują one proporcje, generowanie osób, dodawanie znaków wodnych itp.
- Ustaw instrukcje systemowe , aby kierować działaniem modelu. Ta funkcja działa jak wstęp, który dodajesz, zanim model otrzyma dalsze instrukcje od użytkownika.
- Przekaż schemat odpowiedzi wraz z promptem, aby określić konkretny schemat wyjściowy. Ta funkcja jest najczęściej używana podczas generowania danych wyjściowych w formacie JSON, ale można jej też używać do zadań klasyfikacji (np. gdy chcesz, aby model używał określonych etykiet lub tagów).