Validate complete Llama tool-call output
Source code in vllm/parser/llama_json.py
| def _validate_complete_tool_output(text: str) -> bool | None:
"""Validate complete Llama tool-call output"""
if text.startswith(TOOL_START):
text = text[len(TOOL_START) :]
elif not text.startswith("{"):
return None
decoder = json.JSONDecoder()
position = 0
found = False
while position < len(text):
while position < len(text) and text[position].isspace():
position += 1
if position == len(text):
return found
try:
value, end = decoder.raw_decode(text, position)
except json.JSONDecodeError:
return False
if (
not isinstance(value, dict)
or "name" not in value
or ("arguments" not in value and "parameters" not in value)
):
return False
found = True
position = end
while position < len(text) and text[position].isspace():
position += 1
if position == len(text):
return True
if _has_only_output_end_token(text, position):
return True
if text[position] != ";":
return False
position += 1
return found
|