use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use crate::error::Result;
use crate::shared::{FileBytes, Headers, ProviderMetadata, ProviderOptions, RequestInfo, Warning};
#[async_trait]
pub trait TranscriptionModel: Send + Sync + std::fmt::Debug {
fn provider(&self) -> &str;
fn model_id(&self) -> &str;
fn specification_version(&self) -> &'static str {
"v4"
}
async fn do_generate(&self, options: TranscriptionOptions) -> Result<TranscriptionResult>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TranscriptionOptions {
pub audio: FileBytes,
#[serde(rename = "mediaType")]
pub media_type: String,
#[serde(
default,
rename = "providerOptions",
skip_serializing_if = "Option::is_none"
)]
pub provider_options: Option<ProviderOptions>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub headers: Option<Headers>,
}
#[derive(Debug, Clone)]
pub struct TranscriptionResult {
pub text: String,
pub segments: Vec<TranscriptionSegment>,
pub language: Option<String>,
pub duration_in_seconds: Option<f64>,
pub warnings: Vec<Warning>,
pub request: Option<RequestInfo>,
pub response: TranscriptionResponseInfo,
pub provider_metadata: Option<ProviderMetadata>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TranscriptionSegment {
pub text: String,
#[serde(rename = "startSecond")]
pub start_second: f64,
#[serde(rename = "endSecond")]
pub end_second: f64,
}
#[derive(Debug, Clone)]
pub struct TranscriptionResponseInfo {
pub timestamp: String,
pub model_id: String,
pub headers: Option<Headers>,
pub body: Option<serde_json::Value>,
}