Skip to main content

async_openai/
safety.rs

1use crate::{config::Config, error::OpenAIError, Client, RequestOptions};
2
3/// Safety APIs for the authenticated project.
4pub struct Safety<'c, C: Config> {
5    client: &'c Client<C>,
6}
7
8impl<'c, C: Config> Safety<'c, C> {
9    pub fn new(client: &'c Client<C>) -> Self {
10        Self { client }
11    }
12
13    /// Access safety cases for the authenticated organization (requires api.safety.read).
14    pub fn cases(&self) -> SafetyCases<'_, C> {
15        SafetyCases::new(self.client)
16    }
17
18    /// Access project safety alerts.
19    pub fn alerts(&self) -> SafetyAlerts<'_, C> {
20        SafetyAlerts::new(self.client)
21    }
22}
23
24/// Retrieve safety alerts for the authenticated project.
25pub struct SafetyAlerts<'c, C: Config> {
26    client: &'c Client<C>,
27    pub(crate) request_options: RequestOptions,
28}
29impl<'c, C: Config> SafetyAlerts<'c, C> {
30    pub fn new(client: &'c Client<C>) -> Self {
31        Self {
32            client,
33            request_options: RequestOptions::new(),
34        }
35    }
36    /// Get a safety alert belonging to the authenticated API project.
37    pub async fn retrieve(
38        &self,
39        id: &str,
40    ) -> Result<crate::types::safety::SafetyAlertResource, OpenAIError> {
41        self.client
42            .get(&format!("/safety/alerts/{id}"), &self.request_options)
43            .await
44    }
45}
46
47/// Retrieve organization safety warnings and deactivations.
48pub struct SafetyCases<'c, C: Config> {
49    client: &'c Client<C>,
50    pub(crate) request_options: RequestOptions,
51}
52impl<'c, C: Config> SafetyCases<'c, C> {
53    pub fn new(client: &'c Client<C>) -> Self {
54        Self {
55            client,
56            request_options: RequestOptions::new(),
57        }
58    }
59    /// Retrieve a safety case using the case ID from a safety webhook.
60    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
61    pub async fn retrieve(
62        &self,
63        id: &str,
64    ) -> Result<crate::types::safety::SafetyCaseResource, OpenAIError> {
65        self.client
66            .get(&format!("/safety/cases/{id}"), &self.request_options)
67            .await
68    }
69}