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

オープン 初心者向け
#14,824 コメント 1 件 リアクション 0 件 担当者 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とプロンプトの往復で項目の型が保持されることを確認してください。また、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時間
マージ済み PR(30日)
48

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/semantic-kernel のほかの issue

microsoft/semantic-kernel の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。