Python: Bug: AnnotationContent and StreamingAnnotationContent to_element writes CitationType.X, so annotations in a rendered chat history fail to parse
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
Línea de trabajo
Empieza con los métodos to_element de AnnotationContent y StreamingAnnotationContent en el paquete de contenidos de Python, donde citation_type se escribe como atributo XML. Reproduce el caso serializando una anotación con tostring y analizándola de nuevo con from_element o ChatHistory.from_rendered_prompt. Está terminado cuando la ida y vuelta funciona desde la cadena serializada, con pruebas que cubran la ruta de la cadena y no solo el elemento en memoria.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
AnnotationContent.to_element() and StreamingAnnotationContent.to_element() store the CitationType enum object in the XML attribute:
if self.citation_type:
element.set("type", self.citation_type)
CitationType is a str, Enum. When the element is serialized, the attribute is written with the enum's str() form, CitationType.FILE_CITATION, not the value file_citation. from_element() then cannot read it back. Any chat message that has an annotation with a citation type breaks as soon as the history is rendered to a prompt string and parsed back (ChatHistory.from_rendered_prompt, which is what prompt templates use for {{$chat_history}} style messages).
The existing round trip tests pass because they never serialize the element to a string, so the enum object stays in memory.
To Reproduce
Run against current main (5b4a3269a), Python 3.13:
from semantic_kernel.contents import ChatHistory, ChatMessageContent, AuthorRole, TextContent
from semantic_kernel.contents.annotation_content import AnnotationContent, CitationType
msg = ChatMessageContent(
role=AuthorRole.ASSISTANT,
items=[
TextContent(text="see [1]"),
AnnotationContent(file_id="file-1", quote="q", start_index=4, end_index=7, citation_type=CitationType.FILE_CITATION),
],
)
history = ChatHistory(messages=[msg])
print(msg.to_prompt())
ChatHistory.from_rendered_prompt(str(history))
Output:
<message role="assistant"><text>see [1]</text><annotation type="CitationType.FILE_CITATION" file_id="file-1" quote="q" start_index="4" end_index="7"></annotation></message>
pydantic_core._pydantic_core.ValidationError: 1 validation error for AnnotationContent
type
Input should be 'url_citation', 'file_path', 'file_citation' or 'container_file_citation' [type=enum, input_value='CitationType.FILE_CITATION', input_type=str]
StreamingAnnotationContent has the same line and fails the same way:
from xml.etree.ElementTree import tostring, fromstring
from semantic_kernel.contents.streaming_annotation_content import StreamingAnnotationContent
c = StreamingAnnotationContent(file_id="f", citation_type=CitationType.FILE_CITATION)
StreamingAnnotationContent.from_element(fromstring(tostring(c.to_element(), encoding="unicode")))
Expected behavior
The attribute should be written as the enum value (type="file_citation") so that from_element can parse it. The fix is to use self.citation_type.value in both to_element methods.
I have a fix with tests ready and can open a PR.
Platform
- Language: Python
- Source: main branch (5b4a3269a)
- OS: Windows, Python 3.13
- Lenguaje dominante
- C#
- Estrellas
- 28.6k
- Forks
- 4.8k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 22
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/semantic-kernel
-
python triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
microsoft/semantic-kernel#14615 ·
Los mantenedores suelen responder en 3 días
-
Python: Bug: TimePlugin timeZoneOffset and timeZoneName always return an empty stringPosiblemente ocupada @jeevan1098 la tomó hace 1 día. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
microsoft/semantic-kernel#14583 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
.Net: gpt-image-1 is the default image model in the .NET OpenAI connector, and OpenAI shuts it down on October 23Posiblemente ocupada @nightcityblade la tomó hace 13 días. Abierto.NET triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
microsoft/semantic-kernel#14526 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
Python: VolatileMemoryStore.get_batch and get_nearest_matches ignore with_embeddings=False (deepcopy result is discarded)Posiblemente ocupada @VANDRANKI la tomó hace 15 días. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
microsoft/semantic-kernel#14522 ·
Los mantenedores suelen responder en 3 días
-
Python: VolatileMemoryStore.get_nearest_match returns an un-awaited coroutine instead of a (MemoryRecord, score) tuplePosiblemente ocupada @VANDRANKI la tomó hace 15 días. Abiertopython triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
microsoft/semantic-kernel#14521 ·
Los mantenedores suelen responder en 3 días
Todos los issues de microsoft/semantic-kernel
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
vzeol/DeployCraft#125 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
fboucher/2d6-dungeon-app#245 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
area: settings good first issue priority: p2 type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
AmineChr54/umbra#3 ·
Los mantenedores suelen responder en 1 día
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
7.0
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
unoplatform/uno.extensions#3253 ·
Los mantenedores suelen responder en 1 día