@onco-foundry/mask-port 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/llm_sensitive_word_finder.d.ts +3 -1
- package/dist/llm_sensitive_word_finder.js +11 -2
- package/dist/masker.d.ts +1 -1
- package/dist/masker.js +1 -0
- package/dist/qwen_agent_masker.d.ts +1 -0
- package/dist/tencent_masker.js +1 -0
- package/dist/textin_masker.js +1 -0
- package/package.json +1 -1
|
@@ -17,6 +17,8 @@ export type LlmSensitiveWordFinderOptions = {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* 创建 LLM 敏感词判定器,直接作为 TextIn 脱敏器的 findSensitiveWords 使用。
|
|
20
|
-
*
|
|
20
|
+
* 模型返回的词若不在端口目标集内、不是原文子串或为空,一律丢弃;
|
|
21
|
+
* 姓名类目标另有一道形态硬校验(不含阿拉伯数字),弱模型把数字/序号幻觉成姓名时在此拦截——
|
|
22
|
+
* 「是原文子串」对数字形同虚设("7" 在全文里到处都是),光靠 substring 校验防不住。
|
|
21
23
|
*/
|
|
22
24
|
export declare const createLlmSensitiveWordFinder: (options: LlmSensitiveWordFinderOptions) => SensitiveWordFinder;
|
|
@@ -17,8 +17,11 @@ const SYSTEM_PROMPT = `你从医疗文书扫描件(病历、检查报告、住
|
|
|
17
17
|
- phone:手机号、联系电话
|
|
18
18
|
- address:住址、联系地址
|
|
19
19
|
- doctor_signature:医生姓名(签名处或「医师:」标签后的)
|
|
20
|
+
- medical_record_number:医院内部编号(住院号、病案号、病理号、门诊号等,「××号:」标签后的数字或数字字母组合)
|
|
20
21
|
|
|
21
22
|
要求:
|
|
23
|
+
- 姓名类(patient_name、doctor_signature)只能是中文姓名,绝不包含阿拉伯数字;数字、序号、编号都不是姓名。
|
|
24
|
+
- 编号类(medical_record_number)只提取「××号:」标签后的值;日期、年龄、时间、尺寸测量值、检查分类号(如 BI-RADS 4C)不是编号,不要提取。
|
|
22
25
|
- 只输出原文中逐字出现的字符串,不改写、不概括、不补全。
|
|
23
26
|
- 医院名、科室名、病名、药名不是隐私,不要提取。
|
|
24
27
|
- 没有可提取的内容就输出空数组。
|
|
@@ -27,6 +30,8 @@ const extractedSchema = z.array(z.object({
|
|
|
27
30
|
text: z.string(),
|
|
28
31
|
target: z.string(),
|
|
29
32
|
}));
|
|
33
|
+
/** 姓名类目标:形态校验只拦阿拉伯数字(单字符中文名是合法情形,不拦)。 */
|
|
34
|
+
const NAME_TARGETS = new Set(['patient_name', 'doctor_signature']);
|
|
30
35
|
const modelResponseSchema = z.object({
|
|
31
36
|
content: z.array(z.object({
|
|
32
37
|
type: z.string(),
|
|
@@ -51,7 +56,9 @@ const extractJsonArray = (content) => {
|
|
|
51
56
|
};
|
|
52
57
|
/**
|
|
53
58
|
* 创建 LLM 敏感词判定器,直接作为 TextIn 脱敏器的 findSensitiveWords 使用。
|
|
54
|
-
*
|
|
59
|
+
* 模型返回的词若不在端口目标集内、不是原文子串或为空,一律丢弃;
|
|
60
|
+
* 姓名类目标另有一道形态硬校验(不含阿拉伯数字),弱模型把数字/序号幻觉成姓名时在此拦截——
|
|
61
|
+
* 「是原文子串」对数字形同虚设("7" 在全文里到处都是),光靠 substring 校验防不住。
|
|
55
62
|
*/
|
|
56
63
|
export const createLlmSensitiveWordFinder = (options) => {
|
|
57
64
|
const credentials = z.object({
|
|
@@ -114,7 +121,9 @@ export const createLlmSensitiveWordFinder = (options) => {
|
|
|
114
121
|
continue;
|
|
115
122
|
if (!MASK_TARGETS.includes(item.target))
|
|
116
123
|
continue;
|
|
117
|
-
|
|
124
|
+
if (NAME_TARGETS.has(item.target) && /\d/u.test(word))
|
|
125
|
+
continue;
|
|
126
|
+
const key = `${item.target}:${word}`;
|
|
118
127
|
if (seen.has(key))
|
|
119
128
|
continue;
|
|
120
129
|
seen.add(key);
|
package/dist/masker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** 脱敏目标类别。 */
|
|
2
|
-
export declare const MASK_TARGETS: readonly ['patient_name', 'id_number', 'phone', 'address', 'doctor_signature'];
|
|
2
|
+
export declare const MASK_TARGETS: readonly ['patient_name', 'id_number', 'phone', 'address', 'doctor_signature', 'medical_record_number'];
|
|
3
3
|
export type MaskTarget = (typeof MASK_TARGETS)[number];
|
|
4
4
|
export type MaskRequest = {
|
|
5
5
|
/** 待脱敏的图片字节。 */
|
package/dist/masker.js
CHANGED
package/dist/tencent_masker.js
CHANGED
package/dist/textin_masker.js
CHANGED