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 project safety alerts.
14    pub fn alerts(&self) -> SafetyAlerts<'_, C> {
15        SafetyAlerts::new(self.client)
16    }
17}
18
19/// Retrieve safety alerts for the authenticated project.
20pub struct SafetyAlerts<'c, C: Config> {
21    client: &'c Client<C>,
22    pub(crate) request_options: RequestOptions,
23}
24impl<'c, C: Config> SafetyAlerts<'c, C> {
25    pub fn new(client: &'c Client<C>) -> Self {
26        Self {
27            client,
28            request_options: RequestOptions::new(),
29        }
30    }
31    /// Get a safety alert belonging to the authenticated API project.
32    pub async fn retrieve(
33        &self,
34        id: &str,
35    ) -> Result<crate::types::safety::SafetyAlertResource, OpenAIError> {
36        self.client
37            .get(&format!("/safety/alerts/{id}"), &self.request_options)
38            .await
39    }
40}