| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { writeFileSync } from 'node:fs';
- import { dirname, join } from 'node:path';
- import { fileURLToPath } from 'node:url';
- const scriptDir = dirname(fileURLToPath(import.meta.url));
- const deep = join(scriptDir, '../src/main/java/com/fs/company/service/workflow/deepdialogue');
- function u(s) {
- return s.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
- }
- function writeUtf8(path, content) {
- writeFileSync(path, content.replace(/\r\n/g, '\n'), 'utf8');
- }
- writeUtf8(
- join(deep, 'UniversalSemanticDecomposition.java'),
- u(`package com.fs.company.service.workflow.deepdialogue;
- import java.util.EnumMap;
- import java.util.Map;
- /**
- * \u4e09\u5c42\u8bed\u4e49\u62c6\u89e3\u7ed3\u679c\u3002
- */
- public class UniversalSemanticDecomposition {
- private SurfaceQuestionType surfaceQuestionType = SurfaceQuestionType.OTHER;
- private String explicitQuestion;
- private String implicitSignal;
- private String latentNeed;
- private boolean shouldPauseProbing;
- private String pauseReason;
- private final Map<DeepDialogueDimension, String> dimensionUpdates = new EnumMap<>(DeepDialogueDimension.class);
- public SurfaceQuestionType getSurfaceQuestionType() { return surfaceQuestionType; }
- public void setSurfaceQuestionType(SurfaceQuestionType surfaceQuestionType) {
- this.surfaceQuestionType = surfaceQuestionType != null ? surfaceQuestionType : SurfaceQuestionType.OTHER;
- }
- public String getExplicitQuestion() { return explicitQuestion; }
- public void setExplicitQuestion(String explicitQuestion) { this.explicitQuestion = explicitQuestion; }
- public String getImplicitSignal() { return implicitSignal; }
- public void setImplicitSignal(String implicitSignal) { this.implicitSignal = implicitSignal; }
- public String getLatentNeed() { return latentNeed; }
- public void setLatentNeed(String latentNeed) { this.latentNeed = latentNeed; }
- public boolean isShouldPauseProbing() { return shouldPauseProbing; }
- public void setShouldPauseProbing(boolean shouldPauseProbing) { this.shouldPauseProbing = shouldPauseProbing; }
- public String getPauseReason() { return pauseReason; }
- public void setPauseReason(String pauseReason) { this.pauseReason = pauseReason; }
- public Map<DeepDialogueDimension, String> getDimensionUpdates() { return dimensionUpdates; }
- }
- `)
- );
- writeUtf8(
- join(deep, 'MedicalEfficacyDialoguePolicy.java'),
- u(`package com.fs.company.service.workflow.deepdialogue;
- import java.util.regex.Pattern;
- /**
- * Medical efficacy consultations should be answered via UDD (compliant reply + probing),
- * not semantic handoff to human.
- */
- public final class MedicalEfficacyDialoguePolicy {
- private static final Pattern MEDICAL_EFFICACY = Pattern.compile(
- "\u6cbb\u7597|\u7597\u6548|\u80fd\u5426\u6cbb|\u80fd\u4e0d\u80fd\u6cbb|\u53ef\u4ee5\u6cbb|\u80fd\u6cbb|\u6709\u7528\u5417|\u6709\u6548\u5417|\u6709\u4f5c\u7528|\u80fd\u5426|\u80fd\u4e0d\u80fd"
- + "|\u7cd6\u5c3f\u75c5|\u9ad8\u8840\u538b|\u8840\u538b|\u8840\u7cd6|\u75c7\u72b6|\u836f\u7269|\u7528\u836f|\u670d\u836f|\u533b\u751f|\u533b\u9662|\u5c31\u8bca|\u5065\u5eb7|\u517b\u751f|\u996e\u98df|\u80fd\u5403|\u80fd\u4e0d\u80fd\u5403");
- /** \u6295\u8bc9 / \u6cd5\u52a1 / \u7d27\u6025\u573a\u666f\uff1a\u4ecd\u5e94\u8f6c\u4eba\u5de5\uff0c\u5373\u4fbf\u8bdd\u9898\u6d89\u53ca\u533b\u7597\u3002 */
- private static final Pattern FORCE_HANDOFF = Pattern.compile(
- "\u6295\u8bc9|\u9000\u6b3e|\u62a5\u544a|\u66dd\u5149|12315|\u5f8b\u5e08|\u62a5\u8b66|\u8d77\u8bc9|\u6025\u6551|\u7d27\u6025|\u547d\u5371|\u660f\u8ff7|\u81f4\u547d");
- public static final String RENDER_COMPLIANCE_HINT =
- "\u3010\u533b\u7597\u5408\u89c4\u3011\u4e0d\u5f97\u8bca\u65ad\u6216\u5f00\u5904\u65b9\uff0c\u4e0d\u627f\u8bfa\u6cbb\u6108\u3002"
- + "\u53ef\u7ed9\u51fa\u666e\u901a\u5065\u5eb7/\u996e\u98df\u79d1\u666e\u4fe1\u606f\uff0c\u5e76\u8bf4\u660e\u4e0d\u80fd\u66ff\u4ee3\u836f\u7269\u4e0e\u533b\u751f\u6cbb\u7597\u3002"
- + "\u5982\u75c7\u72b6\u660e\u663e\u6216\u6301\u7eed\u6076\u5316\uff0c\u5efa\u8bae\u53ca\u65f6\u5c31\u533b\u3002";
- private MedicalEfficacyDialoguePolicy() {
- }
- public static boolean isMedicalIndustry(String industryType) {
- if (industryType == null || industryType.isBlank()) {
- return false;
- }
- String t = industryType.trim().toLowerCase();
- return "medical".equals(t) || "health".equals(t) || "tcm".equals(t);
- }
- public static boolean isMedicalEfficacyConsultation(String message) {
- return message != null && !message.isBlank() && MEDICAL_EFFICACY.matcher(message.trim()).find();
- }
- public static boolean requiresForcedHandoff(String message) {
- return message != null && FORCE_HANDOFF.matcher(message).find();
- }
- /**
- * @return true when handoff should be deferred so UDD can answer + probe
- */
- public static boolean shouldAnswerViaUdd(String industryType, String message) {
- if (message == null || message.isBlank() || requiresForcedHandoff(message)) {
- return false;
- }
- if (!isMedicalEfficacyConsultation(message)) {
- return false;
- }
- return isMedicalIndustry(industryType) || isMedicalEfficacyConsultation(message);
- }
- /** Use medical corpus/compliance when industry is medical or message is medical efficacy. */
- public static String resolveEffectiveIndustry(String industryType, String message) {
- if (isMedicalIndustry(industryType)) {
- return industryType.trim();
- }
- if (isMedicalEfficacyConsultation(message)) {
- return "medical";
- }
- return industryType;
- }
- }
- `)
- );
- console.log('fixed UniversalSemanticDecomposition.java and MedicalEfficacyDialoguePolicy.java');
|