짧은 날씨 후속 질문 보정: '내일 가지'→'까지' 오타 해석, 지역이 없으면 직전 날씨 질문의 지역 이어받기(되묻기 방지)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-18 19:18:17 +09:00
1 parent 999389bc21
commit f8f2589036
3 files changed
+63

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
/**
* 짧은 날씨 후속 질문 보정 (2026-10-18).
*
* 실사고: "현풍 지금까지 강수량" 다음에 "내일 가지 예상 강수량은?"을 묻자 모델이 도구도 안 부르고
* "가지가 어느 지역인지 모르겠다(가지리? 가지산?)"며 되물었다. ① "가지"는 "까지"의 흔한 오타였고
* ② 지역이 빠진 짧은 후속 질문은 직전 대화의 지역을 이어받는 게 맞았다.
* 모델에 맡기지 않고, 해당 턴에 힌트 한 줄을 붙인다. 순수 함수 — 테스트 대상.
*/
const WEATHER_RE = /강수|비가|비\s?(?:와|올|오|왔)|눈\s?(?:이|올|오)|날씨|기온|온도|바람|풍속|습도|미세먼지|초미세|예보|우산|폭우|태풍|안개|서리|더워|추워|추울|더울/;
const TIME_BEFORE_GAJI = /(?:오늘|내일|모레|글피|주말|이번\s?주|다음\s?주|아침|점심|저녁|오전|오후|밤|새벽|\d{1,2}\s?시|\d{1,2}\s?일|[월화수목금토일]요일)\s*가지(?=\s|$|[?.!,])/;
const MAX_FOLLOWUP_CHARS = 40;
export function weatherFollowUpHint(
message: string,
history: ReadonlyArray<{ role: string; content?: any }>,
): string | null {
const msg = String(message || '').trim();
if (!msg || msg.length > MAX_FOLLOWUP_CHARS || !WEATHER_RE.test(msg)) return null;
const notes: string[] = [];
if (TIME_BEFORE_GAJI.test(msg)) {
notes.push(`"가지" in the user's message is almost certainly a typo for "까지" ("until/by") — read it as: ${msg.replace(/가지(?=\s|$|[?.!,])/, '까지')}`);
}
// 직전 몇 턴 안의 날씨 질문 — 지역을 이어받을 근거
const recent = history.slice(-6).filter(h => h.role === 'user').map(h => String(h.content || '').trim()).filter(Boolean);
const prev = [...recent].reverse().find(q => WEATHER_RE.test(q));
if (prev) {
notes.push(`Earlier in this conversation the user asked about weather: "${prev.slice(0, 80)}". If the current message names no place, use the SAME place as that earlier question and call the weather tool — do NOT ask which place they mean. Never invent unrelated place names to ask about.`);
}
return notes.length ? notes.join(' ') : null;
}
+11
View File
@@ -85,6 +85,7 @@ import { selectToolsForTurn, bootAllowedTools, codeAiBlockedTools } from './tool
import { buildChatSystemPrompt, groundingResultReadingRule } from './system-prompt';
import { decideRoute } from './model-routing';
import { weatherFabricationReplacement } from './tool-failure-backstop';
import { weatherFollowUpHint } from './followup-hints';
import { replyIsWrongLanguage, TRANSLATE_TO_KOREAN_SYSTEM } from './language-backstop';
import { lightChat } from '../../providers/light-chat';
import { replyLooksEmpty, appendDroppedSearchImages, appendGeneratedChartImages } from './reply-content';
@@ -953,6 +954,16 @@ async function handleChat(
});
}
{
// 짧은 날씨 후속 질문: "가지"→"까지" 오타 해석 + 직전 지역 이어받기 (followup-hints.ts, 2026-10-18)
const _wfHint = weatherFollowUpHint(message, history);
if (_wfHint) {
console.log('[v2] WEATHER FOLLOW-UP HINT added');
messages.push({ role: 'assistant', content: 'Understood.' });
messages.push({ role: 'user', content: `Note: ${_wfHint}` });
}
}
const buildSecondaryAssistContext = () => {
+20
View File
@@ -0,0 +1,20 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { weatherFollowUpHint } from '../src/gateway/chat/followup-hints';
const H = [{ role: 'user', content: '현풍 지금까지 강수량' }, { role: 'assistant', content: '0mm입니다' }];
test('"내일 가지" 오타 + 직전 지역 이어받기', () => {
const h = weatherFollowUpHint('내일 가지 예상 강수량은?', H)!;
assert.match(h, /까지/); assert.match(h, /현풍/);
});
test('정상 "까지"는 오타 힌트 없음, 지역 이어받기만', () => {
const h = weatherFollowUpHint('내일까지 강수량은?', H)!;
assert.doesNotMatch(h, /typo/); assert.match(h, /현풍/);
});
test('날씨 맥락이 없으면 지역 힌트 없음', () => {
assert.equal(weatherFollowUpHint('내일 비 와?', [{ role: 'user', content: '파스타 맛집' }]), null);
});
test('날씨 질문이 아니면 null', () => assert.equal(weatherFollowUpHint('내일 가지 볶음 레시피', H), null));
test('긴 질문은 건드리지 않음', () => assert.equal(weatherFollowUpHint('내일 구미와 서울과 부산과 대구와 광주와 대전의 날씨와 기온과 강수량을 모두 자세히 비교해서 알려줘', H), null));
test('"가지"가 채소면 오타로 보지 않음', () => assert.equal(weatherFollowUpHint('가지 키우기 좋은 날씨야?', []), null));