async_openai_alt/
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    pub async fn list(&self) -> Result<ListModelResponse, OpenAIError> {
23        self.client.get("/models").await
24    }
25
26    /// Retrieves a model instance, providing basic information about the model
27    /// such as the owner and permissioning.
28    pub async fn retrieve(&self, id: &str) -> Result<Model, OpenAIError> {
29        self.client.get(format!("/models/{id}").as_str()).await
30    }
31
32    /// Delete a fine-tuned model. You must have the Owner role in your organization.
33    pub async fn delete(&self, model: &str) -> Result<DeleteModelResponse, OpenAIError> {
34        self.client
35            .delete(format!("/models/{model}").as_str())
36            .await
37    }
38}