use crate::{
config::Config,
error::OpenAIError,
types::models::{DeleteModelResponse, ListModelResponse, Model},
Client, RequestOptions,
};
pub struct Models<'c, C: Config> {
client: &'c Client<C>,
pub(crate) request_options: RequestOptions,
}
impl<'c, C: Config> Models<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self {
client,
request_options: RequestOptions::new(),
}
}
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<ListModelResponse, OpenAIError> {
self.client.get("/models", &self.request_options).await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn retrieve(&self, model: &str) -> Result<Model, OpenAIError> {
self.client
.get(format!("/models/{model}").as_str(), &self.request_options)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, model: &str) -> Result<DeleteModelResponse, OpenAIError> {
self.client
.delete(format!("/models/{model}").as_str(), &self.request_options)
.await
}
}