File size: 840 Bytes
711ed9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""Score publisher-protocol content without treating truncated thoughts as answers."""
def normalize_content(raw, finish_reason):
    raw=(raw or '').lstrip()
    # llama.cpp content-only mode echoes the template's generation prefix.
    # It is protocol framing, not part of the answer (notably for MC letters).
    if raw.startswith('<think>'):
        raw=raw[len('<think>'):].lstrip('\r\n')
    if '</think>' in raw:
        reasoning,_,content=raw.rpartition('</think>')
        return content,reasoning.removeprefix('<think>').strip(),'explicit-close'
    if finish_reason=='length':
        return '',raw,'unclosed-length-limit'
    # Publisher serves without a reasoning parser: completed direct answers
    # without a closing tag are content. Never infer an answer from hidden fields.
    return raw,'','publisher-direct-content'