Answer principles round 2: 0 🔴, 0 🟡; name the typed answer's two parts in Typed
This commit is contained in:
@@ -35,7 +35,7 @@ class Render(unittest.TestCase):
|
|||||||
queued("origin/main moved", "coordinator"),
|
queued("origin/main moved", "coordinator"),
|
||||||
{**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"},
|
{**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"},
|
||||||
{**human("Answered: use B\nYour question: A or B?"), "promptSource": "sdk"},
|
{**human("Answered: use B\nYour question: A or B?"), "promptSource": "sdk"},
|
||||||
], lambda prompt: tuple(reversed(prompt.removeprefix("Answered: ").split("\n"))) if prompt.startswith("Answered: ") else None)
|
], lambda prompt: transcript.Typed(*reversed(prompt.removeprefix("Answered: ").split("\n"))) if prompt.startswith("Answered: ") else None)
|
||||||
self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work\n\n[loop] Continue the task; the previous run stopped before it was finished.\n\n[loop] Your question: A or B?\n\n[human] use B')
|
self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work\n\n[loop] Continue the task; the previous run stopped before it was finished.\n\n[loop] Your question: A or B?\n\n[human] use B')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,12 @@ from failure import Failure
|
|||||||
JUDGED_TOOL_INPUT = 400
|
JUDGED_TOOL_INPUT = 400
|
||||||
|
|
||||||
|
|
||||||
|
class Typed(typing.NamedTuple):
|
||||||
|
"""A -p prompt of loop-claude's that carries an answer the human typed: loop-claude's words, and that answer."""
|
||||||
|
loop_words: str
|
||||||
|
answer: str
|
||||||
|
|
||||||
|
|
||||||
def read_transcript(path: str) -> list[dict] | Failure:
|
def read_transcript(path: str) -> list[dict] | Failure:
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as handle:
|
with open(path, "rb") as handle:
|
||||||
@@ -25,8 +31,8 @@ def human_turns(entries: list[dict]) -> int:
|
|||||||
return sum(1 for entry in entries if human_text(entry) is not None)
|
return sum(1 for entry in entries if human_text(entry) is not None)
|
||||||
|
|
||||||
|
|
||||||
def render(entries: list[dict], typed_answer: typing.Callable[[str], tuple[str, str] | None]) -> str:
|
def render(entries: list[dict], typed_answer: typing.Callable[[str], Typed | None]) -> str:
|
||||||
"""The transcript as the judge reads it. typed_answer splits a -p prompt of loop-claude's that carries an answer the human typed into loop-claude's words and that answer, which reads as the human's, like one typed in claude."""
|
"""The transcript as the judge reads it. typed_answer splits a -p prompt of loop-claude's that carries an answer the human typed, which reads as the human's, like one typed in claude."""
|
||||||
lines = []
|
lines = []
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
lines += [line for part in assistant_parts(entry) if (line := part_line(part, JUDGED_TOOL_INPUT))]
|
lines += [line for part in assistant_parts(entry) if (line := part_line(part, JUDGED_TOOL_INPUT))]
|
||||||
@@ -34,7 +40,7 @@ def render(entries: list[dict], typed_answer: typing.Callable[[str], tuple[str,
|
|||||||
lines.append("[human] " + text)
|
lines.append("[human] " + text)
|
||||||
elif (text := loop_text(entry)) is not None:
|
elif (text := loop_text(entry)) is not None:
|
||||||
typed = typed_answer(text)
|
typed = typed_answer(text)
|
||||||
lines += ["[loop] " + text] if typed is None else ["[loop] " + typed[0], "[human] " + typed[1]]
|
lines += ["[loop] " + text] if typed is None else ["[loop] " + typed.loop_words, "[human] " + typed.answer]
|
||||||
return "\n\n".join(lines)
|
return "\n\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from model_routing.route import ESCALATION_MARKER, HIGHEST_ESCAPE_AND_IMPACT, Ro
|
|||||||
from loop_claude.routing import escalation_rungs
|
from loop_claude.routing import escalation_rungs
|
||||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||||
from markdown_text import listed, quoted
|
from markdown_text import listed, quoted
|
||||||
|
from claude_code.transcript import Typed
|
||||||
|
|
||||||
# Where the judge may quote an answer from, named as the human and the worker see them; of README.md the judge sees only the premises.
|
# Where the judge may quote an answer from, named as the human and the worker see them; of README.md the judge sees only the premises.
|
||||||
QUOTE_SOURCES = listed(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or")
|
QUOTE_SOURCES = listed(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or")
|
||||||
@@ -137,13 +138,13 @@ def typed(question: str, answer: str, route: Route, anchor: Rung | None, stepped
|
|||||||
TYPED_HERE = "The human answered your question at loop-claude's terminal:"
|
TYPED_HERE = "The human answered your question at loop-claude's terminal:"
|
||||||
|
|
||||||
|
|
||||||
def typed_answer(prompt: str) -> tuple[str, str] | None:
|
def typed_answer(prompt: str) -> Typed | None:
|
||||||
"""The rest of the prompt typed made, and the answer it put there, so the judge reads the answer as the human's; None for any other prompt."""
|
"""The answer typed put in prompt, and the rest of that prompt, so the judge reads the answer as the human's; None for any other prompt."""
|
||||||
opening = f"{TYPED_HERE}\n"
|
opening = f"{TYPED_HERE}\n"
|
||||||
if not prompt.startswith(opening):
|
if not prompt.startswith(opening):
|
||||||
return None
|
return None
|
||||||
answer, _, rest = prompt.removeprefix(opening).partition("\n\n")
|
answer, _, rest = prompt.removeprefix(opening).partition("\n\n")
|
||||||
return rest, answer
|
return Typed(rest, answer)
|
||||||
|
|
||||||
|
|
||||||
def stepped_to(route: Route, anchor: Rung | None, stepped: bool) -> str:
|
def stepped_to(route: Route, anchor: Rung | None, stepped: bool) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user