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