dynamo_async_openai/model.rs
1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use crate::{
12 config::Config,
13 error::OpenAIError,
14 types::{DeleteModelResponse, ListModelResponse, Model},
15 Client,
16};
17
18/// List and describe the various models available in the API.
19/// You can refer to the [Models](https://platform.openai.com/docs/models) documentation to understand what
20/// models are available and the differences between them.
21pub struct Models<'c, C: Config> {
22 client: &'c Client<C>,
23}
24
25impl<'c, C: Config> Models<'c, C> {
26 pub fn new(client: &'c Client<C>) -> Self {
27 Self { client }
28 }
29
30 /// Lists the currently available models, and provides basic information
31 /// about each one such as the owner and availability.
32 #[crate::byot(R = serde::de::DeserializeOwned)]
33 pub async fn list(&self) -> Result<ListModelResponse, OpenAIError> {
34 self.client.get("/models").await
35 }
36
37 /// Retrieves a model instance, providing basic information about the model
38 /// such as the owner and permissioning.
39 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
40 pub async fn retrieve(&self, id: &str) -> Result<Model, OpenAIError> {
41 self.client.get(format!("/models/{id}").as_str()).await
42 }
43
44 /// Delete a fine-tuned model. You must have the Owner role in your organization.
45 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
46 pub async fn delete(&self, model: &str) -> Result<DeleteModelResponse, OpenAIError> {
47 self.client
48 .delete(format!("/models/{model}").as_str())
49 .await
50 }
51}