Review syntax after model without typo whitelist
This commit is contained in:
+10
-6
@@ -97,14 +97,18 @@ def review(input_path, source_commit, out_dir, propose=backend):
|
||||
candidate = response.get("candidate")
|
||||
if type(candidate) is not str:
|
||||
raise ValueError("backend candidate must be text")
|
||||
expected = {"print(\"hello\"": "print(\"hello\")",
|
||||
"print(\"hello\"\n": "print(\"hello\")\n"}
|
||||
if source not in expected or candidate != expected[source]:
|
||||
metadata.update(status="rejected", summary="Proposal exceeds the permitted closing-parenthesis repair")
|
||||
try:
|
||||
parsed = ast.parse(candidate)
|
||||
except SyntaxError:
|
||||
parsed = None
|
||||
safe_program = ast.parse('print("hello")')
|
||||
if (parsed is None or
|
||||
ast.dump(parsed, include_attributes=False) != ast.dump(safe_program, include_attributes=False)
|
||||
or candidate.endswith("\n") != source.endswith("\n")):
|
||||
metadata.update(status="rejected", summary="Proposal changes the demo behavior or adds code")
|
||||
code = 2
|
||||
else:
|
||||
ast.parse(candidate)
|
||||
metadata.update(status="corrected", summary="Added the missing closing parenthesis",
|
||||
metadata.update(status="corrected", summary="Model proposed runnable hello program",
|
||||
diff="".join(difflib.unified_diff(source.splitlines(keepends=True),
|
||||
candidate.splitlines(keepends=True), fromfile="original.py", tofile="reviewed.py")))
|
||||
code = 0
|
||||
|
||||
@@ -31,8 +31,8 @@ def propose(source):
|
||||
raise FileNotFoundError("llama-completion executable missing")
|
||||
if _sha256(executable) != lock["runtime_entrypoint_sha256"]:
|
||||
raise ValueError("llama-completion checksum mismatch")
|
||||
if source not in ('print("hello"', 'print("hello"\n'):
|
||||
raise ValueError("real-model adapter only supports the hello fixture")
|
||||
if len(source.encode("utf-8")) > 1024 or "\n" in source.rstrip("\n"):
|
||||
raise ValueError("demo source must be one bounded line")
|
||||
prompt = lock["prompt_template"].format(source_line=source.rstrip("\n"))
|
||||
command = [str(executable), "-m", str(model), "-p", prompt,
|
||||
"-n", str(lock["max_output_tokens"]), "-c", str(lock["context_tokens"]),
|
||||
|
||||
Reference in New Issue
Block a user