outfox-openai 0.7.0

Openai for outfox
Documentation
mod messages;
mod runs;
mod steps;
mod threads;

pub use messages::*;
pub use runs::*;
use serde::Serialize;
pub use steps::*;
pub use threads::*;

use crate::config::Config;
use crate::error::OpenAIError;
use crate::spec::{
    AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
    ModifyAssistantRequest,
};
use crate::{Client, RequestOptions};

/// Build assistants that can call models and use tools to perform tasks.
///
/// [Get started with the Assistants API](https://platform.openai.com/docs/assistants)
pub struct Assistants<'c, C: Config> {
    client: &'c Client<C>,
    pub(crate) request_options: RequestOptions,
}

impl<'c, C: Config> Assistants<'c, C> {
    pub fn new(client: &'c Client<C>) -> Self {
        Self {
            client,
            request_options: RequestOptions::new(),
        }
    }

    /// Create an assistant with a model and instructions.
    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
    pub async fn create(
        &self,
        request: CreateAssistantRequest,
    ) -> Result<AssistantObject, OpenAIError> {
        self.client
            .post("/assistants", request, &self.request_options)
            .await
    }

    /// Retrieves an assistant.
    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
    pub async fn retrieve(&self, assistant_id: &str) -> Result<AssistantObject, OpenAIError> {
        self.client
            .get(
                &format!("/assistants/{assistant_id}"),
                &self.request_options,
            )
            .await
    }

    /// Modifies an assistant.
    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
    pub async fn update(
        &self,
        assistant_id: &str,
        request: ModifyAssistantRequest,
    ) -> Result<AssistantObject, OpenAIError> {
        self.client
            .post(
                &format!("/assistants/{assistant_id}"),
                request,
                &self.request_options,
            )
            .await
    }

    /// Delete an assistant.
    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
    pub async fn delete(&self, assistant_id: &str) -> Result<DeleteAssistantResponse, OpenAIError> {
        self.client
            .delete(
                &format!("/assistants/{assistant_id}"),
                &self.request_options,
            )
            .await
    }

    /// Returns a list of assistants.
    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
    pub async fn list<Q>(&self, _query: &Q) -> Result<ListAssistantsResponse, OpenAIError>
    where
        Q: Serialize + ?Sized,
    {
        // TODO: query parameter is not currently used in the API call
        self.client.get("/assistants", &self.request_options).await
    }
}