Skip to content

Conversation

QwertyJack
Copy link
Contributor

This commit fixes two issues with message content processing:

  1. Missing content field in tool call responses: When assistant messages contain tool_calls, the content field may be missing or None, causing KeyError when checking isinstance(msg['content'], list).

  2. Incomplete multimodal text merging: Previous implementation only extracted the first text block. Now correctly merges all text blocks with newline separator.

Changes:

  • Add _merge_message_content() module-level function in async_engine.py
  • Handle 4 cases: missing content, None content, string content, list content
  • Use '\n'.join() to merge text blocks (matches vLLM behavior)
  • Preserve all message fields (e.g., tool_calls, name, etc.)
  • Add comprehensive unit tests (19 test cases in test_content_merge.py)

Implementation based on vLLM's content normalization logic: https://github.com/vllm-project/vllm/blob/main/vllm/entrypoints/chat_utils.py

🤖 Generated with Claude Code

This commit fixes two issues with message content processing:

1. **Missing content field in tool call responses**: When assistant messages
   contain tool_calls, the content field may be missing or None, causing
   KeyError when checking isinstance(msg['content'], list).

2. **Incomplete multimodal text merging**: Previous implementation only
   extracted the first text block. Now correctly merges all text blocks
   with newline separator.

Changes:
- Add _merge_message_content() module-level function in async_engine.py
- Handle 4 cases: missing content, None content, string content, list content
- Convert None/missing content to empty string '' (prevents Jinja2 errors)
- Use '\n'.join() to merge text blocks (matches vLLM behavior)
- Preserve all message fields (e.g., tool_calls, name, etc.)
- Add comprehensive unit tests (19 test cases in test_content_merge.py)

Implementation based on vLLM's content normalization logic:
https://github.com/vllm-project/vllm/blob/main/vllm/entrypoints/chat_utils.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant