Move predict image safety settings to enum
Some checks failed
Rust / build (push) Has been cancelled

This commit is contained in:
2025-06-08 09:24:34 +01:00
parent 9a8732f609
commit 1d467138ed
2 changed files with 12 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ use std::{error::Error, io::Cursor};
use gemini_rs::prelude::{ use gemini_rs::prelude::{
GeminiClient, PersonGeneration, PredictImageRequest, PredictImageRequestParameters, GeminiClient, PersonGeneration, PredictImageRequest, PredictImageRequestParameters,
PredictImageRequestParametersOutputOptions, PredictImageRequestPrompt, PredictImageRequestParametersOutputOptions, PredictImageRequestPrompt,
PredictImageSafetySetting,
}; };
use image::{ImageFormat, ImageReader}; use image::{ImageFormat, ImageReader};
@@ -35,6 +36,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
compression_quality: Some(75), compression_quality: Some(75),
}), }),
person_generation: Some(PersonGeneration::AllowAll), person_generation: Some(PersonGeneration::AllowAll),
safety_setting: Some(PredictImageSafetySetting::BlockOnlyHigh),
..Default::default() ..Default::default()
}, },
}; };

View File

@@ -126,7 +126,7 @@ pub struct PredictImageRequestParameters {
/// Supported by the models `imagen-3.0-generate-001`, `imagen-3.0-fast-generate-001`, and /// Supported by the models `imagen-3.0-generate-001`, `imagen-3.0-fast-generate-001`, and
/// `imagegeneration@006` only. /// `imagegeneration@006` only.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub safety_setting: Option<String>, pub safety_setting: Option<PredictImageSafetySetting>,
/// Add an invisible watermark to the generated images. The default value is `false` for the /// Add an invisible watermark to the generated images. The default value is `false` for the
/// `imagegeneration@002` and `imagegeneration@005` models, and `true` for the /// `imagegeneration@002` and `imagegeneration@005` models, and `true` for the
@@ -176,3 +176,12 @@ pub enum PersonGeneration {
AllowAdult, AllowAdult,
AllowAll, AllowAll,
} }
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PredictImageSafetySetting {
BlockLowAndAbove,
BlockMediumAndAbove,
BlockOnlyHigh,
BlockNone,
}