From 719aef5a7fa5527988b98d63550bf28c85bcb386 Mon Sep 17 00:00:00 2001 From: goddonebianu Date: Mon, 9 Mar 2026 18:14:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(dictionary):=20=E4=BF=AE=E5=A4=8D=E8=AF=AD?= =?UTF-8?q?=E4=B9=89=E6=98=A0=E5=B0=84=E5=92=8C=E9=94=99=E8=AF=AF=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复语义映射:强制将输入转换为查询语言的对应词 - 移除拼写自动纠正,避免错误纠正(如 franch→franchise) - 修复 winston 日志 Error 对象序列化问题 --- src/lib/bigmodel/dictionary/orchestrator.ts | 2 +- .../bigmodel/dictionary/stage1-preprocess.ts | 24 +++++++++---------- .../dictionary/stage4-entriesGeneration.ts | 2 +- src/modules/dictionary/dictionary-action.ts | 2 +- src/modules/dictionary/dictionary-service.ts | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lib/bigmodel/dictionary/orchestrator.ts b/src/lib/bigmodel/dictionary/orchestrator.ts index a5f9cd1..b8a5638 100644 --- a/src/lib/bigmodel/dictionary/orchestrator.ts +++ b/src/lib/bigmodel/dictionary/orchestrator.ts @@ -41,7 +41,7 @@ export async function executeDictionaryLookup( return finalResult; } catch (error) { - log.error("Dictionary lookup failed", { error }); + log.error("Dictionary lookup failed", { error: error instanceof Error ? error.message : String(error) }); const errorMessage = error instanceof Error ? error.message : "未知错误"; throw new LookUpError(errorMessage); } diff --git a/src/lib/bigmodel/dictionary/stage1-preprocess.ts b/src/lib/bigmodel/dictionary/stage1-preprocess.ts index b1211a0..350fa17 100644 --- a/src/lib/bigmodel/dictionary/stage1-preprocess.ts +++ b/src/lib/bigmodel/dictionary/stage1-preprocess.ts @@ -17,23 +17,23 @@ export async function preprocessInput( 任务: 1. 判断输入是否有效(非空、是自然语言) -2. 识别输入语言和类型(单词/短语) -3. 如果输入语言 ≠ 查询语言,判断是否需要语义映射 -4. 生成查询语言下的标准形式 +2. 识别输入类型(单词/短语) +3. 将输入转换为查询语言的对应词(语义映射) +4. 生成标准形式(必须是查询语言) -语义映射规则: -- 只有当输入是"明确、基础、可词典化的语义概念"(如常见动词、名词、形容词)时才映射 -- 复杂句子、专业术语、无法确定语义的词汇不映射,直接用原文 - -标准形式规则: -- 修正拼写错误 -- 还原为词典形式(英语:动词原形/名词单数;日语:辞书形;中文:标准简化字) +重要规则: +- standardForm 必须是查询语言的词汇 +- 例如:查询语言=维吾尔语,输入="japanese" → standardForm="ياپونىيە" +- 例如:查询语言=中文,输入="japanese" → standardForm="日语" +- 例如:查询语言=English,输入="日语" → standardForm="Japanese" +- 如果输入本身就是查询语言,则保持不变 +- 只做词典形式还原,不纠正拼写 返回 JSON: { "isValid": boolean, "inputType": "word" | "phrase", - "standardForm": "标准形式", + "standardForm": "查询语言对应的标准形式", "confidence": "high" | "medium" | "low", "reason": "错误原因,成功时为空字符串" } @@ -81,7 +81,7 @@ export async function preprocessInput( reason: typeof result.reason === "string" ? result.reason : "", }; } catch (error) { - log.error("Preprocess failed", { error }); + log.error("Preprocess failed", { error: error instanceof Error ? error.message : String(error) }); throw error; } } diff --git a/src/lib/bigmodel/dictionary/stage4-entriesGeneration.ts b/src/lib/bigmodel/dictionary/stage4-entriesGeneration.ts index 805cdf0..0519f99 100644 --- a/src/lib/bigmodel/dictionary/stage4-entriesGeneration.ts +++ b/src/lib/bigmodel/dictionary/stage4-entriesGeneration.ts @@ -49,7 +49,7 @@ ${isWord ? `{"entries":[{"ipa":"音标","partOfSpeech":"词性","definition":" return result; } catch (error) { - log.error("Entries generation failed", { error }); + log.error("Entries generation failed", { error: error instanceof Error ? error.message : String(error) }); throw error; } } diff --git a/src/modules/dictionary/dictionary-action.ts b/src/modules/dictionary/dictionary-action.ts index dcf3a9a..7a01c49 100644 --- a/src/modules/dictionary/dictionary-action.ts +++ b/src/modules/dictionary/dictionary-action.ts @@ -21,7 +21,7 @@ export const actionLookUpDictionary = async (dto: ActionInputLookUpDictionary): message: e.message }; } - log.error("Dictionary lookup failed", { error: e }); + log.error("Dictionary lookup failed", { error: e instanceof Error ? e.message : String(e) }); return { success: false, message: 'Unknown error occured.' diff --git a/src/modules/dictionary/dictionary-service.ts b/src/modules/dictionary/dictionary-service.ts index 911130e..1cfe232 100644 --- a/src/modules/dictionary/dictionary-service.ts +++ b/src/modules/dictionary/dictionary-service.ts @@ -42,7 +42,7 @@ export const serviceLookUp = async (dto: ServiceInputLookUp) => { }, response.entries ).catch(error => { - log.error("Failed to save dictionary data", { error }); + log.error("Failed to save dictionary data", { error: error instanceof Error ? error.message : String(error) }); }); return response; @@ -54,7 +54,7 @@ export const serviceLookUp = async (dto: ServiceInputLookUp) => { definitionLang: definitionLang, dictionaryItemId: lastLookUpResult.id }).catch(error => { - log.error("Failed to save dictionary data", { error }); + log.error("Failed to save dictionary data", { error: error instanceof Error ? error.message : String(error) }); }); return { standardForm: lastLookUpResult.standardForm,