prediction_guard/
injection.rs

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