Skip to main content

outfox_openai/
model.rs

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