api_openai/
moderations.rs

1// src/api/moderations.rs
2//! This module defines the `Moderations` API client, which provides methods
3//! for interacting with the `OpenAI` Moderation API.
4//!
5//! For more details, refer to the [`OpenAI` Moderation API documentation](https://platform.openai.com/docs/api-reference/moderations).
6
7/// Define a private namespace for all its items.
8mod private
9{
10  // Use crate root for base access
11  use crate::
12  {
13    client ::Client,
14    error ::Result,
15    environment ::{ OpenaiEnvironment, EnvironmentInterface },
16  };
17  use crate::components::moderations::
18  {
19    CreateModerationResponse,
20  };
21
22  // External crates
23
24
25  /// The client for the `OpenAI` Moderation API.
26  #[ derive( Debug, Clone ) ]
27  pub struct Moderations< 'client, E >
28  where
29    E : OpenaiEnvironment + EnvironmentInterface + Send + Sync + 'static,
30  {
31    client : &'client Client< E >,
32  }
33
34  impl< 'client, E > Moderations< 'client, E >
35  where
36    E : OpenaiEnvironment + EnvironmentInterface + Send + Sync + 'static,
37  {
38    /// Creates a new `Moderations` client.
39    ///
40    /// # Arguments
41    /// - `client`: The core `OpenAI` `Client` to use for requests.
42    #[ inline ]
43    pub(crate) fn new( client : &'client Client< E > ) -> Self
44    {
45      Self { client }
46    }
47
48    /// Classifies if text violates `OpenAI`'s content policy.
49    ///
50    /// # Arguments
51    /// - `request`: The request body for moderation.
52    ///
53    /// # Errors
54    /// Returns `OpenAIError` if the request fails.
55    #[ inline ]
56    pub async fn create( &self, request : serde_json::Value ) -> Result< CreateModerationResponse >
57    {
58      self.client.post( "moderations", &request ).await
59    }
60  }
61} // end mod private
62
63crate ::mod_interface!
64{
65  // Expose all structs defined in this module
66  exposed use
67  {
68    Moderations,
69  };
70}