prediction_guard/
toxicity.rs

1//! Data types for the toxicity endpoint.
2use serde::{Deserialize, Serialize};
3
4/// Path to the toxicity endpoint.
5pub const PATH: &str = "/toxicity";
6
7/// Request type for the toxicity endpoint.
8#[derive(Debug, Deserialize, Serialize)]
9pub struct Request {
10    pub(crate) text: String,
11}
12
13impl Request {
14    /// Creates a new request for toxicity.
15    ///
16    /// ## Arguments
17    ///
18    /// * `text` - The text to be analyzed.
19    pub fn new(text: String) -> Request {
20        Self { text }
21    }
22}
23
24/// Represents an individual check from the toxicity endpoint.
25#[derive(Debug, Default, Deserialize, Serialize)]
26#[serde(default)]
27pub struct Check {
28    pub score: f64,
29    pub index: i64,
30}
31
32/// Response type for the toxicity endpoint.
33#[derive(Debug, Default, Deserialize, Serialize)]
34#[serde(default)]
35pub struct Response {
36    pub id: String,
37    pub object: String,
38    pub created: i64,
39    pub checks: Vec<Check>,
40}