vllm.reasoning.cohere_command_reasoning_parser ¶
CohereNormalizedTool ¶
Bases: TypedDict
A tool definition normalized to the shape collect_tool_schema expects.
parameters is a JSON Schema object (possibly empty) describing the tool's call signature.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
CohereTagRegistry ¶
CohereTagStyle ¶
Bases: NamedTuple
The structural tags style for a given model architecture.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_has_effective_tools ¶
True when tools contains at least one tool definition to convert.
ResponsesRequest defaults tools to []; ChatCompletionRequest uses None. Both mean "no tools" here. Strings (e.g. a JSON blob) are treated as effective only when non-blank.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_maybe_parse_json_dict ¶
If value is a JSON string, parse to dict; otherwise require dict.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_schema_dict_from_chat_response_format ¶
JSON schema dict from Chat Completions request.response_format only.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_schema_dict_from_structured_outputs ¶
_schema_dict_from_structured_outputs(
so: StructuredOutputsParams | None,
) -> dict | None
Schema dict from structured_outputs (json / json_object).
Same unwrapping as json_schema. json is expected to be str or dict (enforced by StructuredOutputsParams / request models); other types raise ValueError only if a caller bypasses that validation.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_schema_from_json_schema_field ¶
Extract the JSON Schema object from Chat Completions json_schema payload.
Accepts: - JsonSchemaResponseFormat (Pydantic) with schema / json_schema field - dict in OpenAI shape {"name": ..., "schema": {...}} - dict with json_schema key holding either the schema or a nested wrapper - dict that is already a JSON Schema document (some clients omit the wrapper) - JSON strings for any of the above
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_tool_definitions_to_schema_list ¶
_tool_definitions_to_schema_list(
tools: str | list[Any],
) -> list[CohereNormalizedTool]
Build the list of CohereNormalizedTool dicts expected by collect_tool_schema.
Accepts: - JSON string - list of dicts with top-level name / parameters - list of Chat Completions-style {"type": "function", "function": {...}} - list of Pydantic models with model_dump()
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
_unwrap_nested_schema ¶
Return candidate as a dict, unwrapping a nested schema if present.
Returns None if candidate is not (and cannot be parsed into) a dict.
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
collect_tool_schema ¶
collect_tool_schema(
tool_schema: list[CohereNormalizedTool],
) -> str
Build an xgrammar EBNF grammar that matches a JSON array of tool calls.
The grammar shape is architecture-independent; callers are responsible for wrapping it in the correct structural tag (see CohereTagStyle.tools).
Source code in vllm/reasoning/cohere_command_reasoning_parser.py
convert_schema_to_structural_tags ¶
convert_schema_to_structural_tags(
schema: dict | None = None,
tools: str | list[Any] | None = None,
model_architecture: str | None = None,
) -> str | None
Returns a response_format string accepted by xgrammar's structural tag format. Uses the canonical shape: {"type": "structural_tag", "format": {...}} with format.type "triggered_tags" and tag content type "json_schema" or "grammar".
Callers that are not on an engine path (e.g. the reasoning parser) must pass model_architecture explicitly.