Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions openless-all/app/src-tauri/src/coordinator/dictation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,50 @@ mod tests {
false,
PolishMode::Light,
false,
crate::types::ChineseScriptPreference::Auto,
));
}

// issue #622:非 Auto 字形偏好必须关闭流式,改走会做字形转换的一次性路径。
#[test]
fn streaming_insert_ineligible_when_chinese_script_forced() {
for pref in [
crate::types::ChineseScriptPreference::Traditional,
crate::types::ChineseScriptPreference::Simplified,
] {
assert!(!streaming_insert_eligible(
true,
false,
PolishMode::Light,
false,
pref,
));
}
}

// issue #622:非 Auto + 成功 LLM 润色(非流式、无 error)时,最终插入文字
// 必须套用字形转换,不能只靠 prompt 指示。覆盖 issue 给出的两个验收用例。
#[test]
fn finalize_forces_traditional_even_on_successful_polish() {
let cases = [
("你知道你今天想要做什么吗?", "你知道你今天想要做什麼嗎?"),
("所以你已经考过了吗?", "所以你已經考過了嗎?"),
];
for (input, expected) in cases {
let out = finalize_polished_text(
input.to_string(),
false, // translation_active
true, // raw_uses_llm
PolishMode::Light, // 成功润色路径(非 Raw、非 error)
&None, // 无 polish_error
crate::types::ChineseScriptPreference::Traditional,
&[], // 无 correction rules
false, // already_streamed
);
assert_eq!(out, expected);
}
}

#[test]
fn batch_asr_chunk_limit_applies_only_to_zhipu() {
assert_eq!(batch_asr_chunk_limit_ms("zhipu"), Some(30_000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ pub(crate) async fn end_session(inner: &Arc<Inner>) -> Result<(), String> {
translation_active,
mode,
raw_uses_llm,
chinese_script_preference,
);
log::info!(
"[coord] polish dispatch: translation={translation_active} mode={mode:?} streaming_eligible={streaming_eligible}"
Expand Down
30 changes: 16 additions & 14 deletions openless-all/app/src-tauri/src/coordinator/dictation_streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,23 @@ where

pub(crate) fn finalize_polished_text(
polished: String,
translation_active: bool,
_translation_active: bool,
_raw_uses_llm: bool,
mode: PolishMode,
polish_error: &Option<String>,
_mode: PolishMode,
_polish_error: &Option<String>,
chinese_script_preference: crate::types::ChineseScriptPreference,
correction_rules: &[crate::types::CorrectionRule],
already_streamed: bool,
) -> String {
if already_streamed {
return polished;
}
let should_force_script = if translation_active {
polish_error.is_some()
} else {
mode == PolishMode::Raw || polish_error.is_some()
};
let polished = if should_force_script {
apply_chinese_script_preference(&polished, chinese_script_preference)
} else {
polished
};
// issue #622:无论是否经 LLM 润色成功,插入前都套用中文字形转换。
// apply_chinese_script_preference 对 Auto 是 no-op;非 Auto 时确保最终插入文字
// 不混简体——此前仅 Raw / 翻译 / 润色失败时强制转换,成功润色只靠 prompt 指示,
// 而部分 provider 会跟随简体 ASR 输入继续输出简体(流式路径已在上游回退为一次性,
// 见 streaming_insert_eligible)。
let polished = apply_chinese_script_preference(&polished, chinese_script_preference);
if correction_rules.is_empty() {
polished
} else {
Expand All @@ -386,8 +382,14 @@ pub(crate) fn streaming_insert_eligible(
translation_active: bool,
mode: PolishMode,
raw_uses_llm: bool,
chinese_script_preference: crate::types::ChineseScriptPreference,
) -> bool {
streaming_insert_enabled && !translation_active && (mode != PolishMode::Raw || raw_uses_llm)
streaming_insert_enabled
&& !translation_active
&& (mode != PolishMode::Raw || raw_uses_llm)
// issue #622:非 Auto 字形偏好需在插入前整体转换;流式逐字落字无法回退,
// 故关闭流式、走一次性路径(由 finalize_polished_text 套用字形转换)。
&& chinese_script_preference == crate::types::ChineseScriptPreference::Auto
}

pub(crate) fn default_done_message(status: InsertStatus, polish_failed: bool) -> Option<String> {
Expand Down
Loading