feat(ai-formatting): wire dictionary_terms through PostProcessOptions to LLM prompt suffix

This commit is contained in:
2026-04-18 09:25:28 +01:00
parent 1e30bb77d4
commit 8c1bec98ca
3 changed files with 56 additions and 0 deletions

View File

@@ -166,11 +166,20 @@ 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 handle = tokio::task::spawn_blocking(move || {
run_live_session(
session_id,
engine,
config,
dictionary_terms,
worker_results,
worker_status,
worker_stop,
@@ -250,6 +259,7 @@ fn run_live_session(
session_id: u64,
engine: Arc<LocalEngine>,
config: StartLiveTranscriptionConfig,
dictionary_terms: Vec<String>,
result_channel: Channel<LiveResultMessage>,
status_channel: Channel<LiveStatusMessage>,
stop_flag: Arc<AtomicBool>,
@@ -284,6 +294,7 @@ fn run_live_session(
&mut inflight,
session_id,
&config,
&dictionary_terms,
&result_channel,
&status_channel,
)? {}
@@ -386,6 +397,7 @@ fn run_live_session(
&mut inflight,
session_id,
&config,
&dictionary_terms,
&result_channel,
&status_channel,
)?;
@@ -512,6 +524,7 @@ fn poll_inference(
inflight: &mut Option<InferenceTask>,
session_id: u64,
config: &StartLiveTranscriptionConfig,
dictionary_terms: &[String],
result_channel: &Channel<LiveResultMessage>,
status_channel: &Channel<LiveStatusMessage>,
) -> Result<Option<bool>, String> {
@@ -531,6 +544,7 @@ fn poll_inference(
british_english: config.british_english,
anti_hallucination: config.anti_hallucination,
format_mode: FormatMode::parse(&config.format_mode),
dictionary_terms: dictionary_terms.to_vec(),
},
);
let segment_count = segments.len();

View File

@@ -50,6 +50,13 @@ pub async fn transcribe_pcm(
.await
.map_err(|e| e.to_string())??;
let dictionary_terms: Vec<String> = kon_storage::database::list_dictionary(&state.db)
.await
.unwrap_or_default()
.into_iter()
.map(|e| e.term)
.collect();
let mut segments: Vec<Segment> = timed.transcript.segments().to_vec();
post_process_segments(
&mut segments,
@@ -58,6 +65,7 @@ pub async fn transcribe_pcm(
british_english,
anti_hallucination,
format_mode: FormatMode::parse(&format_mode),
dictionary_terms,
},
);
@@ -114,6 +122,13 @@ pub async fn transcribe_file(
.await
.map_err(|e| e.to_string())??;
let dictionary_terms: Vec<String> = kon_storage::database::list_dictionary(&state.db)
.await
.unwrap_or_default()
.into_iter()
.map(|e| e.term)
.collect();
let mut segments: Vec<Segment> = timed.transcript.segments().to_vec();
post_process_segments(
&mut segments,
@@ -122,6 +137,7 @@ pub async fn transcribe_file(
british_english,
anti_hallucination,
format_mode: FormatMode::parse(&format_mode),
dictionary_terms,
},
);
@@ -157,6 +173,13 @@ pub async fn transcribe_pcm_parakeet(
.await
.map_err(|e| e.to_string())??;
let dictionary_terms: Vec<String> = kon_storage::database::list_dictionary(&state.db)
.await
.unwrap_or_default()
.into_iter()
.map(|e| e.term)
.collect();
let mut segments: Vec<Segment> = timed.transcript.segments().to_vec();
post_process_segments(
&mut segments,
@@ -165,6 +188,7 @@ pub async fn transcribe_pcm_parakeet(
british_english,
anti_hallucination,
format_mode: FormatMode::parse(&format_mode),
dictionary_terms,
},
);