rusty_openai/openai_api/client.rs
1use crate::{error_handling::OpenAIResult, openai::OpenAI};
2use serde_json::Value;
3
4/// [`ClientApi`] struct to interact with the models endpoint of the API.
5pub struct ClientApi<'a>(pub(crate) &'a OpenAI<'a>);
6
7impl<'a> ClientApi<'a> {
8 /// Fetch the list of available models from the API.
9 ///
10 /// # Returns
11 ///
12 /// A Result containing the JSON response as [`serde_json::Value`] on success, or an [`OpenAIError`][crate::error_handling::OpenAIError] on failure.
13 pub async fn get_models(&self) -> OpenAIResult<Value> {
14 // Send a GET request to the models endpoint.
15 self.0.get("/models").await
16 }
17}