Skip to content

vllm.entrypoints.openai.decisions.slot_prompt

The fixed prompt of slot-readout decision models, byte for byte as trained.

Functions:

  • render_state –

    Strings as they are (stripped with strip), others as indented JSON.

  • render_suffix –

    The question, its options under slot labels and the answer line.

render_state(value, strip=False)

Strings as they are (stripped with strip), others as indented JSON.

Source code in vllm/entrypoints/openai/decisions/slot_prompt.py
def render_state(value: Any, strip: bool = False) -> str:
    """Strings as they are (stripped with `strip`), others as indented JSON."""
    if value is None:
        return ""
    if isinstance(value, str):
        return value.strip() if strip else value
    return json.dumps(value, ensure_ascii=False, indent=2)

render_suffix(type_name, instructions, criteria)

The question, its options under slot labels and the answer line.

Source code in vllm/entrypoints/openai/decisions/slot_prompt.py
def render_suffix(type_name: str, instructions: Any, criteria: Any) -> str:
    """The question, its options under slot labels and the answer line."""
    if type_name == "noul":
        criteria = criteria or {}
        names = ["yes", "no"]
        descriptions = [
            d if criteria.get(k) is None else criteria[k]
            for k, d in NOUL_DEFAULTS.items()
        ]
    elif type_name == "choice":
        names, descriptions = list(criteria), list(criteria.values())
    else:
        names, descriptions = [f"level {i}" for i in range(len(criteria))], criteria
    lines = []
    for label, name, desc in zip(SLOT_LABELS, names, descriptions):
        text = render_state(desc, strip=True)
        lines.append(f"{label}. {name}: {text}" if text else f"{label}. {name}")
    header = "Rate the state:" if type_name == "score" else "Question:"
    question = render_state(instructions, strip=True) or DEFAULT_INSTRUCTIONS[type_name]
    kind = "letter" if len(names) <= len(LABELS) else "label"
    options, labels = "\n".join(lines), ", ".join(SLOT_LABELS[: len(names)])
    return (
        f"{header} {question}\n\nOptions:\n{options}\n\n"
        f"Answer with one {kind}: {labels}."
    )