NotRequired -> Required

This commit is contained in:
Chester Curme 2025-07-08 16:14:12 -04:00
parent 59b12f7e46
commit ac23607a61

View File

@ -4,50 +4,50 @@ import warnings
from typing import Any, Literal, Union from typing import Any, Literal, Union
from pydantic import TypeAdapter, ValidationError from pydantic import TypeAdapter, ValidationError
from typing_extensions import NotRequired, TypedDict from typing_extensions import Required, TypedDict
# Text and annotations # Text and annotations
class UrlCitation(TypedDict, total=False): class UrlCitation(TypedDict, total=False):
"""Citation from a URL.""" """Citation from a URL."""
type: Literal["url_citation"] type: Required[Literal["url_citation"]]
url: str url: Required[str]
"""Source URL.""" """Source URL."""
title: NotRequired[str] title: str
"""Source title.""" """Source title."""
cited_text: NotRequired[str] cited_text: str
"""Text from the source that is being cited.""" """Text from the source that is being cited."""
start_index: NotRequired[int] start_index: int
"""Start index of the response text for which the annotation applies.""" """Start index of the response text for which the annotation applies."""
end_index: NotRequired[int] end_index: int
"""End index of the response text for which the annotation applies.""" """End index of the response text for which the annotation applies."""
class DocumentCitation(TypedDict, total=False): class DocumentCitation(TypedDict, total=False):
"""Annotation for data from a document.""" """Annotation for data from a document."""
type: Literal["document_citation"] type: Required[Literal["document_citation"]]
title: NotRequired[str] title: str
"""Source title.""" """Source title."""
cited_text: NotRequired[str] cited_text: str
"""Text from the source that is being cited.""" """Text from the source that is being cited."""
start_index: NotRequired[int] start_index: int
"""Start index of the response text for which the annotation applies.""" """Start index of the response text for which the annotation applies."""
end_index: NotRequired[int] end_index: int
"""End index of the response text for which the annotation applies.""" """End index of the response text for which the annotation applies."""
class NonStandardAnnotation(TypedDict, total=False): class NonStandardAnnotation(TypedDict):
"""Provider-specific annotation format.""" """Provider-specific annotation format."""
type: Literal["non_standard_annotation"] type: Literal["non_standard_annotation"]
@ -59,13 +59,11 @@ class NonStandardAnnotation(TypedDict, total=False):
class TextContentBlock(TypedDict, total=False): class TextContentBlock(TypedDict, total=False):
"""Content block for text output.""" """Content block for text output."""
type: Literal["text"] type: Required[Literal["text"]]
"""Type of the content block.""" """Type of the content block."""
text: str text: Required[str]
"""Block text.""" """Block text."""
annotations: NotRequired[ annotations: list[Union[UrlCitation, DocumentCitation, NonStandardAnnotation]]
list[Union[UrlCitation, DocumentCitation, NonStandardAnnotation]]
]
"""Citations and other annotations.""" """Citations and other annotations."""
@ -77,9 +75,9 @@ class ToolCallContentBlock(TypedDict, total=False):
message's ``tool_calls`` attribute. message's ``tool_calls`` attribute.
""" """
type: Literal["tool_call"] type: Required[Literal["tool_call"]]
"""Type of the content block.""" """Type of the content block."""
id: str id: Required[str]
"""Tool call ID.""" """Tool call ID."""
@ -87,9 +85,9 @@ class ToolCallContentBlock(TypedDict, total=False):
class ReasoningContentBlock(TypedDict, total=False): class ReasoningContentBlock(TypedDict, total=False):
"""Content block for reasoning output.""" """Content block for reasoning output."""
type: Literal["reasoning"] type: Required[Literal["reasoning"]]
"""Type of the content block.""" """Type of the content block."""
reasoning: NotRequired[str] reasoning: str
"""Reasoning text.""" """Reasoning text."""
@ -97,51 +95,51 @@ class ReasoningContentBlock(TypedDict, total=False):
class BaseDataContentBlock(TypedDict, total=False): class BaseDataContentBlock(TypedDict, total=False):
"""Base class for data content blocks.""" """Base class for data content blocks."""
mime_type: NotRequired[str] mime_type: str
"""MIME type of the content block (if needed).""" """MIME type of the content block (if needed)."""
class URLContentBlock(BaseDataContentBlock): class URLContentBlock(BaseDataContentBlock):
"""Content block for data from a URL.""" """Content block for data from a URL."""
type: Literal["image", "audio", "file"] type: Required[Literal["image", "audio", "file"]]
"""Type of the content block.""" """Type of the content block."""
source_type: Literal["url"] source_type: Required[Literal["url"]]
"""Source type (url).""" """Source type (url)."""
url: str url: Required[str]
"""URL for data.""" """URL for data."""
class Base64ContentBlock(BaseDataContentBlock): class Base64ContentBlock(BaseDataContentBlock):
"""Content block for inline data from a base64 string.""" """Content block for inline data from a base64 string."""
type: Literal["image", "audio", "file"] type: Required[Literal["image", "audio", "file"]]
"""Type of the content block.""" """Type of the content block."""
source_type: Literal["base64"] source_type: Required[Literal["base64"]]
"""Source type (base64).""" """Source type (base64)."""
data: str data: Required[str]
"""Data as a base64 string.""" """Data as a base64 string."""
class PlainTextContentBlock(BaseDataContentBlock): class PlainTextContentBlock(BaseDataContentBlock):
"""Content block for plain text data (e.g., from a document).""" """Content block for plain text data (e.g., from a document)."""
type: Literal["file"] type: Required[Literal["file"]]
"""Type of the content block.""" """Type of the content block."""
source_type: Literal["text"] source_type: Required[Literal["text"]]
"""Source type (text).""" """Source type (text)."""
text: str text: Required[str]
"""Text data.""" """Text data."""
class IDContentBlock(TypedDict): class IDContentBlock(BaseDataContentBlock):
"""Content block for data specified by an identifier.""" """Content block for data specified by an identifier."""
type: Literal["image", "audio", "file"] type: Required[Literal["image", "audio", "file"]]
"""Type of the content block.""" """Type of the content block."""
source_type: Literal["id"] source_type: Required[Literal["id"]]
"""Source type (id).""" """Source type (id)."""
id: str id: Required[str]
"""Identifier for data source.""" """Identifier for data source."""
@ -156,7 +154,7 @@ _DataContentBlockAdapter: TypeAdapter[DataContentBlock] = TypeAdapter(DataConten
# Non-standard # Non-standard
class NonStandardContentBlock(TypedDict, total=False): class NonStandardContentBlock(TypedDict):
"""Content block provider-specific data. """Content block provider-specific data.
This block contains data for which there is not yet a standard type. This block contains data for which there is not yet a standard type.