async_openai/
model.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::models::{DeleteModelResponse, ListModelResponse, Model},
5    Client, RequestOptions,
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    pub(crate) request_options: RequestOptions,
14}
15
16impl<'c, C: Config> Models<'c, C> {
17    pub fn new(client: &'c Client<C>) -> Self {
18        Self {
19            client,
20            request_options: RequestOptions::new(),
21        }
22    }
23
24    /// Lists the currently available models, and provides basic information
25    /// about each one such as the owner and availability.
26    #[crate::byot(R = serde::de::DeserializeOwned)]
27    pub async fn list(&self) -> Result<ListModelResponse, OpenAIError> {
28        self.client.get("/models", &self.request_options).await
29    }
30
31    /// Retrieves a model instance, providing basic information about the model
32    /// such as the owner and permissioning.
33    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
34    pub async fn retrieve(&self, model: &str) -> Result<Model, OpenAIError> {
35        self.client
36            .get(format!("/models/{model}").as_str(), &self.request_options)
37            .await
38    }
39
40    /// Delete a fine-tuned model. You must have the Owner role in your organization.
41    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
42    pub async fn delete(&self, model: &str) -> Result<DeleteModelResponse, OpenAIError> {
43        self.client
44            .delete(format!("/models/{model}").as_str(), &self.request_options)
45            .await
46    }
47}