async_openai/
model.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::{DeleteModelResponse, ListModelResponse, Model},
5    Client,
6};
7
8/// List and describe the various models available in the API.
9/// You can refer to the [Models](https://platform.openai.com/docs/models) documentation to understand what
10/// models are available and the differences between them.
11pub struct Models<'c, C: Config> {
12    client: &'c Client<C>,
13}
14
15impl<'c, C: Config> Models<'c, C> {
16    pub fn new(client: &'c Client<C>) -> Self {
17        Self { client }
18    }
19
20    /// Lists the currently available models, and provides basic information
21    /// about each one such as the owner and availability.
22    #[crate::byot(R = serde::de::DeserializeOwned)]
23    pub async fn list(&self) -> Result<ListModelResponse, OpenAIError> {
24        self.client.get("/models").await
25    }
26
27    /// Retrieves a model instance, providing basic information about the model
28    /// such as the owner and permissioning.
29    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
30    pub async fn retrieve(&self, id: &str) -> Result<Model, OpenAIError> {
31        self.client.get(format!("/models/{id}").as_str()).await
32    }
33
34    /// Delete a fine-tuned model. You must have the Owner role in your organization.
35    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
36    pub async fn delete(&self, model: &str) -> Result<DeleteModelResponse, OpenAIError> {
37        self.client
38            .delete(format!("/models/{model}").as_str())
39            .await
40    }
41}