Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from typing_extensions import Literal

from ..._models import BaseModel
from .response_output_text import Annotation

__all__ = ["ResponseOutputTextAnnotationAddedEvent"]


class ResponseOutputTextAnnotationAddedEvent(BaseModel):
"""Emitted when an annotation is added to output text content."""

annotation: object
annotation: Annotation
"""The annotation object being added. (See annotation schema for details.)"""

annotation_index: int
Expand Down
25 changes: 25 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from openai._utils import PropertyInfo
from openai._compat import PYDANTIC_V1, parse_obj, model_dump, model_json
from openai._models import DISCRIMINATOR_CACHE, BaseModel, construct_type
from openai.types.responses import ResponseOutputTextAnnotationAddedEvent
from openai.types.responses.response_output_text import AnnotationURLCitation


class BasicModel(BaseModel):
Expand Down Expand Up @@ -961,3 +963,26 @@ def __getattr__(self, attr: str) -> Item: ...
assert model.a.prop == 1
assert isinstance(model.a, Item)
assert model.other == "foo"


def test_response_output_text_annotation_added_event_uses_annotation_union() -> None:
event = ResponseOutputTextAnnotationAddedEvent.model_validate(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the pydantic-version-neutral parser

This new test is run in the repo's Pydantic v1 job (scripts/test invokes nox -s test-pydantic-v1, and noxfile.py installs pydantic<2), but model_validate only exists on Pydantic v2 models and this project only shims dump methods on its v1 BaseModel. Under the v1 test job this line raises AttributeError before exercising the regression; use the already imported _compat.parse_obj/model_parse helper or skip the test for PYDANTIC_V1.

Useful? React with 👍 / 👎.

{
"annotation": {
"type": "url_citation",
"title": "Example",
"url": "https://example.com",
"start_index": 0,
"end_index": 7,
},
"annotation_index": 0,
"content_index": 0,
"item_id": "item_123",
"output_index": 0,
"sequence_number": 1,
"type": "response.output_text.annotation.added",
}
)

assert isinstance(event.annotation, AnnotationURLCitation)
assert event.annotation.url == "https://example.com"