Skip to content

Commit b37d282

Browse files
committed
types::moderations
1 parent ced7144 commit b37d282

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

async-openai/src/moderation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
config::Config,
33
error::OpenAIError,
4-
types::{CreateModerationRequest, CreateModerationResponse},
4+
types::moderations::{CreateModerationRequest, CreateModerationResponse},
55
Client,
66
};
77

async-openai/src/types/impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use super::{
2828
CreateImageEditRequest, CreateImageVariationRequest, DallE2ImageSize, Image, ImageInput,
2929
ImageModel, ImageResponseFormat, ImageSize, ImagesResponse,
3030
},
31+
moderations::ModerationInput,
3132
responses::{EasyInputContent, Role as ResponsesRole},
3233
uploads::AddUploadPartRequest,
3334
ChatCompletionFunctionCall, ChatCompletionFunctions, ChatCompletionNamedToolChoice,
@@ -40,7 +41,7 @@ use super::{
4041
ChatCompletionRequestToolMessageContent, ChatCompletionRequestUserMessage,
4142
ChatCompletionRequestUserMessageContent, ChatCompletionRequestUserMessageContentPart,
4243
ChatCompletionToolChoiceOption, CreateContainerFileRequest, CreateMessageRequestContent,
43-
CreateVideoRequest, FunctionName, ImageUrl, ModerationInput, Prompt, Role, Stop,
44+
CreateVideoRequest, FunctionName, ImageUrl, Prompt, Role, Stop,
4445
};
4546

4647
/// for `impl_from!(T, Enum)`, implements

async-openai/src/types/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod logprob;
2121
mod mcp;
2222
mod message;
2323
pub mod models;
24-
mod moderation;
24+
pub mod moderations;
2525
mod project_api_key;
2626
mod project_service_account;
2727
mod project_users;
@@ -52,7 +52,6 @@ pub use invites::*;
5252
pub use logprob::*;
5353
pub use mcp::*;
5454
pub use message::*;
55-
pub use moderation::*;
5655
pub use project_api_key::*;
5756
pub use project_service_account::*;
5857
pub use project_users::*;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod moderation;
2+
3+
pub use moderation::*;

async-openai/src/types/moderation.rs renamed to async-openai/src/types/moderations/moderation.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,29 @@ pub enum ModerationInput {
1616
MultiModal(Vec<ModerationContentPart>),
1717
}
1818

19+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
20+
pub struct ModerationTextInput {
21+
/// A string of text to classify
22+
pub text: String,
23+
}
24+
25+
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
26+
pub struct ModerationImageURLInput {
27+
/// Either a URL of the image or the base64 encoded image data.
28+
pub image_url: String,
29+
}
30+
1931
/// Content part for multi-modal moderation input
2032
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
2133
#[serde(tag = "type")]
2234
pub enum ModerationContentPart {
2335
/// An object describing text to classify
2436
#[serde(rename = "text")]
25-
Text {
26-
/// A string of text to classify
27-
text: String,
28-
},
37+
Text(ModerationTextInput),
2938

3039
/// An object describing an image to classify
3140
#[serde(rename = "image_url")]
32-
ImageUrl {
33-
/// Contains either an image URL or a data URL for a base64 encoded image
34-
image_url: ModerationImageUrl,
35-
},
36-
}
37-
38-
/// Image URL configuration for image moderation
39-
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
40-
pub struct ModerationImageUrl {
41-
/// Either a URL of the image or the base64 encoded image data
42-
pub url: String,
41+
ImageUrl(ModerationImageURLInput),
4342
}
4443

4544
#[derive(Debug, Default, Clone, Serialize, Builder, PartialEq, Deserialize)]
@@ -53,15 +52,15 @@ pub struct CreateModerationRequest {
5352
/// an array of multi-modal input objects similar to other models.
5453
pub input: ModerationInput,
5554

56-
/// The content moderation model you would like to use. Learn more in the
57-
/// [moderation guide](https://platform.openai.com/docs/guides/moderation), and learn about
58-
/// available models [here](https://platform.openai.com/docs/models/moderation).
55+
/// The content moderation model you would like to use. Learn more in
56+
/// [the moderation guide](https://platform.openai.com/docs/guides/moderation), and learn about
57+
/// available models [here](https://platform.openai.com/docs/models#moderation).
5958
#[serde(skip_serializing_if = "Option::is_none")]
6059
pub model: Option<String>,
6160
}
6261

6362
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
64-
pub struct Category {
63+
pub struct Categories {
6564
/// Content that expresses, incites, or promotes hate based on race, gender,
6665
/// ethnicity, religion, nationality, sexual orientation, disability status, or
6766
/// caste. Hateful content aimed at non-protected groups (e.g., chess players)
@@ -147,7 +146,7 @@ pub struct ContentModerationResult {
147146
/// Whether any of the below categories are flagged.
148147
pub flagged: bool,
149148
/// A list of the categories, and whether they are flagged or not.
150-
pub categories: Category,
149+
pub categories: Categories,
151150
/// A list of the categories along with their scores as predicted by model.
152151
pub category_scores: CategoryScore,
153152
/// A list of the categories along with the input type(s) that the score applies to.

0 commit comments

Comments
 (0)