Skip to main content

openai_compat/resources/
models.rs

1//! `/models` resource, mirroring `resources/models.py`.
2
3use reqwest::Method;
4
5use crate::client::Client;
6use crate::error::OpenAIError;
7use crate::pagination::List;
8use crate::request::RequestOptions;
9use crate::types::models::{Deleted, Model};
10
11/// The models resource.
12#[derive(Debug, Clone)]
13pub struct Models {
14    client: Client,
15}
16
17impl Models {
18    pub(crate) fn new(client: Client) -> Self {
19        Self { client }
20    }
21
22    /// List the currently available models.
23    pub async fn list(&self) -> Result<List<Model>, OpenAIError> {
24        self.client
25            .execute(Method::GET, "/models", RequestOptions::default())
26            .await
27    }
28
29    /// Retrieve a model by id.
30    pub async fn retrieve(&self, model: &str) -> Result<Model, OpenAIError> {
31        self.client
32            .execute(
33                Method::GET,
34                &format!("/models/{model}"),
35                RequestOptions::default(),
36            )
37            .await
38    }
39
40    /// Delete a fine-tuned model. Requires owner permissions.
41    pub async fn delete(&self, model: &str) -> Result<Deleted, OpenAIError> {
42        self.client
43            .execute(
44                Method::DELETE,
45                &format!("/models/{model}"),
46                RequestOptions::default(),
47            )
48            .await
49    }
50}