czat: P7 „ta druga” po jednej pozycji pyta, goły przypis nie jest odniesieniem
Po liście z jedną pozycją kod odpowiada, że była tylko jedna, i pyta, zamiast szukać pytania od nowa. Rekord cytowany tylko po zdaniu bez wartości i bez nazwy („nie znalazłem odpowiedzi [1]”) nie trafia do odniesień ani do źródeł następnej tury. Angielskie liczebniki zostają na P11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016uwxqFNnaMueKrFn1ogB8u
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
22a369fd31
commit
8ab82d019d
@@ -206,3 +206,17 @@ def test_p6_the_check_and_the_refusals_follow_the_data_not_the_words() -> None:
|
||||
assert "tydzień kalendarzowy od 2026-11-09 do 2026-11-15" in got["terminy"]
|
||||
assert got["poem"].get("coded") == "refusal", got["poem"]
|
||||
assert got["total"].get("coded") == "fallback" and "205 000,50 PLN" in got["total"]["content"], got["total"]
|
||||
|
||||
|
||||
def test_p7_a_second_of_one_is_asked_and_a_bare_citation_is_no_reference() -> None:
|
||||
# After a one-item list "a ta druga?" was searched as a new question and answered about another record
|
||||
# (q-ta-druga, 9.11); and "nie znalazłem odpowiedzi [1]" made [1] what the next "ta umowa" meant.
|
||||
got = _run("""const s = session([(b) => `W ciągu 30 dni kończy się jedna umowa: UM-2026-0006 Ochrona obiektu [${nOf(b, 'okno 30 dni')}].`]);
|
||||
await s.ask('Które umowy wygasają w ciągu 30 dni?');
|
||||
const second = await s.ask('a ta druga?');
|
||||
const t = session(['W danych, do których masz dostęp, nie znalazłem odpowiedzi [1].']);
|
||||
const bare = await t.ask('Jaki jest NIP firmy Kalinowy Dwór?');
|
||||
return { calls: s.asked.length, coded: second.coded, content: second.content, mentioned: bare.mentioned };""")
|
||||
assert got["calls"] == 1 and got["coded"] == "ask"
|
||||
assert "tylko jedna" in got["content"] and "UM-2026-0006" in got["content"]
|
||||
assert got["mentioned"] == []
|
||||
|
||||
+15
-4
@@ -3202,8 +3202,9 @@ function chatResolveRefs(prev, ana, index) {
|
||||
if (!cands.length) return { keys: [], none: ana.demonstrative && ['umowa', 'sprawa'].includes(kind), kind };
|
||||
if (ana.ordinal) {
|
||||
const r = ana.ordinal < 0 ? cands[cands.length - 1] : cands[ana.ordinal - 1];
|
||||
// "ta druga" after one record: "which one?" with one option helps nobody, and pinning it would be wrong.
|
||||
return r ? { keys: [r.key] } : cands.length === 1 ? { keys: [] } : { keys: [], ambiguous: cands, kind };
|
||||
// "ta druga" after one record: pinning it would be wrong, and searching the question as new found another
|
||||
// record and answered about it (q-ta-druga, 9.11): code says there was only one and asks.
|
||||
return r ? { keys: [r.key] } : cands.length === 1 ? { keys: [], only: cands[0], kind } : { keys: [], ambiguous: cands, kind };
|
||||
}
|
||||
return cands.length === 1 ? { keys: [cands[0].key] } : { keys: [], ambiguous: cands, kind };
|
||||
}
|
||||
@@ -3236,12 +3237,18 @@ const chatQuotes = (t) => [...new Set([...(t.table ? t.content.split('\n\n| ')[0
|
||||
|
||||
const chatCitedNs = (text) => [...new Set((String(text).match(/\[\d+(?:\s*,\s*\d+)*\]/g) || []).flatMap((m) => m.match(/\d+/g).map(Number)))];
|
||||
|
||||
// A record cited only after words with no value and no name ("nie znalazłem odpowiedzi [1]") is not what the
|
||||
// answer was about: made a reference, the next "ta umowa" pointed at it (P7, 9.11).
|
||||
const chatBareCite = (text, n, records) => [...text.matchAll(/\[(\d+(?:\s*,\s*\d+)*)\]/g)]
|
||||
.filter((m) => m[1].split(',').map(Number).includes(n))
|
||||
.every((m) => { const piece = text.slice(0, m.index).split(/[.!?\n]\s/).at(-1); return !chatClaims(piece).length && !chatNamed(piece, records).length; });
|
||||
|
||||
// The records the previous answer cited come first again: most follow-ups ("ale przecież…") are about them.
|
||||
// A law text is not in the index; the ref's kept text stands in for it.
|
||||
function chatCarry(prev, index) {
|
||||
if (!prev || !prev.refs) return [];
|
||||
const byN = new Map(prev.refs.map((r) => [r.n, r]));
|
||||
return chatCitedNs(prev.content).map((n) => byN.get(n)).filter((r) => r && r.key)
|
||||
return chatCitedNs(prev.content).filter((n) => !chatBareCite(prev.content, n, index.records)).map((n) => byN.get(n)).filter((r) => r && r.key)
|
||||
.map((r) => index.byKey.get(r.key) || (r.text ? { slug: r.slug, kind: r.kind, title: r.title, inner: r.inner, url: r.url, text: r.text, key: r.key } : null))
|
||||
.filter(Boolean).slice(0, 4);
|
||||
}
|
||||
@@ -3543,7 +3550,7 @@ async function chatRound(model, messages, answer, onUpdate, { signal = chat.ctl.
|
||||
function chatMentioned(text, sources, index) {
|
||||
const citedRecs = chatCitedNs(text).map((n) => sources[n - 1]).filter(Boolean);
|
||||
const pos = new Map(chatNamed(text, [...citedRecs, ...citedRecs.flatMap((r) => (r.members || []).map((k) => index.byKey.get(k)).filter(Boolean))]));
|
||||
for (const r of citedRecs) if (!pos.has(r.key)) pos.set(r.key, text.search(new RegExp(`\\[(\\d+\\s*,\\s*)*${sources.indexOf(r) + 1}\\b`)));
|
||||
for (const r of citedRecs) if (!pos.has(r.key) && !chatBareCite(text, sources.indexOf(r) + 1, index.records)) pos.set(r.key, text.search(new RegExp(`\\[(\\d+\\s*,\\s*)*${sources.indexOf(r) + 1}\\b`)));
|
||||
return [...pos].sort((a, b) => a[1] - b[1]).map(([k]) => k);
|
||||
}
|
||||
// Items past `count` of a numbered list, each with its sub-lines, up to the next paragraph ("Następny krok:").
|
||||
@@ -3777,6 +3784,10 @@ async function chatTurn({ model, question, turns, index, answer = { role: 'assis
|
||||
return done(`O ${which} chodzi: ${res.ambiguous.slice(0, 6).map((r) => r.title).join('; ')}? Napisz numer albo nazwę.`,
|
||||
{ coded: 'ask', mentioned: res.ambiguous.map((r) => r.key) });
|
||||
}
|
||||
if (res.only) {
|
||||
return done(`W poprzedniej odpowiedzi była tylko jedna pozycja: ${res.only.title}. O ${which} chodzi? Podaj numer albo nazwę.`,
|
||||
{ coded: 'ask', mentioned: [res.only.key] });
|
||||
}
|
||||
// A first question with nothing before it ("Ile umów w statusie szkic i jakie to umowy?") is asked of the
|
||||
// data; only a pronoun that can only point back ("w tej umowie") is asked about.
|
||||
if (res.none && (prev || ana.strong)) return done(`Nie wiem, o ${which} chodzi: w tej rozmowie nie padła jeszcze żadna ${res.kind}. Podaj jej numer albo nazwę.`, { coded: 'ask' });
|
||||
|
||||
Reference in New Issue
Block a user