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 buildin tools)
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
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 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 | |
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.