Python: Bug: ChatMessageContent.from_element drops AudioContent and BinaryContent into raw TextContent

未关闭 适合新手
#14,824 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@halcyon-past 已经在做这个了。

开始于 2026年11月18日。

  • #14825 来自 @halcyon-past —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从python/semantic_kernel/contents/chat_message_content.py开始,阅读TAG_CONTENT_MAP以及from_element()对内容标签的处理。检查AudioContent和BinaryContent如何序列化和反序列化,然后验证 XML 和 prompt 往返后能保留其项目类型。还要检查semantic_kernel.contents.__all__对BinaryContent的导出;完成标准是这两种类型往返后都不会变成TextContent。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

When ChatMessageContent containing AudioContent or BinaryContent is converted to an XML Element and deserialized via ChatMessageContent.from_element(), or round-tripped through prompt rendering (ChatHistory.to_prompt() / ChatHistory.from_rendered_prompt()), the AudioContent and BinaryContent items are corrupted into TextContent containing literal XML tags (e.g. <audio>...</audio>), and a warning is logged:
Unknown tag "audio" in ChatMessageContent, treating as text

Where

In python/semantic_kernel/contents/chat_message_content.py:
TAG_CONTENT_MAP includes tags for annotation, text, file_reference, function_call, function_result, image, reasoning, and streaming variants, but omits AUDIO_CONTENT_TAG ("audio") and BINARY_CONTENT_TAG ("binary").

Also, BinaryContent is omitted from semantic_kernel.contents.__all__.

To Reproduce
from semantic_kernel.contents import AudioContent, ChatMessageContent, AuthorRole

ac = AudioContent(data=b"test_audio", mime_type="audio/mpeg")
cmc = ChatMessageContent(role=AuthorRole.USER, items=[ac])
elem = cmc.to_element()
restored = ChatMessageContent.from_element(elem)

assert cmc == restored
# Fails:
# WARNING:root:Unknown tag "audio" in ChatMessageContent, treating as text
# AssertionError: ChatMessageContent(..., items=[AudioContent(...)]) != ChatMessageContent(..., items=[TextContent(text='<audio>data:audio/mpeg;,test_audio</audio>')])
Expected behavior

ChatMessageContent.from_element() correctly deserializes <audio> into AudioContent and <binary> into BinaryContent, preserving item types across prompt and XML round trips.

Platform
  • Language: Python
  • Source: main branch
  • OS: Mac / Linux / Windows
主要语言
C#
星标
28.8k
派生
4.9k
平均合并
2 天 17 小时
30 天内合并 PR
48

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/semantic-kernel 的其他 Issue

查看 microsoft/semantic-kernel 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。