From 4b9140284b9386747656d2b3b6cf707e6ff00121 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:16:44 +0000 Subject: [PATCH 1/4] feat(client): support results endpoint (#835) --- .stats.yml | 2 +- api.md | 4 +-- src/anthropic/_response.py | 4 +-- .../resources/beta/messages/batches.py | 4 +-- src/anthropic/resources/messages/batches.py | 36 +++---------------- .../beta/messages/test_batches.py | 6 ++-- tests/api_resources/messages/test_batches.py | 23 +++--------- 7 files changed, 18 insertions(+), 61 deletions(-) diff --git a/.stats.yml b/.stats.yml index 239e17b..c809f63 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 21 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-75f0573c3d6d79650bcbd8b1b4fcf93ce146d567afeb1061cd4afccf8d1d6799.yml diff --git a/api.md b/api.md index 44f97ac..de23917 100644 --- a/api.md +++ b/api.md @@ -95,7 +95,7 @@ Methods: - client.messages.batches.list(\*\*params) -> SyncPage[MessageBatch] - client.messages.batches.delete(message_batch_id) -> DeletedMessageBatch - client.messages.batches.cancel(message_batch_id) -> MessageBatch -- client.messages.batches.results(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse] +- client.messages.batches.results(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse] # Models @@ -218,4 +218,4 @@ Methods: - client.beta.messages.batches.list(\*\*params) -> SyncPage[BetaMessageBatch] - client.beta.messages.batches.delete(message_batch_id) -> BetaDeletedMessageBatch - client.beta.messages.batches.cancel(message_batch_id) -> BetaMessageBatch -- client.beta.messages.batches.results(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse] +- client.beta.messages.batches.results(message_batch_id) -> JSONLDecoder[BetaMessageBatchIndividualResponse] diff --git a/src/anthropic/_response.py b/src/anthropic/_response.py index 830bee5..40f7995 100644 --- a/src/anthropic/_response.py +++ b/src/anthropic/_response.py @@ -140,7 +140,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: origin = get_origin(cast_to) or cast_to if inspect.isclass(origin): - if issubclass(origin, (JSONLDecoder)): + if issubclass(cast(Any, origin), JSONLDecoder): return cast( R, cast("type[JSONLDecoder[Any]]", cast_to)( @@ -150,7 +150,7 @@ def _parse(self, *, to: type[_T] | None = None) -> R | _T: ), ) - if issubclass(origin, AsyncJSONLDecoder): + if issubclass(cast(Any, origin), AsyncJSONLDecoder): return cast( R, cast("type[AsyncJSONLDecoder[Any]]", cast_to)( diff --git a/src/anthropic/resources/beta/messages/batches.py b/src/anthropic/resources/beta/messages/batches.py index 3a13812..850ed70 100644 --- a/src/anthropic/resources/beta/messages/batches.py +++ b/src/anthropic/resources/beta/messages/batches.py @@ -395,8 +395,8 @@ def results( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - stream=True, cast_to=JSONLDecoder[BetaMessageBatchIndividualResponse], + stream=True, ) @@ -764,8 +764,8 @@ async def results( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - stream=True, cast_to=AsyncJSONLDecoder[BetaMessageBatchIndividualResponse], + stream=True, ) diff --git a/src/anthropic/resources/messages/batches.py b/src/anthropic/resources/messages/batches.py index 7092730..14338ac 100644 --- a/src/anthropic/resources/messages/batches.py +++ b/src/anthropic/resources/messages/batches.py @@ -14,25 +14,15 @@ ) from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource -from ..._response import ( - BinaryAPIResponse, - AsyncBinaryAPIResponse, - StreamedBinaryAPIResponse, - AsyncStreamedBinaryAPIResponse, - to_streamed_response_wrapper, - to_custom_raw_response_wrapper, - async_to_streamed_response_wrapper, - to_custom_streamed_response_wrapper, - async_to_custom_raw_response_wrapper, - async_to_custom_streamed_response_wrapper, -) +from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper from ...pagination import SyncPage, AsyncPage from ..._exceptions import AnthropicError from ..._base_client import AsyncPaginator, make_request_options -from ...types.messages import MessageBatchIndividualResponse, batch_list_params, batch_create_params +from ...types.messages import batch_list_params, batch_create_params from ..._decoders.jsonl import JSONLDecoder, AsyncJSONLDecoder from ...types.messages.message_batch import MessageBatch from ...types.messages.deleted_message_batch import DeletedMessageBatch +from ...types.messages.message_batch_individual_response import MessageBatchIndividualResponse __all__ = ["Batches", "AsyncBatches"] @@ -317,8 +307,8 @@ def results( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - stream=True, cast_to=JSONLDecoder[MessageBatchIndividualResponse], + stream=True, ) @@ -602,8 +592,8 @@ async def results( options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - stream=True, cast_to=AsyncJSONLDecoder[MessageBatchIndividualResponse], + stream=True, ) @@ -626,10 +616,6 @@ def __init__(self, batches: Batches) -> None: self.cancel = _legacy_response.to_raw_response_wrapper( batches.cancel, ) - self.results = to_custom_raw_response_wrapper( - batches.results, - BinaryAPIResponse, - ) class AsyncBatchesWithRawResponse: @@ -651,10 +637,6 @@ def __init__(self, batches: AsyncBatches) -> None: self.cancel = _legacy_response.async_to_raw_response_wrapper( batches.cancel, ) - self.results = async_to_custom_raw_response_wrapper( - batches.results, - AsyncBinaryAPIResponse, - ) class BatchesWithStreamingResponse: @@ -676,10 +658,6 @@ def __init__(self, batches: Batches) -> None: self.cancel = to_streamed_response_wrapper( batches.cancel, ) - self.results = to_custom_streamed_response_wrapper( - batches.results, - StreamedBinaryAPIResponse, - ) class AsyncBatchesWithStreamingResponse: @@ -701,7 +679,3 @@ def __init__(self, batches: AsyncBatches) -> None: self.cancel = async_to_streamed_response_wrapper( batches.cancel, ) - self.results = async_to_custom_streamed_response_wrapper( - batches.results, - AsyncStreamedBinaryAPIResponse, - ) diff --git a/tests/api_resources/beta/messages/test_batches.py b/tests/api_resources/beta/messages/test_batches.py index 1e5e856..bb28454 100644 --- a/tests/api_resources/beta/messages/test_batches.py +++ b/tests/api_resources/beta/messages/test_batches.py @@ -18,8 +18,6 @@ BetaDeletedMessageBatch, ) -# pyright: reportDeprecated=false - base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -363,8 +361,8 @@ def test_method_results(self, client: Anthropic, respx_mock: MockRouter) -> None assert i == 1 assert results.http_response.is_stream_consumed + @pytest.mark.skip(reason="Prism doesn't support JSONL responses yet") @parametrize - @pytest.mark.respx(base_url=base_url) def test_path_params_results(self, client: Anthropic) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): client.beta.messages.batches.results( @@ -713,8 +711,8 @@ async def test_method_results(self, async_client: AsyncAnthropic, respx_mock: Mo assert i == 1 assert results.http_response.is_stream_consumed + @pytest.mark.skip(reason="Prism doesn't support JSONL responses yet") @parametrize - @pytest.mark.respx(base_url=base_url) async def test_path_params_results(self, async_client: AsyncAnthropic) -> None: with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): await async_client.beta.messages.batches.results( diff --git a/tests/api_resources/messages/test_batches.py b/tests/api_resources/messages/test_batches.py index 96bb529..de84b3c 100644 --- a/tests/api_resources/messages/test_batches.py +++ b/tests/api_resources/messages/test_batches.py @@ -12,9 +12,10 @@ from anthropic import Anthropic, AsyncAnthropic from tests.utils import assert_matches_type from anthropic.pagination import SyncPage, AsyncPage -from anthropic.types.messages import MessageBatch, DeletedMessageBatch - -# pyright: reportDeprecated=false +from anthropic.types.messages import ( + MessageBatch, + DeletedMessageBatch, +) base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -273,14 +274,6 @@ def test_method_results(self, client: Anthropic, respx_mock: MockRouter) -> None assert i == 1 assert results.http_response.is_stream_consumed - @parametrize - @pytest.mark.respx(base_url=base_url) - def test_path_params_results(self, client: Anthropic) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): - client.messages.batches.with_raw_response.results( - "", - ) - class TestAsyncBatches: parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) @@ -535,11 +528,3 @@ async def test_method_results(self, async_client: AsyncAnthropic, respx_mock: Mo assert i == 1 assert results.http_response.is_stream_consumed - - @parametrize - @pytest.mark.respx(base_url=base_url) - async def test_path_params_results(self, async_client: AsyncAnthropic) -> None: - with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_batch_id` but received ''"): - await async_client.messages.batches.with_raw_response.results( - "", - ) From bb1f52bfba3eb029942b71c1544021dd42f88651 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 12:39:45 +0000 Subject: [PATCH 2/4] chore(internal): minor formatting changes (#838) --- .github/workflows/ci.yml | 2 +- scripts/bootstrap | 2 +- scripts/lint | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 978fcec..02e0b6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,7 @@ jobs: - name: Run lints run: ./scripts/lint + test: name: test runs-on: ubuntu-latest @@ -51,4 +52,3 @@ jobs: - name: Run tests run: ./scripts/test - diff --git a/scripts/bootstrap b/scripts/bootstrap index 8c5c60e..e84fe62 100755 --- a/scripts/bootstrap +++ b/scripts/bootstrap @@ -4,7 +4,7 @@ set -e cd "$(dirname "$0")/.." -if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then +if ! command -v rye >/dev/null 2>&1 && [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then brew bundle check >/dev/null 2>&1 || { echo "==> Installing Homebrew dependencies…" brew bundle diff --git a/scripts/lint b/scripts/lint index 34be434..159fd68 100755 --- a/scripts/lint +++ b/scripts/lint @@ -9,4 +9,3 @@ rye run lint echo "==> Making sure it imports" rye run python -c 'import anthropic' - From 67aa83e5d589f6afad5fbc8bd2e616cc71a80a29 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:48:25 +0000 Subject: [PATCH 3/4] feat(api): add citations (#839) --- .stats.yml | 2 +- api.md | 26 ++++++++ .../resources/beta/messages/batches.py | 16 ++--- src/anthropic/resources/messages/batches.py | 16 ++--- src/anthropic/types/__init__.py | 15 +++++ src/anthropic/types/beta/__init__.py | 17 ++++++ .../types/beta/beta_base64_pdf_block_param.py | 19 ++++-- .../types/beta/beta_citation_char_location.py | 22 +++++++ .../beta/beta_citation_char_location_param.py | 22 +++++++ .../beta_citation_content_block_location.py | 22 +++++++ ...a_citation_content_block_location_param.py | 22 +++++++ .../types/beta/beta_citation_page_location.py | 22 +++++++ .../beta/beta_citation_page_location_param.py | 22 +++++++ .../types/beta/beta_citations_config_param.py | 11 ++++ .../types/beta/beta_citations_delta.py | 23 +++++++ ...beta_content_block_source_content_param.py | 13 ++++ .../beta/beta_content_block_source_param.py | 16 +++++ .../beta/beta_plain_text_source_param.py | 15 +++++ .../beta_raw_content_block_delta_event.py | 8 ++- src/anthropic/types/beta/beta_text_block.py | 10 ++++ .../types/beta/beta_text_block_param.py | 5 +- .../types/beta/beta_text_citation.py | 16 +++++ .../types/beta/beta_text_citation_param.py | 16 +++++ src/anthropic/types/citation_char_location.py | 22 +++++++ .../types/citation_char_location_param.py | 22 +++++++ .../types/citation_content_block_location.py | 22 +++++++ .../citation_content_block_location_param.py | 22 +++++++ src/anthropic/types/citation_page_location.py | 22 +++++++ .../types/citation_page_location_param.py | 22 +++++++ src/anthropic/types/citations_config_param.py | 11 ++++ src/anthropic/types/citations_delta.py | 22 +++++++ .../content_block_source_content_param.py | 13 ++++ .../types/content_block_source_param.py | 16 +++++ src/anthropic/types/document_block_param.py | 19 ++++-- .../types/plain_text_source_param.py | 15 +++++ .../types/raw_content_block_delta_event.py | 6 +- src/anthropic/types/text_block.py | 10 ++++ src/anthropic/types/text_block_param.py | 5 +- src/anthropic/types/text_citation.py | 15 +++++ src/anthropic/types/text_citation_param.py | 16 +++++ .../beta/messages/test_batches.py | 20 +++++++ tests/api_resources/beta/test_messages.py | 60 +++++++++++++++++++ tests/api_resources/test_messages.py | 60 +++++++++++++++++++ 43 files changed, 765 insertions(+), 31 deletions(-) create mode 100644 src/anthropic/types/beta/beta_citation_char_location.py create mode 100644 src/anthropic/types/beta/beta_citation_char_location_param.py create mode 100644 src/anthropic/types/beta/beta_citation_content_block_location.py create mode 100644 src/anthropic/types/beta/beta_citation_content_block_location_param.py create mode 100644 src/anthropic/types/beta/beta_citation_page_location.py create mode 100644 src/anthropic/types/beta/beta_citation_page_location_param.py create mode 100644 src/anthropic/types/beta/beta_citations_config_param.py create mode 100644 src/anthropic/types/beta/beta_citations_delta.py create mode 100644 src/anthropic/types/beta/beta_content_block_source_content_param.py create mode 100644 src/anthropic/types/beta/beta_content_block_source_param.py create mode 100644 src/anthropic/types/beta/beta_plain_text_source_param.py create mode 100644 src/anthropic/types/beta/beta_text_citation.py create mode 100644 src/anthropic/types/beta/beta_text_citation_param.py create mode 100644 src/anthropic/types/citation_char_location.py create mode 100644 src/anthropic/types/citation_char_location_param.py create mode 100644 src/anthropic/types/citation_content_block_location.py create mode 100644 src/anthropic/types/citation_content_block_location_param.py create mode 100644 src/anthropic/types/citation_page_location.py create mode 100644 src/anthropic/types/citation_page_location_param.py create mode 100644 src/anthropic/types/citations_config_param.py create mode 100644 src/anthropic/types/citations_delta.py create mode 100644 src/anthropic/types/content_block_source_content_param.py create mode 100644 src/anthropic/types/content_block_source_param.py create mode 100644 src/anthropic/types/plain_text_source_param.py create mode 100644 src/anthropic/types/text_citation.py create mode 100644 src/anthropic/types/text_citation_param.py diff --git a/.stats.yml b/.stats.yml index c809f63..e7d0669 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 21 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-75f0573c3d6d79650bcbd8b1b4fcf93ce146d567afeb1061cd4afccf8d1d6799.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-7270ee0a79d885681ee507414608229f61c27f47c40f355dcd210b38aa7cddf1.yml diff --git a/api.md b/api.md index de23917..10b0770 100644 --- a/api.md +++ b/api.md @@ -24,9 +24,19 @@ Types: from anthropic.types import ( Base64PDFSource, CacheControlEphemeral, + CitationCharLocation, + CitationCharLocationParam, + CitationContentBlockLocation, + CitationContentBlockLocationParam, + CitationPageLocation, + CitationPageLocationParam, + CitationsConfigParam, + CitationsDelta, ContentBlock, ContentBlockDeltaEvent, ContentBlockParam, + ContentBlockSource, + ContentBlockSourceContent, ContentBlockStartEvent, ContentBlockStopEvent, DocumentBlockParam, @@ -42,6 +52,7 @@ from anthropic.types import ( MessageTokensCount, Metadata, Model, + PlainTextSource, RawContentBlockDeltaEvent, RawContentBlockStartEvent, RawContentBlockStopEvent, @@ -51,6 +62,8 @@ from anthropic.types import ( RawMessageStreamEvent, TextBlock, TextBlockParam, + TextCitation, + TextCitationParam, TextDelta, Tool, ToolChoice, @@ -153,8 +166,18 @@ from anthropic.types.beta import ( BetaBase64PDFBlock, BetaBase64PDFSource, BetaCacheControlEphemeral, + BetaCitationCharLocation, + BetaCitationCharLocationParam, + BetaCitationContentBlockLocation, + BetaCitationContentBlockLocationParam, + BetaCitationPageLocation, + BetaCitationPageLocationParam, + BetaCitationsConfigParam, + BetaCitationsDelta, BetaContentBlock, BetaContentBlockParam, + BetaContentBlockSource, + BetaContentBlockSourceContent, BetaImageBlockParam, BetaInputJSONDelta, BetaMessage, @@ -162,6 +185,7 @@ from anthropic.types.beta import ( BetaMessageParam, BetaMessageTokensCount, BetaMetadata, + BetaPlainTextSource, BetaRawContentBlockDeltaEvent, BetaRawContentBlockStartEvent, BetaRawContentBlockStopEvent, @@ -171,6 +195,8 @@ from anthropic.types.beta import ( BetaRawMessageStreamEvent, BetaTextBlock, BetaTextBlockParam, + BetaTextCitation, + BetaTextCitationParam, BetaTextDelta, BetaTool, BetaToolBash20241022, diff --git a/src/anthropic/resources/beta/messages/batches.py b/src/anthropic/resources/beta/messages/batches.py index 850ed70..63ea0d1 100644 --- a/src/anthropic/resources/beta/messages/batches.py +++ b/src/anthropic/resources/beta/messages/batches.py @@ -239,11 +239,11 @@ def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> BetaDeletedMessageBatch: - """This endpoint is idempotent and can be used to poll for Message Batch - completion. + """ + Delete a Message Batch. - To access the results of a Message Batch, make a request to the - `results_url` field in the response. + Message Batches can only be deleted once they've finished processing. If you'd + like to delete an in-progress batch, you must first cancel it. Args: message_batch_id: ID of the Message Batch. @@ -608,11 +608,11 @@ async def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> BetaDeletedMessageBatch: - """This endpoint is idempotent and can be used to poll for Message Batch - completion. + """ + Delete a Message Batch. - To access the results of a Message Batch, make a request to the - `results_url` field in the response. + Message Batches can only be deleted once they've finished processing. If you'd + like to delete an in-progress batch, you must first cancel it. Args: message_batch_id: ID of the Message Batch. diff --git a/src/anthropic/resources/messages/batches.py b/src/anthropic/resources/messages/batches.py index 14338ac..3cb7260 100644 --- a/src/anthropic/resources/messages/batches.py +++ b/src/anthropic/resources/messages/batches.py @@ -192,11 +192,11 @@ def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> DeletedMessageBatch: - """This endpoint is idempotent and can be used to poll for Message Batch - completion. + """ + Delete a Message Batch. - To access the results of a Message Batch, make a request to the - `results_url` field in the response. + Message Batches can only be deleted once they've finished processing. If you'd + like to delete an in-progress batch, you must first cancel it. Args: message_batch_id: ID of the Message Batch. @@ -477,11 +477,11 @@ async def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, ) -> DeletedMessageBatch: - """This endpoint is idempotent and can be used to poll for Message Batch - completion. + """ + Delete a Message Batch. - To access the results of a Message Batch, make a request to the - `results_url` field in the response. + Message Batches can only be deleted once they've finished processing. If you'd + like to delete an in-progress batch, you must first cancel it. Args: message_batch_id: ID of the Message Batch. diff --git a/src/anthropic/types/__init__.py b/src/anthropic/types/__init__.py index a880b82..5d7d3d7 100644 --- a/src/anthropic/types/__init__.py +++ b/src/anthropic/types/__init__.py @@ -27,9 +27,11 @@ from .model_param import ModelParam as ModelParam from .content_block import ContentBlock as ContentBlock from .message_param import MessageParam as MessageParam +from .text_citation import TextCitation as TextCitation from .beta_api_error import BetaAPIError as BetaAPIError from .metadata_param import MetadataParam as MetadataParam from .tool_use_block import ToolUseBlock as ToolUseBlock +from .citations_delta import CitationsDelta as CitationsDelta from .input_json_delta import InputJSONDelta as InputJSONDelta from .text_block_param import TextBlockParam as TextBlockParam from .image_block_param import ImageBlockParam as ImageBlockParam @@ -42,6 +44,7 @@ from .message_delta_event import MessageDeltaEvent as MessageDeltaEvent from .message_delta_usage import MessageDeltaUsage as MessageDeltaUsage from .message_start_event import MessageStartEvent as MessageStartEvent +from .text_citation_param import TextCitationParam as TextCitationParam from .anthropic_beta_param import AnthropicBetaParam as AnthropicBetaParam from .beta_not_found_error import BetaNotFoundError as BetaNotFoundError from .document_block_param import DocumentBlockParam as DocumentBlockParam @@ -53,10 +56,14 @@ from .beta_rate_limit_error import BetaRateLimitError as BetaRateLimitError from .message_create_params import MessageCreateParams as MessageCreateParams from .tool_choice_any_param import ToolChoiceAnyParam as ToolChoiceAnyParam +from .citation_char_location import CitationCharLocation as CitationCharLocation +from .citation_page_location import CitationPageLocation as CitationPageLocation +from .citations_config_param import CitationsConfigParam as CitationsConfigParam from .raw_message_stop_event import RawMessageStopEvent as RawMessageStopEvent from .tool_choice_auto_param import ToolChoiceAutoParam as ToolChoiceAutoParam from .tool_choice_tool_param import ToolChoiceToolParam as ToolChoiceToolParam from .base64_pdf_source_param import Base64PDFSourceParam as Base64PDFSourceParam +from .plain_text_source_param import PlainTextSourceParam as PlainTextSourceParam from .raw_message_delta_event import RawMessageDeltaEvent as RawMessageDeltaEvent from .raw_message_start_event import RawMessageStartEvent as RawMessageStartEvent from .tool_result_block_param import ToolResultBlockParam as ToolResultBlockParam @@ -68,8 +75,16 @@ from .content_block_start_event import ContentBlockStartEvent as ContentBlockStartEvent from .beta_gateway_timeout_error import BetaGatewayTimeoutError as BetaGatewayTimeoutError from .beta_invalid_request_error import BetaInvalidRequestError as BetaInvalidRequestError +from .content_block_source_param import ContentBlockSourceParam as ContentBlockSourceParam from .message_count_tokens_params import MessageCountTokensParams as MessageCountTokensParams +from .citation_char_location_param import CitationCharLocationParam as CitationCharLocationParam +from .citation_page_location_param import CitationPageLocationParam as CitationPageLocationParam from .raw_content_block_stop_event import RawContentBlockStopEvent as RawContentBlockStopEvent from .cache_control_ephemeral_param import CacheControlEphemeralParam as CacheControlEphemeralParam from .raw_content_block_delta_event import RawContentBlockDeltaEvent as RawContentBlockDeltaEvent from .raw_content_block_start_event import RawContentBlockStartEvent as RawContentBlockStartEvent +from .citation_content_block_location import CitationContentBlockLocation as CitationContentBlockLocation +from .content_block_source_content_param import ContentBlockSourceContentParam as ContentBlockSourceContentParam +from .citation_content_block_location_param import ( + CitationContentBlockLocationParam as CitationContentBlockLocationParam, +) diff --git a/src/anthropic/types/beta/__init__.py b/src/anthropic/types/beta/__init__.py index c233d9c..142f24a 100644 --- a/src/anthropic/types/beta/__init__.py +++ b/src/anthropic/types/beta/__init__.py @@ -11,8 +11,10 @@ from .model_list_params import ModelListParams as ModelListParams from .beta_content_block import BetaContentBlock as BetaContentBlock from .beta_message_param import BetaMessageParam as BetaMessageParam +from .beta_text_citation import BetaTextCitation as BetaTextCitation from .beta_metadata_param import BetaMetadataParam as BetaMetadataParam from .beta_tool_use_block import BetaToolUseBlock as BetaToolUseBlock +from .beta_citations_delta import BetaCitationsDelta as BetaCitationsDelta from .beta_input_json_delta import BetaInputJSONDelta as BetaInputJSONDelta from .beta_text_block_param import BetaTextBlockParam as BetaTextBlockParam from .beta_tool_union_param import BetaToolUnionParam as BetaToolUnionParam @@ -21,23 +23,38 @@ from .beta_tool_choice_param import BetaToolChoiceParam as BetaToolChoiceParam from .beta_content_block_param import BetaContentBlockParam as BetaContentBlockParam from .beta_message_delta_usage import BetaMessageDeltaUsage as BetaMessageDeltaUsage +from .beta_text_citation_param import BetaTextCitationParam as BetaTextCitationParam from .beta_message_tokens_count import BetaMessageTokensCount as BetaMessageTokensCount from .beta_tool_use_block_param import BetaToolUseBlockParam as BetaToolUseBlockParam from .beta_tool_choice_any_param import BetaToolChoiceAnyParam as BetaToolChoiceAnyParam from .beta_base64_pdf_block_param import BetaBase64PDFBlockParam as BetaBase64PDFBlockParam +from .beta_citation_char_location import BetaCitationCharLocation as BetaCitationCharLocation +from .beta_citation_page_location import BetaCitationPageLocation as BetaCitationPageLocation +from .beta_citations_config_param import BetaCitationsConfigParam as BetaCitationsConfigParam from .beta_raw_message_stop_event import BetaRawMessageStopEvent as BetaRawMessageStopEvent from .beta_tool_choice_auto_param import BetaToolChoiceAutoParam as BetaToolChoiceAutoParam from .beta_tool_choice_tool_param import BetaToolChoiceToolParam as BetaToolChoiceToolParam from .message_count_tokens_params import MessageCountTokensParams as MessageCountTokensParams from .beta_base64_pdf_source_param import BetaBase64PDFSourceParam as BetaBase64PDFSourceParam +from .beta_plain_text_source_param import BetaPlainTextSourceParam as BetaPlainTextSourceParam from .beta_raw_message_delta_event import BetaRawMessageDeltaEvent as BetaRawMessageDeltaEvent from .beta_raw_message_start_event import BetaRawMessageStartEvent as BetaRawMessageStartEvent from .beta_tool_result_block_param import BetaToolResultBlockParam as BetaToolResultBlockParam from .beta_raw_message_stream_event import BetaRawMessageStreamEvent as BetaRawMessageStreamEvent from .beta_tool_bash_20241022_param import BetaToolBash20241022Param as BetaToolBash20241022Param +from .beta_content_block_source_param import BetaContentBlockSourceParam as BetaContentBlockSourceParam +from .beta_citation_char_location_param import BetaCitationCharLocationParam as BetaCitationCharLocationParam +from .beta_citation_page_location_param import BetaCitationPageLocationParam as BetaCitationPageLocationParam from .beta_raw_content_block_stop_event import BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent from .beta_cache_control_ephemeral_param import BetaCacheControlEphemeralParam as BetaCacheControlEphemeralParam from .beta_raw_content_block_delta_event import BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent from .beta_raw_content_block_start_event import BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent +from .beta_citation_content_block_location import BetaCitationContentBlockLocation as BetaCitationContentBlockLocation from .beta_tool_text_editor_20241022_param import BetaToolTextEditor20241022Param as BetaToolTextEditor20241022Param from .beta_tool_computer_use_20241022_param import BetaToolComputerUse20241022Param as BetaToolComputerUse20241022Param +from .beta_content_block_source_content_param import ( + BetaContentBlockSourceContentParam as BetaContentBlockSourceContentParam, +) +from .beta_citation_content_block_location_param import ( + BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam, +) diff --git a/src/anthropic/types/beta/beta_base64_pdf_block_param.py b/src/anthropic/types/beta/beta_base64_pdf_block_param.py index 43a2132..dba8317 100644 --- a/src/anthropic/types/beta/beta_base64_pdf_block_param.py +++ b/src/anthropic/types/beta/beta_base64_pdf_block_param.py @@ -2,18 +2,29 @@ from __future__ import annotations -from typing import Optional -from typing_extensions import Literal, Required, TypedDict +from typing import Union, Optional +from typing_extensions import Literal, Required, TypeAlias, TypedDict +from .beta_citations_config_param import BetaCitationsConfigParam from .beta_base64_pdf_source_param import BetaBase64PDFSourceParam +from .beta_plain_text_source_param import BetaPlainTextSourceParam +from .beta_content_block_source_param import BetaContentBlockSourceParam from .beta_cache_control_ephemeral_param import BetaCacheControlEphemeralParam -__all__ = ["BetaBase64PDFBlockParam"] +__all__ = ["BetaBase64PDFBlockParam", "Source"] + +Source: TypeAlias = Union[BetaBase64PDFSourceParam, BetaPlainTextSourceParam, BetaContentBlockSourceParam] class BetaBase64PDFBlockParam(TypedDict, total=False): - source: Required[BetaBase64PDFSourceParam] + source: Required[Source] type: Required[Literal["document"]] cache_control: Optional[BetaCacheControlEphemeralParam] + + citations: BetaCitationsConfigParam + + context: Optional[str] + + title: Optional[str] diff --git a/src/anthropic/types/beta/beta_citation_char_location.py b/src/anthropic/types/beta/beta_citation_char_location.py new file mode 100644 index 0000000..2109949 --- /dev/null +++ b/src/anthropic/types/beta/beta_citation_char_location.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["BetaCitationCharLocation"] + + +class BetaCitationCharLocation(BaseModel): + cited_text: str + + document_index: int + + document_title: Optional[str] = None + + end_char_index: int + + start_char_index: int + + type: Literal["char_location"] diff --git a/src/anthropic/types/beta/beta_citation_char_location_param.py b/src/anthropic/types/beta/beta_citation_char_location_param.py new file mode 100644 index 0000000..8c09f5a --- /dev/null +++ b/src/anthropic/types/beta/beta_citation_char_location_param.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["BetaCitationCharLocationParam"] + + +class BetaCitationCharLocationParam(TypedDict, total=False): + cited_text: Required[str] + + document_index: Required[int] + + document_title: Required[Optional[str]] + + end_char_index: Required[int] + + start_char_index: Required[int] + + type: Required[Literal["char_location"]] diff --git a/src/anthropic/types/beta/beta_citation_content_block_location.py b/src/anthropic/types/beta/beta_citation_content_block_location.py new file mode 100644 index 0000000..8fde76f --- /dev/null +++ b/src/anthropic/types/beta/beta_citation_content_block_location.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["BetaCitationContentBlockLocation"] + + +class BetaCitationContentBlockLocation(BaseModel): + cited_text: str + + document_index: int + + document_title: Optional[str] = None + + end_block_index: int + + start_block_index: int + + type: Literal["content_block_location"] diff --git a/src/anthropic/types/beta/beta_citation_content_block_location_param.py b/src/anthropic/types/beta/beta_citation_content_block_location_param.py new file mode 100644 index 0000000..9e378a7 --- /dev/null +++ b/src/anthropic/types/beta/beta_citation_content_block_location_param.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["BetaCitationContentBlockLocationParam"] + + +class BetaCitationContentBlockLocationParam(TypedDict, total=False): + cited_text: Required[str] + + document_index: Required[int] + + document_title: Required[Optional[str]] + + end_block_index: Required[int] + + start_block_index: Required[int] + + type: Required[Literal["content_block_location"]] diff --git a/src/anthropic/types/beta/beta_citation_page_location.py b/src/anthropic/types/beta/beta_citation_page_location.py new file mode 100644 index 0000000..9e6f60d --- /dev/null +++ b/src/anthropic/types/beta/beta_citation_page_location.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from ..._models import BaseModel + +__all__ = ["BetaCitationPageLocation"] + + +class BetaCitationPageLocation(BaseModel): + cited_text: str + + document_index: int + + document_title: Optional[str] = None + + end_page_number: int + + start_page_number: int + + type: Literal["page_location"] diff --git a/src/anthropic/types/beta/beta_citation_page_location_param.py b/src/anthropic/types/beta/beta_citation_page_location_param.py new file mode 100644 index 0000000..60e5b1c --- /dev/null +++ b/src/anthropic/types/beta/beta_citation_page_location_param.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["BetaCitationPageLocationParam"] + + +class BetaCitationPageLocationParam(TypedDict, total=False): + cited_text: Required[str] + + document_index: Required[int] + + document_title: Required[Optional[str]] + + end_page_number: Required[int] + + start_page_number: Required[int] + + type: Required[Literal["page_location"]] diff --git a/src/anthropic/types/beta/beta_citations_config_param.py b/src/anthropic/types/beta/beta_citations_config_param.py new file mode 100644 index 0000000..409cfde --- /dev/null +++ b/src/anthropic/types/beta/beta_citations_config_param.py @@ -0,0 +1,11 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import TypedDict + +__all__ = ["BetaCitationsConfigParam"] + + +class BetaCitationsConfigParam(TypedDict, total=False): + enabled: bool diff --git a/src/anthropic/types/beta/beta_citations_delta.py b/src/anthropic/types/beta/beta_citations_delta.py new file mode 100644 index 0000000..2c6c02b --- /dev/null +++ b/src/anthropic/types/beta/beta_citations_delta.py @@ -0,0 +1,23 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Union +from typing_extensions import Literal, Annotated, TypeAlias + +from ..._utils import PropertyInfo +from ..._models import BaseModel +from .beta_citation_char_location import BetaCitationCharLocation +from .beta_citation_page_location import BetaCitationPageLocation +from .beta_citation_content_block_location import BetaCitationContentBlockLocation + +__all__ = ["BetaCitationsDelta", "Citation"] + +Citation: TypeAlias = Annotated[ + Union[BetaCitationCharLocation, BetaCitationPageLocation, BetaCitationContentBlockLocation], + PropertyInfo(discriminator="type"), +] + + +class BetaCitationsDelta(BaseModel): + citation: Citation + + type: Literal["citations_delta"] diff --git a/src/anthropic/types/beta/beta_content_block_source_content_param.py b/src/anthropic/types/beta/beta_content_block_source_content_param.py new file mode 100644 index 0000000..bc13b14 --- /dev/null +++ b/src/anthropic/types/beta/beta_content_block_source_content_param.py @@ -0,0 +1,13 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from typing_extensions import TypeAlias + +from .beta_text_block_param import BetaTextBlockParam +from .beta_image_block_param import BetaImageBlockParam + +__all__ = ["BetaContentBlockSourceContentParam"] + +BetaContentBlockSourceContentParam: TypeAlias = Union[BetaTextBlockParam, BetaImageBlockParam] diff --git a/src/anthropic/types/beta/beta_content_block_source_param.py b/src/anthropic/types/beta/beta_content_block_source_param.py new file mode 100644 index 0000000..512cf0d --- /dev/null +++ b/src/anthropic/types/beta/beta_content_block_source_param.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union, Iterable +from typing_extensions import Literal, Required, TypedDict + +from .beta_content_block_source_content_param import BetaContentBlockSourceContentParam + +__all__ = ["BetaContentBlockSourceParam"] + + +class BetaContentBlockSourceParam(TypedDict, total=False): + content: Required[Union[str, Iterable[BetaContentBlockSourceContentParam]]] + + type: Required[Literal["content"]] diff --git a/src/anthropic/types/beta/beta_plain_text_source_param.py b/src/anthropic/types/beta/beta_plain_text_source_param.py new file mode 100644 index 0000000..187a238 --- /dev/null +++ b/src/anthropic/types/beta/beta_plain_text_source_param.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["BetaPlainTextSourceParam"] + + +class BetaPlainTextSourceParam(TypedDict, total=False): + data: Required[str] + + media_type: Required[Literal["text/plain"]] + + type: Required[Literal["text"]] diff --git a/src/anthropic/types/beta/beta_raw_content_block_delta_event.py b/src/anthropic/types/beta/beta_raw_content_block_delta_event.py index 03ce655..cfe0a3b 100644 --- a/src/anthropic/types/beta/beta_raw_content_block_delta_event.py +++ b/src/anthropic/types/beta/beta_raw_content_block_delta_event.py @@ -1,15 +1,19 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from typing import Union -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Annotated, TypeAlias +from ..._utils import PropertyInfo from ..._models import BaseModel from .beta_text_delta import BetaTextDelta +from .beta_citations_delta import BetaCitationsDelta from .beta_input_json_delta import BetaInputJSONDelta __all__ = ["BetaRawContentBlockDeltaEvent", "Delta"] -Delta: TypeAlias = Union[BetaTextDelta, BetaInputJSONDelta] +Delta: TypeAlias = Annotated[ + Union[BetaTextDelta, BetaInputJSONDelta, BetaCitationsDelta], PropertyInfo(discriminator="type") +] class BetaRawContentBlockDeltaEvent(BaseModel): diff --git a/src/anthropic/types/beta/beta_text_block.py b/src/anthropic/types/beta/beta_text_block.py index 8c95d7a..f6374b4 100644 --- a/src/anthropic/types/beta/beta_text_block.py +++ b/src/anthropic/types/beta/beta_text_block.py @@ -1,13 +1,23 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from typing import List, Optional from typing_extensions import Literal from ..._models import BaseModel +from .beta_text_citation import BetaTextCitation __all__ = ["BetaTextBlock"] class BetaTextBlock(BaseModel): + citations: Optional[List[BetaTextCitation]] = None + """Citations supporting the text block. + + The type of citation returned will depend on the type of document being cited. + Citing a PDF results in `page_location`, plain text results in `char_location`, + and content document results in `content_block_location`. + """ + text: str type: Literal["text"] diff --git a/src/anthropic/types/beta/beta_text_block_param.py b/src/anthropic/types/beta/beta_text_block_param.py index 4dea557..e40b03a 100644 --- a/src/anthropic/types/beta/beta_text_block_param.py +++ b/src/anthropic/types/beta/beta_text_block_param.py @@ -2,9 +2,10 @@ from __future__ import annotations -from typing import Optional +from typing import Iterable, Optional from typing_extensions import Literal, Required, TypedDict +from .beta_text_citation_param import BetaTextCitationParam from .beta_cache_control_ephemeral_param import BetaCacheControlEphemeralParam __all__ = ["BetaTextBlockParam"] @@ -16,3 +17,5 @@ class BetaTextBlockParam(TypedDict, total=False): type: Required[Literal["text"]] cache_control: Optional[BetaCacheControlEphemeralParam] + + citations: Optional[Iterable[BetaTextCitationParam]] diff --git a/src/anthropic/types/beta/beta_text_citation.py b/src/anthropic/types/beta/beta_text_citation.py new file mode 100644 index 0000000..538878b --- /dev/null +++ b/src/anthropic/types/beta/beta_text_citation.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Union +from typing_extensions import Annotated, TypeAlias + +from ..._utils import PropertyInfo +from .beta_citation_char_location import BetaCitationCharLocation +from .beta_citation_page_location import BetaCitationPageLocation +from .beta_citation_content_block_location import BetaCitationContentBlockLocation + +__all__ = ["BetaTextCitation"] + +BetaTextCitation: TypeAlias = Annotated[ + Union[BetaCitationCharLocation, BetaCitationPageLocation, BetaCitationContentBlockLocation], + PropertyInfo(discriminator="type"), +] diff --git a/src/anthropic/types/beta/beta_text_citation_param.py b/src/anthropic/types/beta/beta_text_citation_param.py new file mode 100644 index 0000000..b04c330 --- /dev/null +++ b/src/anthropic/types/beta/beta_text_citation_param.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from typing_extensions import TypeAlias + +from .beta_citation_char_location_param import BetaCitationCharLocationParam +from .beta_citation_page_location_param import BetaCitationPageLocationParam +from .beta_citation_content_block_location_param import BetaCitationContentBlockLocationParam + +__all__ = ["BetaTextCitationParam"] + +BetaTextCitationParam: TypeAlias = Union[ + BetaCitationCharLocationParam, BetaCitationPageLocationParam, BetaCitationContentBlockLocationParam +] diff --git a/src/anthropic/types/citation_char_location.py b/src/anthropic/types/citation_char_location.py new file mode 100644 index 0000000..011b106 --- /dev/null +++ b/src/anthropic/types/citation_char_location.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from .._models import BaseModel + +__all__ = ["CitationCharLocation"] + + +class CitationCharLocation(BaseModel): + cited_text: str + + document_index: int + + document_title: Optional[str] = None + + end_char_index: int + + start_char_index: int + + type: Literal["char_location"] diff --git a/src/anthropic/types/citation_char_location_param.py b/src/anthropic/types/citation_char_location_param.py new file mode 100644 index 0000000..1cc1dfb --- /dev/null +++ b/src/anthropic/types/citation_char_location_param.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["CitationCharLocationParam"] + + +class CitationCharLocationParam(TypedDict, total=False): + cited_text: Required[str] + + document_index: Required[int] + + document_title: Required[Optional[str]] + + end_char_index: Required[int] + + start_char_index: Required[int] + + type: Required[Literal["char_location"]] diff --git a/src/anthropic/types/citation_content_block_location.py b/src/anthropic/types/citation_content_block_location.py new file mode 100644 index 0000000..0df0ce5 --- /dev/null +++ b/src/anthropic/types/citation_content_block_location.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from .._models import BaseModel + +__all__ = ["CitationContentBlockLocation"] + + +class CitationContentBlockLocation(BaseModel): + cited_text: str + + document_index: int + + document_title: Optional[str] = None + + end_block_index: int + + start_block_index: int + + type: Literal["content_block_location"] diff --git a/src/anthropic/types/citation_content_block_location_param.py b/src/anthropic/types/citation_content_block_location_param.py new file mode 100644 index 0000000..ee0a6a2 --- /dev/null +++ b/src/anthropic/types/citation_content_block_location_param.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["CitationContentBlockLocationParam"] + + +class CitationContentBlockLocationParam(TypedDict, total=False): + cited_text: Required[str] + + document_index: Required[int] + + document_title: Required[Optional[str]] + + end_block_index: Required[int] + + start_block_index: Required[int] + + type: Required[Literal["content_block_location"]] diff --git a/src/anthropic/types/citation_page_location.py b/src/anthropic/types/citation_page_location.py new file mode 100644 index 0000000..94c4d50 --- /dev/null +++ b/src/anthropic/types/citation_page_location.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from typing_extensions import Literal + +from .._models import BaseModel + +__all__ = ["CitationPageLocation"] + + +class CitationPageLocation(BaseModel): + cited_text: str + + document_index: int + + document_title: Optional[str] = None + + end_page_number: int + + start_page_number: int + + type: Literal["page_location"] diff --git a/src/anthropic/types/citation_page_location_param.py b/src/anthropic/types/citation_page_location_param.py new file mode 100644 index 0000000..483837b --- /dev/null +++ b/src/anthropic/types/citation_page_location_param.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Optional +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["CitationPageLocationParam"] + + +class CitationPageLocationParam(TypedDict, total=False): + cited_text: Required[str] + + document_index: Required[int] + + document_title: Required[Optional[str]] + + end_page_number: Required[int] + + start_page_number: Required[int] + + type: Required[Literal["page_location"]] diff --git a/src/anthropic/types/citations_config_param.py b/src/anthropic/types/citations_config_param.py new file mode 100644 index 0000000..817397f --- /dev/null +++ b/src/anthropic/types/citations_config_param.py @@ -0,0 +1,11 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import TypedDict + +__all__ = ["CitationsConfigParam"] + + +class CitationsConfigParam(TypedDict, total=False): + enabled: bool diff --git a/src/anthropic/types/citations_delta.py b/src/anthropic/types/citations_delta.py new file mode 100644 index 0000000..3eab03d --- /dev/null +++ b/src/anthropic/types/citations_delta.py @@ -0,0 +1,22 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Union +from typing_extensions import Literal, Annotated, TypeAlias + +from .._utils import PropertyInfo +from .._models import BaseModel +from .citation_char_location import CitationCharLocation +from .citation_page_location import CitationPageLocation +from .citation_content_block_location import CitationContentBlockLocation + +__all__ = ["CitationsDelta", "Citation"] + +Citation: TypeAlias = Annotated[ + Union[CitationCharLocation, CitationPageLocation, CitationContentBlockLocation], PropertyInfo(discriminator="type") +] + + +class CitationsDelta(BaseModel): + citation: Citation + + type: Literal["citations_delta"] diff --git a/src/anthropic/types/content_block_source_content_param.py b/src/anthropic/types/content_block_source_content_param.py new file mode 100644 index 0000000..0e70cd2 --- /dev/null +++ b/src/anthropic/types/content_block_source_content_param.py @@ -0,0 +1,13 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from typing_extensions import TypeAlias + +from .text_block_param import TextBlockParam +from .image_block_param import ImageBlockParam + +__all__ = ["ContentBlockSourceContentParam"] + +ContentBlockSourceContentParam: TypeAlias = Union[TextBlockParam, ImageBlockParam] diff --git a/src/anthropic/types/content_block_source_param.py b/src/anthropic/types/content_block_source_param.py new file mode 100644 index 0000000..8050f3e --- /dev/null +++ b/src/anthropic/types/content_block_source_param.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union, Iterable +from typing_extensions import Literal, Required, TypedDict + +from .content_block_source_content_param import ContentBlockSourceContentParam + +__all__ = ["ContentBlockSourceParam"] + + +class ContentBlockSourceParam(TypedDict, total=False): + content: Required[Union[str, Iterable[ContentBlockSourceContentParam]]] + + type: Required[Literal["content"]] diff --git a/src/anthropic/types/document_block_param.py b/src/anthropic/types/document_block_param.py index 57522e9..e116fa7 100644 --- a/src/anthropic/types/document_block_param.py +++ b/src/anthropic/types/document_block_param.py @@ -2,18 +2,29 @@ from __future__ import annotations -from typing import Optional -from typing_extensions import Literal, Required, TypedDict +from typing import Union, Optional +from typing_extensions import Literal, Required, TypeAlias, TypedDict +from .citations_config_param import CitationsConfigParam from .base64_pdf_source_param import Base64PDFSourceParam +from .plain_text_source_param import PlainTextSourceParam +from .content_block_source_param import ContentBlockSourceParam from .cache_control_ephemeral_param import CacheControlEphemeralParam -__all__ = ["DocumentBlockParam"] +__all__ = ["DocumentBlockParam", "Source"] + +Source: TypeAlias = Union[Base64PDFSourceParam, PlainTextSourceParam, ContentBlockSourceParam] class DocumentBlockParam(TypedDict, total=False): - source: Required[Base64PDFSourceParam] + source: Required[Source] type: Required[Literal["document"]] cache_control: Optional[CacheControlEphemeralParam] + + citations: CitationsConfigParam + + context: Optional[str] + + title: Optional[str] diff --git a/src/anthropic/types/plain_text_source_param.py b/src/anthropic/types/plain_text_source_param.py new file mode 100644 index 0000000..a2a3b8d --- /dev/null +++ b/src/anthropic/types/plain_text_source_param.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Literal, Required, TypedDict + +__all__ = ["PlainTextSourceParam"] + + +class PlainTextSourceParam(TypedDict, total=False): + data: Required[str] + + media_type: Required[Literal["text/plain"]] + + type: Required[Literal["text"]] diff --git a/src/anthropic/types/raw_content_block_delta_event.py b/src/anthropic/types/raw_content_block_delta_event.py index 8785197..b8e7b81 100644 --- a/src/anthropic/types/raw_content_block_delta_event.py +++ b/src/anthropic/types/raw_content_block_delta_event.py @@ -1,15 +1,17 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from typing import Union -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Annotated, TypeAlias +from .._utils import PropertyInfo from .._models import BaseModel from .text_delta import TextDelta +from .citations_delta import CitationsDelta from .input_json_delta import InputJSONDelta __all__ = ["RawContentBlockDeltaEvent", "Delta"] -Delta: TypeAlias = Union[TextDelta, InputJSONDelta] +Delta: TypeAlias = Annotated[Union[TextDelta, InputJSONDelta, CitationsDelta], PropertyInfo(discriminator="type")] class RawContentBlockDeltaEvent(BaseModel): diff --git a/src/anthropic/types/text_block.py b/src/anthropic/types/text_block.py index f06083d..ecdddb6 100644 --- a/src/anthropic/types/text_block.py +++ b/src/anthropic/types/text_block.py @@ -1,13 +1,23 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from typing import List, Optional from typing_extensions import Literal from .._models import BaseModel +from .text_citation import TextCitation __all__ = ["TextBlock"] class TextBlock(BaseModel): + citations: Optional[List[TextCitation]] = None + """Citations supporting the text block. + + The type of citation returned will depend on the type of document being cited. + Citing a PDF results in `page_location`, plain text results in `char_location`, + and content document results in `content_block_location`. + """ + text: str type: Literal["text"] diff --git a/src/anthropic/types/text_block_param.py b/src/anthropic/types/text_block_param.py index 0b27ee2..9215173 100644 --- a/src/anthropic/types/text_block_param.py +++ b/src/anthropic/types/text_block_param.py @@ -2,9 +2,10 @@ from __future__ import annotations -from typing import Optional +from typing import Iterable, Optional from typing_extensions import Literal, Required, TypedDict +from .text_citation_param import TextCitationParam from .cache_control_ephemeral_param import CacheControlEphemeralParam __all__ = ["TextBlockParam"] @@ -16,3 +17,5 @@ class TextBlockParam(TypedDict, total=False): type: Required[Literal["text"]] cache_control: Optional[CacheControlEphemeralParam] + + citations: Optional[Iterable[TextCitationParam]] diff --git a/src/anthropic/types/text_citation.py b/src/anthropic/types/text_citation.py new file mode 100644 index 0000000..159771a --- /dev/null +++ b/src/anthropic/types/text_citation.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Union +from typing_extensions import Annotated, TypeAlias + +from .._utils import PropertyInfo +from .citation_char_location import CitationCharLocation +from .citation_page_location import CitationPageLocation +from .citation_content_block_location import CitationContentBlockLocation + +__all__ = ["TextCitation"] + +TextCitation: TypeAlias = Annotated[ + Union[CitationCharLocation, CitationPageLocation, CitationContentBlockLocation], PropertyInfo(discriminator="type") +] diff --git a/src/anthropic/types/text_citation_param.py b/src/anthropic/types/text_citation_param.py new file mode 100644 index 0000000..8e98814 --- /dev/null +++ b/src/anthropic/types/text_citation_param.py @@ -0,0 +1,16 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Union +from typing_extensions import TypeAlias + +from .citation_char_location_param import CitationCharLocationParam +from .citation_page_location_param import CitationPageLocationParam +from .citation_content_block_location_param import CitationContentBlockLocationParam + +__all__ = ["TextCitationParam"] + +TextCitationParam: TypeAlias = Union[ + CitationCharLocationParam, CitationPageLocationParam, CitationContentBlockLocationParam +] diff --git a/tests/api_resources/beta/messages/test_batches.py b/tests/api_resources/beta/messages/test_batches.py index bb28454..3c06576 100644 --- a/tests/api_resources/beta/messages/test_batches.py +++ b/tests/api_resources/beta/messages/test_batches.py @@ -68,6 +68,16 @@ def test_method_create_with_all_params(self, client: Anthropic) -> None: "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], "temperature": 1, @@ -417,6 +427,16 @@ async def test_method_create_with_all_params(self, async_client: AsyncAnthropic) "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], "temperature": 1, diff --git a/tests/api_resources/beta/test_messages.py b/tests/api_resources/beta/test_messages.py index e203f74..1d6fae2 100644 --- a/tests/api_resources/beta/test_messages.py +++ b/tests/api_resources/beta/test_messages.py @@ -53,6 +53,16 @@ def test_method_create_with_all_params_overload_1(self, client: Anthropic) -> No "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -159,6 +169,16 @@ def test_method_create_with_all_params_overload_2(self, client: Anthropic) -> No "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -260,6 +280,16 @@ def test_method_count_tokens_with_all_params(self, client: Anthropic) -> None: "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], tool_choice={ @@ -364,6 +394,16 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -470,6 +510,16 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -571,6 +621,16 @@ async def test_method_count_tokens_with_all_params(self, async_client: AsyncAnth "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], tool_choice={ diff --git a/tests/api_resources/test_messages.py b/tests/api_resources/test_messages.py index eb8bafd..9fa312d 100644 --- a/tests/api_resources/test_messages.py +++ b/tests/api_resources/test_messages.py @@ -54,6 +54,16 @@ def test_method_create_with_all_params_overload_1(self, client: Anthropic) -> No "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -158,6 +168,16 @@ def test_method_create_with_all_params_overload_2(self, client: Anthropic) -> No "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -267,6 +287,16 @@ def test_method_count_tokens_with_all_params(self, client: Anthropic) -> None: "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], tool_choice={ @@ -369,6 +399,16 @@ async def test_method_create_with_all_params_overload_1(self, async_client: Asyn "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -473,6 +513,16 @@ async def test_method_create_with_all_params_overload_2(self, async_client: Asyn "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], temperature=1, @@ -582,6 +632,16 @@ async def test_method_count_tokens_with_all_params(self, async_client: AsyncAnth "text": "Today's date is 2024-06-01.", "type": "text", "cache_control": {"type": "ephemeral"}, + "citations": [ + { + "cited_text": "cited_text", + "document_index": 0, + "document_title": "x", + "end_char_index": 0, + "start_char_index": 0, + "type": "char_location", + } + ], } ], tool_choice={ From c5102baffb2ffdca05196d9d222dddbe173ccf1e Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:48:53 +0000 Subject: [PATCH 4/4] release: 0.45.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 14 ++++++++++++++ pyproject.toml | 2 +- src/anthropic/_version.py | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index cc51f6f..fc0d7ff 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.44.0" + ".": "0.45.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index dcffb96..0dfc5d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 0.45.0 (2025-01-23) + +Full Changelog: [v0.44.0...v0.45.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.44.0...v0.45.0) + +### Features + +* **api:** add citations ([#839](https://github.com/anthropics/anthropic-sdk-python/issues/839)) ([2ec74b6](https://github.com/anthropics/anthropic-sdk-python/commit/2ec74b6ff106c6e3d7d55e3c189e345098f8575e)) +* **client:** support results endpoint ([#835](https://github.com/anthropics/anthropic-sdk-python/issues/835)) ([5dd88bf](https://github.com/anthropics/anthropic-sdk-python/commit/5dd88bf2d20b8909736cc0bc1e81296ba6e322a9)) + + +### Chores + +* **internal:** minor formatting changes ([#838](https://github.com/anthropics/anthropic-sdk-python/issues/838)) ([31eb826](https://github.com/anthropics/anthropic-sdk-python/commit/31eb826deb96a17d3c0bb953c728f39412c12ada)) + ## 0.44.0 (2025-01-21) Full Changelog: [v0.43.1...v0.44.0](https://github.com/anthropics/anthropic-sdk-python/compare/v0.43.1...v0.44.0) diff --git a/pyproject.toml b/pyproject.toml index ba848c3..2fdb785 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "anthropic" -version = "0.44.0" +version = "0.45.0" description = "The official Python library for the anthropic API" dynamic = ["readme"] license = "MIT" diff --git a/src/anthropic/_version.py b/src/anthropic/_version.py index 3527ab6..29afc8b 100644 --- a/src/anthropic/_version.py +++ b/src/anthropic/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "anthropic" -__version__ = "0.44.0" # x-release-please-version +__version__ = "0.45.0" # x-release-please-version