lispm-llm / data_arguments.py
Ryan.K
Publish LispM Emacs agent harness classifier
6ae9156 unverified
Raw History Blame Contribute Delete
1.79 kB
"""Deterministic typed literals for synthetic calibration and evaluation rows.
The model sees NAME rather than the literal. Fixtures still need valid values
for the runtime's URL and basename contracts, including unsupported requests
about web navigation; otherwise malformed arguments would inflate rejection.
This module does not read benchmarks and is not used during user inference.
"""
import json
import re
from urllib.parse import quote
# Web-context negatives receive a real URI rather than an invalid placeholder.
_WEB_CONTEXT = re.compile(r'\b(?:url|uri|website|site|browser|web)\b', re.IGNORECASE)
# Quoted strings are matched first so their contents cannot become placeholders.
_LITERAL_OR_PLACEHOLDER = re.compile(r'"(?:\\.|[^"\\])*"|(?<![\w-])NAME(?![\w-])')
def example_argument(label, value='Notes'):
"""Return a valid representative literal for LABEL, preserving VALUE identity."""
if label == 'lispm-browser-open-url':
return 'https://example.org/' + quote(value, safe='')
return value
def materialize(phrase, label=None, argument=None):
"""Replace NAME with one quoted typed literal, keeping existing quotes intact.
Explicit ARGUMENT values in a frozen corpus take precedence. Positive labels
determine their argument kind. Rejection rows about web operations use a
valid URL so their intent, rather than an invalid URL, is being evaluated.
"""
if argument is None:
web_negative = label in (None, 'reject') and _WEB_CONTEXT.search(phrase)
argument = example_argument('lispm-browser-open-url' if web_negative else label)
quoted = json.dumps(argument, ensure_ascii=False)
return _LITERAL_OR_PLACEHOLDER.sub(
lambda match: quoted if match.group() == 'NAME' else match.group(), phrase)