vllm.entrypoints.openai.parser.harmony_utils ¶
auto_drop_analysis_messages ¶
Harmony models expect the analysis messages (representing raw chain of thought) to be dropped after an assistant message to the final channel is produced from the reasoning of those messages.
The openai-harmony library does this if the very last assistant message is to the final channel, but it does not handle the case where we're in longer multi-turn conversations and the client gave us reasoning content from previous turns of the conversation with multiple assistant messages to the final channel in the conversation.
So, we find the index of the last assistant message to the final channel and drop all analysis messages that precede it, leaving only the analysis messages that are relevant to the current part of the conversation.
Source code in vllm/entrypoints/openai/parser/harmony_utils.py
flatten_chat_text_content ¶
Extract the text parts from a chat message content field and flatten them into a single string.
Source code in vllm/entrypoints/openai/parser/harmony_utils.py
has_custom_tools ¶
Checks if the given tool types are custom tools (i.e. any tool other than MCP builtin tools)
is_function_recipient ¶
is_function_recipient(
recipient: str,
allowed_function_tool_names: frozenset[str]
| None = None,
) -> bool
Check whether recipient refers to a function tool call.
The optional allowed_function_tool_names parameter is used by the Responses API to distinguish bare function-call recipients (missing the functions. prefix) from MCP tool calls. When provided, a bare recipient is only treated as a function call if it appears in the set. The Chat Completions path omits this parameter so that all bare recipients are accepted as function calls (the heuristic fallback).
Source code in vllm/entrypoints/openai/parser/harmony_utils.py
parse_chat_input_to_harmony_message ¶
parse_chat_input_to_harmony_message(
chat_msg, tool_id_names: dict[str, str] | None = None
) -> list[Message]
Parse a message from request.messages in the Chat Completion API to Harmony messages.
Source code in vllm/entrypoints/openai/parser/harmony_utils.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
parse_chat_inputs_to_harmony_messages ¶
Parse a list of messages from request.messages in the Chat Completion API to Harmony messages.
Source code in vllm/entrypoints/openai/parser/harmony_utils.py
parse_chat_output ¶
Parse the output of a Harmony chat completion into reasoning and final content. Note that when the openai tool parser is used, serving_chat only uses this for the reasoning content and gets the final content from the tool call parser.
When the openai tool parser is not enabled, or when GptOssReasoningParser is in use,this needs to return the final content without any tool calls parsed.
Empty reasoning or final content is returned as None instead of an empty string.