АДРЕСНЫЙ РЕЖИМ - M2.3b тюнинг account-scope и диагностика стадий адресного рантайма
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
import type { AddressModeDetection } from "../types/addressQuery";
|
||||
|
||||
const ADDRESS_ACTION_TOKENS = [
|
||||
"show",
|
||||
"list",
|
||||
"find",
|
||||
"get",
|
||||
"lookup",
|
||||
"open",
|
||||
"balance",
|
||||
"debt",
|
||||
"owe",
|
||||
"покажи",
|
||||
"список",
|
||||
"найди",
|
||||
"выведи",
|
||||
"кто",
|
||||
"кому",
|
||||
"какие",
|
||||
"остаток",
|
||||
"долг",
|
||||
"задолж",
|
||||
"хвост",
|
||||
"незакрыт"
|
||||
];
|
||||
|
||||
const ADDRESS_ENTITY_TOKENS = [
|
||||
"counterparty",
|
||||
"counterparties",
|
||||
"contract",
|
||||
"contracts",
|
||||
"account",
|
||||
"accounts",
|
||||
"document",
|
||||
"documents",
|
||||
"balance",
|
||||
"payable",
|
||||
"payables",
|
||||
"receivable",
|
||||
"receivables",
|
||||
"owe",
|
||||
"owes",
|
||||
"owed",
|
||||
"контрагент",
|
||||
"договор",
|
||||
"счет",
|
||||
"счёт",
|
||||
"документ",
|
||||
"остаток",
|
||||
"дебитор",
|
||||
"кредитор",
|
||||
"аванс",
|
||||
"оплат",
|
||||
"долг",
|
||||
"должен",
|
||||
"должны",
|
||||
"должна"
|
||||
];
|
||||
|
||||
const DEEP_REASONING_TOKENS = [
|
||||
"why",
|
||||
"because",
|
||||
"root cause",
|
||||
"mechanism",
|
||||
"prove",
|
||||
"chain",
|
||||
"почему",
|
||||
"причин",
|
||||
"механизм",
|
||||
"докажи",
|
||||
"цепоч",
|
||||
"разрыв",
|
||||
"ошибк"
|
||||
];
|
||||
|
||||
function hasAnyToken(text: string, tokens: string[]): boolean {
|
||||
return tokens.some((token) => text.includes(token));
|
||||
}
|
||||
|
||||
export function detectAddressQuestionMode(userMessage: string): AddressModeDetection {
|
||||
const text = String(userMessage ?? "").trim().toLowerCase();
|
||||
if (!text) {
|
||||
return {
|
||||
mode: "unsupported",
|
||||
confidence: "low",
|
||||
reasons: ["empty_message"]
|
||||
};
|
||||
}
|
||||
|
||||
const hasAddressAction = hasAnyToken(text, ADDRESS_ACTION_TOKENS);
|
||||
const hasAddressEntity = hasAnyToken(text, ADDRESS_ENTITY_TOKENS);
|
||||
const hasDeepReasoning = hasAnyToken(text, DEEP_REASONING_TOKENS);
|
||||
|
||||
if (hasAddressAction && hasAddressEntity && !hasDeepReasoning) {
|
||||
return {
|
||||
mode: "address_query",
|
||||
confidence: "high",
|
||||
reasons: ["address_action_detected", "address_entity_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasAddressEntity && !hasDeepReasoning) {
|
||||
return {
|
||||
mode: "address_query",
|
||||
confidence: "medium",
|
||||
reasons: ["address_entity_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
if (hasDeepReasoning) {
|
||||
return {
|
||||
mode: "deep_analysis",
|
||||
confidence: "high",
|
||||
reasons: ["deep_reasoning_signal_detected"]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
mode: "unsupported",
|
||||
confidence: "low",
|
||||
reasons: ["no_address_or_deep_signal"]
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user