Skip to main content

transcribe_cpp_types/
model.rs

1//! Model- and session-level plain data: [`Capabilities`], [`SessionOptions`]
2//! and [`SessionLimits`].
3
4use crate::types::{KvType, TimestampKind};
5
6/// Immutable, model-level capabilities read from GGUF metadata.
7#[derive(Debug, Clone, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct Capabilities {
10    pub native_sample_rate: i32,
11    /// Supported language codes (empty if the model is language-agnostic).
12    pub languages: Vec<String>,
13    /// Supported translation target language codes (empty if not advertised).
14    pub translate_target_languages: Vec<String>,
15    /// The finest timestamp granularity the model can produce.
16    pub max_timestamp_kind: TimestampKind,
17    pub supports_language_detect: bool,
18    pub supports_translate: bool,
19    pub supports_streaming: bool,
20    pub supports_spec_decode: bool,
21    /// Longest accepted audio in ms (0 = no practical limit).
22    pub max_audio_ms: i64,
23}
24
25/// Options for creating a session.
26#[derive(Debug, Clone, PartialEq, Eq)]
27#[cfg_attr(
28    feature = "serde",
29    derive(serde::Serialize, serde::Deserialize),
30    serde(default)
31)]
32pub struct SessionOptions {
33    /// CPU threads for ops that run on CPU; 0 = library default.
34    pub n_threads: i32,
35    /// K/V activation precision.
36    pub kv_type: KvType,
37    /// Optional decoder context cap in tokens; 0 = model maximum.
38    pub n_ctx: i32,
39}
40
41impl Default for SessionOptions {
42    fn default() -> Self {
43        SessionOptions {
44            n_threads: 0,
45            kv_type: KvType::Auto,
46            n_ctx: 0,
47        }
48    }
49}
50
51/// Per-session effective limits.
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
54pub struct SessionLimits {
55    /// Decoder context cap in force for this session (0 = unbounded family).
56    pub effective_n_ctx: i32,
57    /// Longest accepted audio in ms (0 = no practical limit).
58    pub effective_max_audio_ms: i64,
59    /// Worst-case decoder KV bytes for one utterance (0 = no decoder KV).
60    pub max_kv_bytes: i64,
61}