ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.12.23: декомпозиция deep-turn пайплайна ассистента в runtime-адаптеры
This commit is contained in:
@@ -264,6 +264,32 @@ function parseRawQuestions(rawQuestions: string): string[] {
|
||||
return byLine.length > 0 ? byLine : [text];
|
||||
}
|
||||
|
||||
function normalizeAnalysisDate(value: unknown): string | null {
|
||||
if (typeof value !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
const match = trimmed.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const year = Number(match[1]);
|
||||
const month = Number(match[2]);
|
||||
const day = Number(match[3]);
|
||||
if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day)) {
|
||||
return null;
|
||||
}
|
||||
const candidate = new Date(Date.UTC(year, month - 1, day));
|
||||
if (
|
||||
candidate.getUTCFullYear() !== year ||
|
||||
candidate.getUTCMonth() + 1 !== month ||
|
||||
candidate.getUTCDate() !== day
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return `${match[1]}-${match[2]}-${match[3]}`;
|
||||
}
|
||||
|
||||
type V2FamilyFragment =
|
||||
| NormalizedQueryV2["fragments"][number]
|
||||
| NormalizedQueryV2_0_1["fragments"][number]
|
||||
@@ -936,6 +962,7 @@ export class EvalService {
|
||||
mode: EvalRunMode;
|
||||
caseSetFile?: string;
|
||||
rawQuestions?: string;
|
||||
analysisDate?: string;
|
||||
cases: EvalInputCase[];
|
||||
}): Promise<Record<string, unknown>> {
|
||||
const runId = `eval-${nanoid(10)}`;
|
||||
@@ -976,6 +1003,13 @@ export class EvalService {
|
||||
...payload.normalizeConfig,
|
||||
userQuestion: item.raw_question,
|
||||
context: {
|
||||
period_hint: payload.analysisDate ?? undefined,
|
||||
analysis_context: payload.analysisDate
|
||||
? {
|
||||
as_of_date: payload.analysisDate,
|
||||
source: "eval_analysis_date"
|
||||
}
|
||||
: undefined,
|
||||
eval_label: runId,
|
||||
case_id: item.case_id,
|
||||
eval_mode: payload.mode
|
||||
@@ -1876,6 +1910,7 @@ export class EvalService {
|
||||
mode: EvalRunMode;
|
||||
caseSetFile?: string;
|
||||
compareWithReportFile?: string;
|
||||
analysisDate?: string;
|
||||
runId?: string;
|
||||
}): Promise<Record<string, unknown>> {
|
||||
if (!FEATURE_ASSISTANT_ACCOUNTANT_EVAL_V1) {
|
||||
@@ -1889,6 +1924,7 @@ export class EvalService {
|
||||
const suite = parseAssistantSuiteFile(payload.caseSetFile);
|
||||
const suiteCases = suite.cases.filter((item) => !payload.caseIds || payload.caseIds.includes(item.case_id));
|
||||
const runId = typeof payload.runId === "string" && payload.runId.trim().length > 0 ? payload.runId.trim() : `assistant-stage1-${nanoid(10)}`;
|
||||
const analysisDate = normalizeAnalysisDate(payload.analysisDate);
|
||||
const assistantService = new AssistantService(this.normalizerService, new AssistantSessionStore());
|
||||
const diagnostics: AssistantCaseDiagnostics[] = [];
|
||||
let requestsTotal = 0;
|
||||
@@ -1917,6 +1953,15 @@ export class EvalService {
|
||||
developerPrompt: payload.normalizeConfig.developerPrompt,
|
||||
domainPrompt: payload.normalizeConfig.domainPrompt,
|
||||
fewShotExamples: payload.normalizeConfig.fewShotExamples,
|
||||
context: analysisDate
|
||||
? {
|
||||
period_hint: analysisDate,
|
||||
analysis_context: {
|
||||
as_of_date: analysisDate,
|
||||
source: "eval_analysis_date"
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
useMock: payload.useMock
|
||||
})) as AssistantMessageResponsePayload;
|
||||
turnResponses.push(response);
|
||||
@@ -2153,6 +2198,7 @@ export class EvalService {
|
||||
eval_target: "assistant_stage1",
|
||||
mode: payload.mode,
|
||||
use_mock: Boolean(payload.useMock),
|
||||
analysis_date: analysisDate,
|
||||
prompt_version: payload.normalizeConfig.promptVersion ?? null,
|
||||
suite_id: suite.suite_id,
|
||||
suite_version: suite.suite_version,
|
||||
@@ -2225,6 +2271,7 @@ export class EvalService {
|
||||
mode: EvalRunMode;
|
||||
caseSetFile?: string;
|
||||
compareWithReportFile?: string;
|
||||
analysisDate?: string;
|
||||
runId?: string;
|
||||
}): Promise<Record<string, unknown>> {
|
||||
if (!FEATURE_ASSISTANT_STAGE2_EVAL_V1) {
|
||||
@@ -2238,6 +2285,7 @@ export class EvalService {
|
||||
const suite = parseAssistantStage2SuiteFile(payload.caseSetFile);
|
||||
const suiteCases = suite.cases.filter((item) => !payload.caseIds || payload.caseIds.includes(item.case_id));
|
||||
const runId = typeof payload.runId === "string" && payload.runId.trim().length > 0 ? payload.runId.trim() : `assistant-stage2-${nanoid(10)}`;
|
||||
const analysisDate = normalizeAnalysisDate(payload.analysisDate);
|
||||
const assistantService = new AssistantService(this.normalizerService, new AssistantSessionStore());
|
||||
const diagnostics: AssistantStage2CaseDiagnostics[] = [];
|
||||
let requestsTotal = 0;
|
||||
@@ -2269,6 +2317,15 @@ export class EvalService {
|
||||
developerPrompt: payload.normalizeConfig.developerPrompt,
|
||||
domainPrompt: payload.normalizeConfig.domainPrompt,
|
||||
fewShotExamples: payload.normalizeConfig.fewShotExamples,
|
||||
context: analysisDate
|
||||
? {
|
||||
period_hint: analysisDate,
|
||||
analysis_context: {
|
||||
as_of_date: analysisDate,
|
||||
source: "eval_analysis_date"
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
useMock: payload.useMock
|
||||
})) as AssistantMessageResponsePayload;
|
||||
turnResponses.push(response);
|
||||
@@ -2446,6 +2503,7 @@ export class EvalService {
|
||||
eval_target: "assistant_stage2",
|
||||
mode: payload.mode,
|
||||
use_mock: Boolean(payload.useMock),
|
||||
analysis_date: analysisDate,
|
||||
prompt_version: payload.normalizeConfig.promptVersion ?? null,
|
||||
suite_id: suite.suite_id,
|
||||
suite_version: suite.suite_version,
|
||||
@@ -2552,10 +2610,12 @@ export class EvalService {
|
||||
rawQuestions?: string;
|
||||
evalTarget?: EvalTarget;
|
||||
compareWithReportFile?: string;
|
||||
analysisDate?: string;
|
||||
runId?: string;
|
||||
}): Promise<Record<string, unknown>> {
|
||||
const mode = payload.mode ?? "standard";
|
||||
const evalTarget = payload.evalTarget ?? "normalizer";
|
||||
const analysisDate = normalizeAnalysisDate(payload.analysisDate);
|
||||
|
||||
if (evalTarget === "assistant_stage1") {
|
||||
return this.runAssistantStage1({
|
||||
@@ -2565,6 +2625,7 @@ export class EvalService {
|
||||
mode,
|
||||
caseSetFile: payload.caseSetFile,
|
||||
compareWithReportFile: payload.compareWithReportFile,
|
||||
analysisDate: analysisDate ?? undefined,
|
||||
runId: payload.runId
|
||||
});
|
||||
}
|
||||
@@ -2577,6 +2638,7 @@ export class EvalService {
|
||||
mode,
|
||||
caseSetFile: payload.caseSetFile,
|
||||
compareWithReportFile: payload.compareWithReportFile,
|
||||
analysisDate: analysisDate ?? undefined,
|
||||
runId: payload.runId
|
||||
});
|
||||
}
|
||||
@@ -2622,6 +2684,7 @@ export class EvalService {
|
||||
return this.runV2({
|
||||
...payload,
|
||||
mode,
|
||||
analysisDate: analysisDate ?? undefined,
|
||||
cases: filtered
|
||||
});
|
||||
}
|
||||
@@ -2651,6 +2714,13 @@ export class EvalService {
|
||||
...payload.normalizeConfig,
|
||||
userQuestion: item.raw_question,
|
||||
context: {
|
||||
period_hint: analysisDate ?? undefined,
|
||||
analysis_context: analysisDate
|
||||
? {
|
||||
as_of_date: analysisDate,
|
||||
source: "eval_analysis_date"
|
||||
}
|
||||
: undefined,
|
||||
expected_route: item.expected.route_hint as NormalizeRequestPayload["context"] extends infer C
|
||||
? C extends { expected_route?: infer R }
|
||||
? R
|
||||
@@ -2779,6 +2849,7 @@ export class EvalService {
|
||||
timestamp: new Date().toISOString(),
|
||||
mode,
|
||||
use_mock: Boolean(payload.useMock),
|
||||
analysis_date: analysisDate,
|
||||
prompt_version: payload.normalizeConfig.promptVersion ?? null,
|
||||
dataset: {
|
||||
source: payload.caseSetFile ? "file" : "data/eval_cases/*.json",
|
||||
|
||||
Reference in New Issue
Block a user