rig/client/
transcription.rs

1#[allow(deprecated)]
2use crate::transcription::TranscriptionModelDyn;
3use crate::transcription::{
4    TranscriptionError, TranscriptionModel, TranscriptionRequest, TranscriptionResponse,
5};
6use std::sync::Arc;
7
8/// A provider client with transcription capabilities.
9/// Clone is required for conversions between client types.
10pub trait TranscriptionClient {
11    /// The type of TranscriptionModel used by the Client
12    type TranscriptionModel: TranscriptionModel;
13
14    /// Create a transcription model with the given name.
15    ///
16    /// # Example with OpenAI
17    /// ```
18    /// use rig::prelude::*;
19    /// use rig::providers::openai::{Client, self};
20    ///
21    /// // Initialize the OpenAI client
22    /// let openai = Client::new("your-open-ai-api-key");
23    ///
24    /// let whisper = openai.transcription_model(openai::WHISPER_1);
25    /// ```
26    fn transcription_model(&self, model: impl Into<String>) -> Self::TranscriptionModel;
27}
28
29#[allow(deprecated)]
30#[deprecated(
31    since = "0.25.0",
32    note = "`DynClientBuilder` and related features have been deprecated and will be removed in a future release. In this case, use `TranscriptionClient` instead."
33)]
34pub trait TranscriptionClientDyn {
35    /// Create a transcription model with the given name.
36    fn transcription_model<'a>(&self, model: &str) -> Box<dyn TranscriptionModelDyn + 'a>;
37}
38
39#[allow(deprecated)]
40impl<M, T> TranscriptionClientDyn for T
41where
42    T: TranscriptionClient<TranscriptionModel = M>,
43    M: TranscriptionModel + 'static,
44{
45    fn transcription_model<'a>(&self, model: &str) -> Box<dyn TranscriptionModelDyn + 'a> {
46        Box::new(self.transcription_model(model))
47    }
48}
49
50#[allow(deprecated)]
51#[deprecated(
52    since = "0.25.0",
53    note = "`DynClientBuilder` and related features have been deprecated and will be removed in a future release."
54)]
55/// Wraps a TranscriptionModel in a dyn-compatible way for TranscriptionRequestBuilder.
56#[derive(Clone)]
57pub struct TranscriptionModelHandle<'a> {
58    pub inner: Arc<dyn TranscriptionModelDyn + 'a>,
59}
60
61#[allow(deprecated)]
62impl TranscriptionModel for TranscriptionModelHandle<'_> {
63    type Response = ();
64    type Client = ();
65
66    /// **PANICS**: We are deprecating DynClientBuilder and related functionality, during this
67    /// transition some methods will be invalid, like this one
68    fn make(_: &Self::Client, _: impl Into<String>) -> Self {
69        panic!(
70            "Invalid method: Cannot make a TranscriptionModelHandle from a client + model identifier"
71        )
72    }
73
74    async fn transcription(
75        &self,
76        request: TranscriptionRequest,
77    ) -> Result<TranscriptionResponse<Self::Response>, TranscriptionError> {
78        self.inner.transcription(request).await
79    }
80}