knowledge: rename ExtractSignature.stop -> stop_table (his review)
The field's purpose was unclear from its name; stop_table says what it stops. Renamed across the signature, its desc/docstring, the caller (raw.stop_table), the wiki.py legacy note, and the test fakes.
This commit is contained in:
@@ -988,7 +988,7 @@ class KnowledgeExpert:
|
|||||||
charge_llm()
|
charge_llm()
|
||||||
heading = f"== Tables == (table {frag['table_idx']}, part {frag['part']}/{frag['of']})"
|
heading = f"== Tables == (table {frag['table_idx']}, part {frag['part']}/{frag['of']})"
|
||||||
raw = self.extract(question=question, heading=heading, text=text)
|
raw = self.extract(question=question, heading=heading, text=text)
|
||||||
if raw.stop:
|
if raw.stop_table:
|
||||||
stopped.add(frag["table_idx"])
|
stopped.add(frag["table_idx"])
|
||||||
self._log(f"extractor STOP_TABLE: table {frag['table_idx']} "
|
self._log(f"extractor STOP_TABLE: table {frag['table_idx']} "
|
||||||
f"({frag['caption'][:40]!r}) not relevant — "
|
f"({frag['caption'][:40]!r}) not relevant — "
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class ExtractSignature(dspy.Signature):
|
|||||||
copied exactly (at least 10 characters). Only facts the text states;
|
copied exactly (at least 10 characters). Only facts the text states;
|
||||||
no inference.
|
no inference.
|
||||||
If the text is a fragment of a larger TABLE whose caption/headers show
|
If the text is a fragment of a larger TABLE whose caption/headers show
|
||||||
its subject is wrong for the question, set stop=True with no facts.
|
its subject is wrong for the question, set stop_table=True with no facts.
|
||||||
Do NOT stop for text that is merely hard — only when the table's
|
Do NOT stop for text that is merely hard — only when the table's
|
||||||
subject is wrong."""
|
subject is wrong."""
|
||||||
question: str = dspy.InputField()
|
question: str = dspy.InputField()
|
||||||
@@ -56,7 +56,7 @@ class ExtractSignature(dspy.Signature):
|
|||||||
text: str = dspy.InputField()
|
text: str = dspy.InputField()
|
||||||
facts: list[Fact] = dspy.OutputField(
|
facts: list[Fact] = dspy.OutputField(
|
||||||
desc="the extracted facts; empty list if none")
|
desc="the extracted facts; empty list if none")
|
||||||
stop: bool = dspy.OutputField(
|
stop_table: bool = dspy.OutputField(
|
||||||
desc="True when this table fragment's subject is wrong for the question")
|
desc="True when this table fragment's subject is wrong for the question")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -92,18 +92,18 @@ def test_process_page_fragments():
|
|||||||
wikitext=WIKITEXT_2TABLES)
|
wikitext=WIKITEXT_2TABLES)
|
||||||
page.tables = parse_tables(WIKITEXT_2TABLES)
|
page.tables = parse_tables(WIKITEXT_2TABLES)
|
||||||
|
|
||||||
# scripted extractor: world-table parts -> stop=True; Italy table -> one Fact
|
# scripted extractor: world-table parts -> stop_table=True; Italy table -> one Fact
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
class FakeOut:
|
class FakeOut:
|
||||||
def __init__(self, facts, stop=False):
|
def __init__(self, facts, stop_table=False):
|
||||||
self.facts = facts
|
self.facts = facts
|
||||||
self.stop = stop
|
self.stop_table = stop_table
|
||||||
|
|
||||||
def fake_extract(question, heading, text, _calls=calls):
|
def fake_extract(question, heading, text, _calls=calls):
|
||||||
_calls.append((question, heading, text))
|
_calls.append((question, heading, text))
|
||||||
if "World rivers" in text:
|
if "World rivers" in text:
|
||||||
return FakeOut([], stop=True)
|
return FakeOut([], stop_table=True)
|
||||||
if "Rivers of Italy" in text:
|
if "Rivers of Italy" in text:
|
||||||
# quote = the full rendered row context (header + row), verbatim
|
# quote = the full rendered row context (header + row), verbatim
|
||||||
# from the fragment the extractor saw
|
# from the fragment the extractor saw
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ def part_of(frag: dict) -> str:
|
|||||||
|
|
||||||
def parse_stop_table(out_text: str) -> bool:
|
def parse_stop_table(out_text: str) -> bool:
|
||||||
"""LEGACY textual STOP_TABLE detector — kept only for tests. Production
|
"""LEGACY textual STOP_TABLE detector — kept only for tests. Production
|
||||||
code reads the typed `stop: bool` field of ExtractSignature."""
|
code reads the typed `stop_table: bool` field of ExtractSignature."""
|
||||||
return "STOP_TABLE" in (out_text or "").upper()[:80]
|
return "STOP_TABLE" in (out_text or "").upper()[:80]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user