1use crate::config::Config;
2use crate::error::OpenAIError;
3use crate::spec::{DeleteModelResponse, ListModelResponse, Model};
4use crate::{Client, RequestOptions};
5
6pub 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 #[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 #[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 #[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}