INNER CODE UNIT · Python

_outer_object

zachlagden/Pi-hole-Optimized-Blocklists · .github/triage/triage/ai_review.py:337

def _outer_object(text: str) -> dict:
    start, end = text.find("{"), text.rfind("}")
    if start < 0 or end < start:
        raise ValueError("the model did not return JSON")
    return json.loads(text[start : end + 1])


def _json_object(raw: str) -> dict:
    try:
        return _outer_object(THINK_RE.sub("", raw).strip())
    except ValueError:
        thinking, closed, answer = raw.rpartition("</think>")
        opening = thinking.rfind("{")
        if not closed or opening < 0 or thinking[opening:].strip() not in {"{", '{"'}:
            raise
        return _outer_object(thinking[opening:].strip() + answer.strip())

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…