rig/client/
audio_generation.rs

1#[cfg(feature = "audio")]
2mod audio {
3    #[allow(deprecated)]
4    use crate::audio_generation::AudioGenerationModelDyn;
5    use crate::audio_generation::{
6        AudioGenerationError, AudioGenerationModel, AudioGenerationRequest, AudioGenerationResponse,
7    };
8    use crate::client::Nothing;
9    use std::future::Future;
10    use std::sync::Arc;
11
12    /// A provider client with audio generation capabilities.
13    /// Clone is required for conversions between client types.
14    pub trait AudioGenerationClient {
15        /// The AudioGenerationModel used by the Client
16        type AudioGenerationModel: AudioGenerationModel<Client = Self>;
17
18        /// Create an audio generation model with the given name.
19        ///
20        /// # Example
21        /// ```
22        /// use rig::providers::openai::{Client, self};
23        ///
24        /// // Initialize the OpenAI client
25        /// let openai = Client::new("your-open-ai-api-key");
26        ///
27        /// let tts = openai.audio_generation_model(openai::TTS_1);
28        /// ```
29        fn audio_generation_model(&self, model: impl Into<String>) -> Self::AudioGenerationModel {
30            Self::AudioGenerationModel::make(self, model)
31        }
32    }
33
34    #[allow(deprecated)]
35    #[deprecated(
36        since = "0.25.0",
37        note = "`DynClientBuilder` and related features have been deprecated and will be removed in a future release. In this case, use `ImageGenerationModel` instead."
38    )]
39    pub trait AudioGenerationClientDyn {
40        fn audio_generation_model<'a>(&self, model: &str) -> Box<dyn AudioGenerationModelDyn + 'a>;
41    }
42
43    #[allow(deprecated)]
44    impl<T, M> AudioGenerationClientDyn for T
45    where
46        T: AudioGenerationClient<AudioGenerationModel = M>,
47        M: AudioGenerationModel + 'static,
48    {
49        fn audio_generation_model<'a>(&self, model: &str) -> Box<dyn AudioGenerationModelDyn + 'a> {
50            Box::new(self.audio_generation_model(model))
51        }
52    }
53
54    #[deprecated(
55        since = "0.25.0",
56        note = "`DynClientBuilder` and related features have been deprecated and will be removed in a future release. In this case, use `ImageGenerationModel` instead."
57    )]
58    /// Wraps a AudioGenerationModel in a dyn-compatible way for AudioGenerationRequestBuilder.
59    #[derive(Clone)]
60    pub struct AudioGenerationModelHandle<'a> {
61        #[allow(deprecated)]
62        pub(crate) inner: Arc<dyn AudioGenerationModelDyn + 'a>,
63    }
64
65    #[allow(deprecated)]
66    impl AudioGenerationModel for AudioGenerationModelHandle<'_> {
67        type Response = ();
68        type Client = Nothing;
69
70        /// **PANICS**: DynClientBuilder and related features (like this model handle) are being phased out,
71        /// during this transition period some methods will panic when called
72        fn make(_: &Self::Client, _: impl Into<String>) -> Self {
73            panic!(
74                "Function should be unreachable as Self can only be constructed from another 'AudioGenerationModel'"
75            )
76        }
77
78        fn audio_generation(
79            &self,
80            request: AudioGenerationRequest,
81        ) -> impl Future<
82            Output = Result<AudioGenerationResponse<Self::Response>, AudioGenerationError>,
83        > + Send {
84            self.inner.audio_generation(request)
85        }
86    }
87}
88
89#[cfg(feature = "audio")]
90pub use audio::*;