pub struct ModerationsClient<'a, T = ()> { /* private fields */ }Expand description
Client for moderations API.
Implementations§
Source§impl<T: Default + Send + Sync> ModerationsClient<'_, T>
impl<T: Default + Send + Sync> ModerationsClient<'_, T>
Sourcepub fn builder(&self, input: impl Into<String>) -> ModerationBuilder
pub fn builder(&self, input: impl Into<String>) -> ModerationBuilder
Create a moderation builder for checking text content.
§Example
ⓘ
use openai_ergonomic::Client;
let client = Client::from_env()?;
let builder = client.moderations().builder("Text to check");
let response = client.moderations().create(builder).await?;
println!("Flagged: {}", response.results[0].flagged);Sourcepub fn check(&self, input: impl Into<String>) -> ModerationBuilder
pub fn check(&self, input: impl Into<String>) -> ModerationBuilder
Convenience method for moderating a single text input.
§Example
ⓘ
use openai_ergonomic::Client;
let client = Client::from_env()?;
let builder = client.moderations().check("Hello world");
let response = client.moderations().create(builder).await?;
if response.results[0].flagged {
println!("Content was flagged for moderation");
}Sourcepub async fn create(
&self,
builder: ModerationBuilder,
) -> Result<CreateModerationResponse>
pub async fn create( &self, builder: ModerationBuilder, ) -> Result<CreateModerationResponse>
Execute a moderation request built with ModerationBuilder.
§Example
ⓘ
use openai_ergonomic::Client;
let client = Client::from_env()?;
let builder = client
.moderations()
.check("Is this content appropriate?")
.model("text-moderation-latest");
let response = client.moderations().create(builder).await?;
println!("Model: {}", response.model);
for result in response.results {
println!("Flagged: {}", result.flagged);
println!("Hate: {}", result.categories.hate);
println!("Violence: {}", result.categories.violence);
}§Errors
Returns an error if the API request fails or the response cannot be parsed.
Trait Implementations§
Source§impl<'a, T: Clone> Clone for ModerationsClient<'a, T>
impl<'a, T: Clone> Clone for ModerationsClient<'a, T>
Source§fn clone(&self) -> ModerationsClient<'a, T>
fn clone(&self) -> ModerationsClient<'a, T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a, T: Debug> Debug for ModerationsClient<'a, T>
impl<'a, T: Debug> Debug for ModerationsClient<'a, T>
impl<'a, T: Copy> Copy for ModerationsClient<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for ModerationsClient<'a, T>
impl<'a, T = ()> !RefUnwindSafe for ModerationsClient<'a, T>
impl<'a, T> Send for ModerationsClient<'a, T>
impl<'a, T> Sync for ModerationsClient<'a, T>
impl<'a, T> Unpin for ModerationsClient<'a, T>
impl<'a, T = ()> !UnwindSafe for ModerationsClient<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more