OpenAI 兼容 JSON 模式
OpenAI 兼容 JSON 模式
r = client.chat.completions.create(
model="<模型名>",
messages=[{"role": "user", "content": "输出包含 name 与 age 的 JSON"}],
response_format={"type": "json_object"},
)vLLM 引导解码(示意)
vLLM 引导解码(示意)
from vllm import SamplingParams
from vllm.sampling_params import GuidedDecodingParams
sp = SamplingParams(
guided_decoding=GuidedDecodingParams(
json={"type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"]}
)
)约束校验有每步开销:首字延迟会上升,schema 越复杂越明显;接口形态随版本演进,以所用版本文档为准。