Commit d4be176
Fix message content field handling for tool calls and multimodal input
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]>1 parent 420b5c4 commit d4be176
File tree
2 files changed
+410
-5
lines changed- lmdeploy/serve
- tests/test_lmdeploy
2 files changed
+410
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
35 | 86 | | |
36 | 87 | | |
37 | 88 | | |
| |||
609 | 660 | | |
610 | 661 | | |
611 | 662 | | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
617 | 666 | | |
618 | 667 | | |
619 | 668 | | |
| |||
0 commit comments