Files
ModelHub XC c1ce9811bb 初始化项目,由ModelHub XC社区提供模型
Model: Xirui1208/selective-readtwice-7b-early-evaluated-20260928
Source: Original Platform
2026-11-17 05:18:17 +08:00

109 lines
3.8 KiB
Python

"""Inference-only v64 slot Gate bound to the rewrite1024 ReadTwice protocol.
The Gate prompt and slot layout below are byte-identical to the historical
``selective.protocol_v43`` contract used by the best v64 Selective model. The
SKIM, UPDATE, and FINAL prompts come from the current rewrite1024 protocol.
"""
from .protocol_readtwice import (
TEMPLATE_FINAL,
TEMPLATE_SKIM,
TEMPLATE_UPDATE_READTWICE,
)
GATE_SLOT_MARKER = "<gate_slot>"
TEMPLATE_PARALLEL_SLOT_DENSE_GATE = """Below is a global outline of a long document, one gist per section:
<section_count>
{total_sections}
</section_count>
<outline>
{outline}
</outline>
A user will ask the following question about the document:
<question>
{prompt}
</question>
Decide whether every focused section should be read in full during the second
pass. Output READ when a section contains, or is likely to contain, factual
evidence useful for answering the question, including direct answer evidence,
entity identity, aliases, attributes, and multi-step bridge facts. Output SKIP
when the section is unrelated or would not add useful evidence. Use the whole
outline to interpret every focused entry. Missing a required bridge or answer
section is more harmful than reading one additional plausible section. Do not
enforce a fixed number or fraction of READ decisions; classify every section
independently.
All focused entries are packed below for one batched decision. The slot
markers identify the entries to classify; do not reproduce them in the answer.
<focus_sections>
{focus_sections}
</focus_sections>
Return exactly {total_sections} decisions in outline order. Decision i is for
Section i. The count in GATE brackets and the number of decisions must both
match <section_count>. Begin the only output line with GATE[{total_sections}]:
and then emit exactly {total_sections} comma-and-space-separated decisions.
Use uppercase READ or SKIP only. Output no explanation or additional line.
"""
def pack_focus_sections(outline, total_sections):
"""Turn a canonical outline into deterministic focused blocks and slots."""
entries = str(outline).splitlines()
if len(entries) != int(total_sections):
raise ValueError(
f"outline has {len(entries)} entries, expected {total_sections}"
)
blocks = []
for section_id, entry in enumerate(entries, 1):
prefix = f"[Section {section_id}] "
if not entry.startswith(prefix):
raise ValueError(
f"outline entry {section_id} does not start with {prefix!r}"
)
blocks.append(
"<focused_item>\n"
"Classify this section:\n"
f"<focus_section>\n{section_id}\n</focus_section>\n"
"<focused_outline_entry>\n"
f"{entry}\n"
"</focused_outline_entry>\n"
f"{GATE_SLOT_MARKER}\n"
"</focused_item>"
)
return "\n".join(blocks)
def format_gate_prompt(outline, prompt, total_sections):
"""Render the historical v64 parallel-slot Gate prompt exactly."""
return TEMPLATE_PARALLEL_SLOT_DENSE_GATE.format(
total_sections=int(total_sections),
outline=str(outline),
prompt=str(prompt),
focus_sections=pack_focus_sections(outline, total_sections),
)
def format_gate_target(decisions):
"""Render a canonical dense Gate target for protocol checks."""
values = [str(value).strip().upper() for value in decisions]
if not values or any(value not in {"READ", "SKIP"} for value in values):
raise ValueError("decisions must be a non-empty READ/SKIP sequence")
return f"GATE[{len(values)}]: " + ", ".join(values)
__all__ = [
"GATE_SLOT_MARKER",
"TEMPLATE_FINAL",
"TEMPLATE_PARALLEL_SLOT_DENSE_GATE",
"TEMPLATE_SKIM",
"TEMPLATE_UPDATE_READTWICE",
"format_gate_prompt",
"format_gate_target",
"pack_focus_sections",
]