Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/semantic_kernel/contents/annotation_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def to_element(self) -> Element:
"""Convert the annotation content to an Element."""
element = Element(self.tag)
if self.citation_type:
element.set("type", self.citation_type)
element.set("type", self.citation_type.value)
if self.file_id:
element.set("file_id", self.file_id)
if self.quote:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def to_element(self) -> Element:
"""Convert the annotation content to an Element."""
element = Element(self.tag)
if self.citation_type:
element.set("type", self.citation_type)
element.set("type", self.citation_type.value)
if self.file_id:
element.set("file_id", self.file_id)
if self.quote:
Expand Down
17 changes: 17 additions & 0 deletions python/tests/unit/contents/test_annotation_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,20 @@ def test_to_dict_call(annotation):
"text": expected_text,
}
assert annotation.to_dict() == expected_dict


def test_element_roundtrip_through_serialized_xml():
"""Citation types must survive serialize -> parse, not just memory (#14590)."""
from xml.etree.ElementTree import fromstring, tostring

annotation = AnnotationContent(
file_id="file-1",
quote="q",
start_index=4,
end_index=7,
type=CitationType.FILE_CITATION.value,
)
element = annotation.to_element()
assert element.get("type") == "file_citation"
reparsed = AnnotationContent.from_element(fromstring(tostring(element)))
assert reparsed == annotation
17 changes: 17 additions & 0 deletions python/tests/unit/contents/test_streaming_annotation_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,20 @@ def test_to_dict_call(annotation):
"text": expected_text,
}
assert annotation.to_dict() == expected_dict


def test_element_roundtrip_through_serialized_xml():
"""Citation types must survive serialize -> parse, not just memory (#14590)."""
from xml.etree.ElementTree import fromstring, tostring

annotation = StreamingAnnotationContent(
file_id="file-1",
quote="q",
start_index=4,
end_index=7,
citation_type=CitationType.FILE_CITATION.value,
)
element = annotation.to_element()
assert element.get("type") == "file_citation"
reparsed = StreamingAnnotationContent.from_element(fromstring(tostring(element)))
assert reparsed == annotation
Loading