feat(transcribe): route dictionary_terms + initial_prompt through active profile

This commit is contained in:
2026-04-19 20:51:41 +01:00
parent c8952df591
commit 6544bcbaa0
2 changed files with 115 additions and 28 deletions

View File

@@ -61,6 +61,10 @@ pub struct StartLiveTranscriptionConfig {
/// Optional explicit microphone device name (from `list_audio_devices`).
/// None or empty string = let `MicrophoneCapture::start` auto-select.
pub microphone_device: Option<String>,
/// Optional profile id. None falls back to `DEFAULT_PROFILE_ID`. Drives
/// the post-processing dictionary via `profile_terms` and, when the
/// request's `initial_prompt` is empty, supplies the Whisper prompt.
pub profile_id: Option<String>,
}
#[derive(Debug, Serialize)]
@@ -131,7 +135,7 @@ struct InferenceTask {
pub async fn start_live_transcription_session(
state: tauri::State<'_, AppState>,
live_state: tauri::State<'_, LiveTranscriptionState>,
config: StartLiveTranscriptionConfig,
mut config: StartLiveTranscriptionConfig,
result_channel: Channel<LiveResultMessage>,
status_channel: Channel<LiveStatusMessage>,
) -> Result<StartLiveTranscriptionResponse, String> {
@@ -142,6 +146,37 @@ pub async fn start_live_transcription_session(
}
}
let resolved_profile_id = config
.profile_id
.clone()
.unwrap_or_else(|| kon_storage::DEFAULT_PROFILE_ID.to_string());
let profile = kon_storage::database::get_profile(&state.db, &resolved_profile_id)
.await
.map_err(|e| e.to_string())?
.ok_or_else(|| format!("Profile {resolved_profile_id} not found"))?;
let profile_terms: Vec<String> =
kon_storage::database::list_profile_terms(&state.db, &resolved_profile_id)
.await
.map_err(|e| e.to_string())?
.into_iter()
.map(|t| t.term)
.collect();
// Collapse the effective initial_prompt on the struct so downstream
// `TranscriptionOptions` construction (see `maybe_dispatch_chunk`) picks
// up profile fallback without further plumbing.
let effective_prompt = match config.initial_prompt.as_deref() {
Some(p) if !p.is_empty() => p.to_string(),
_ => profile.initial_prompt.clone(),
};
config.initial_prompt = if effective_prompt.is_empty() {
None
} else {
Some(effective_prompt)
};
let model_id = config
.model_id
.clone()
@@ -166,13 +201,7 @@ pub async fn start_live_transcription_session(
let worker_status = status_channel.clone();
let worker_results = result_channel.clone();
let dictionary_terms: Vec<String> =
kon_storage::database::list_dictionary(&state.db)
.await
.unwrap_or_default()
.into_iter()
.map(|e| e.term)
.collect();
let dictionary_terms = profile_terms.clone();
let handle = tokio::task::spawn_blocking(move || {
run_live_session(