|
| 1 | +//! List and look up Deepgram models, both public and project-scoped. |
| 2 | +//! |
| 3 | +//! See the [Deepgram API Reference][api] for more info. |
| 4 | +//! |
| 5 | +//! [api]: https://developers.deepgram.com/reference/manage-api/get-models |
| 6 | +
|
| 7 | +use crate::{ |
| 8 | + manage::models::response::{ListModelsResponse, ModelInfo}, |
| 9 | + send_and_translate_response, Deepgram, |
| 10 | +}; |
| 11 | + |
| 12 | +pub mod list_options; |
| 13 | +pub mod response; |
| 14 | + |
| 15 | +/// Sub-client for the model-listing endpoints. Constructed via |
| 16 | +/// [`Deepgram::models`]. |
| 17 | +#[derive(Debug, Clone)] |
| 18 | +pub struct Models<'a>(&'a Deepgram); |
| 19 | + |
| 20 | +impl Deepgram { |
| 21 | + /// Construct a new [`Models`] sub-client. |
| 22 | + pub fn models(&self) -> Models<'_> { |
| 23 | + self.into() |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +impl<'a> From<&'a Deepgram> for Models<'a> { |
| 28 | + fn from(deepgram: &'a Deepgram) -> Self { |
| 29 | + Self(deepgram) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +impl Models<'_> { |
| 34 | + /// `GET /v1/models` — metadata for all latest public models. |
| 35 | + /// |
| 36 | + /// To list project-scoped (including non-public) models, use |
| 37 | + /// [`Models::list_for_project`]. |
| 38 | + pub async fn list(&self, options: &list_options::Options) -> crate::Result<ListModelsResponse> { |
| 39 | + let url = "https://api.deepgram.com/v1/models"; |
| 40 | + let mut request = self.0.client.get(url); |
| 41 | + let pairs = options.query_pairs(); |
| 42 | + if !pairs.is_empty() { |
| 43 | + request = request.query(&pairs); |
| 44 | + } |
| 45 | + send_and_translate_response(request).await |
| 46 | + } |
| 47 | + |
| 48 | + /// `GET /v1/models/{model_id}` — metadata for one public model. |
| 49 | + pub async fn get(&self, model_id: &str) -> crate::Result<ModelInfo> { |
| 50 | + let url = format!("https://api.deepgram.com/v1/models/{model_id}"); |
| 51 | + send_and_translate_response(self.0.client.get(url)).await |
| 52 | + } |
| 53 | + |
| 54 | + /// `GET /v1/projects/{project_id}/models` — metadata for all |
| 55 | + /// models the project has access to, including non-public ones. |
| 56 | + pub async fn list_for_project( |
| 57 | + &self, |
| 58 | + project_id: &str, |
| 59 | + options: &list_options::Options, |
| 60 | + ) -> crate::Result<ListModelsResponse> { |
| 61 | + let url = format!("https://api.deepgram.com/v1/projects/{project_id}/models"); |
| 62 | + let mut request = self.0.client.get(url); |
| 63 | + let pairs = options.query_pairs(); |
| 64 | + if !pairs.is_empty() { |
| 65 | + request = request.query(&pairs); |
| 66 | + } |
| 67 | + send_and_translate_response(request).await |
| 68 | + } |
| 69 | + |
| 70 | + /// `GET /v1/projects/{project_id}/models/{model_id}` — metadata |
| 71 | + /// for a single project-scoped model. |
| 72 | + pub async fn get_for_project( |
| 73 | + &self, |
| 74 | + project_id: &str, |
| 75 | + model_id: &str, |
| 76 | + ) -> crate::Result<ModelInfo> { |
| 77 | + let url = format!("https://api.deepgram.com/v1/projects/{project_id}/models/{model_id}"); |
| 78 | + send_and_translate_response(self.0.client.get(url)).await |
| 79 | + } |
| 80 | +} |
0 commit comments