Skip to content

Commit

Permalink
feat(client): support results endpoint (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jan 22, 2025
1 parent d212ec9 commit 5dd88bf
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Methods:
- <code title="get /v1/messages/batches">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">list</a>(\*\*<a href="src/anthropic/types/messages/batch_list_params.py">params</a>) -> <a href="./src/anthropic/types/messages/message_batch.py">SyncPage[MessageBatch]</a></code>
- <code title="delete /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">delete</a>(message_batch_id) -> <a href="./src/anthropic/types/messages/deleted_message_batch.py">DeletedMessageBatch</a></code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">cancel</a>(message_batch_id) -> <a href="./src/anthropic/types/messages/message_batch.py">MessageBatch</a></code>
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">results</a>(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse]</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/anthropic/resources/messages/batches.py">results</a>(message_batch_id) -> <a href="./src/anthropic/types/messages/message_batch_individual_response.py">JSONLDecoder[MessageBatchIndividualResponse]</a></code>

# Models

Expand Down Expand Up @@ -218,4 +218,4 @@ Methods:
- <code title="get /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">list</a>(\*\*<a href="src/anthropic/types/beta/messages/batch_list_params.py">params</a>) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch.py">SyncPage[BetaMessageBatch]</a></code>
- <code title="delete /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">delete</a>(message_batch_id) -> <a href="./src/anthropic/types/beta/messages/beta_deleted_message_batch.py">BetaDeletedMessageBatch</a></code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">cancel</a>(message_batch_id) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch.py">BetaMessageBatch</a></code>
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">results</a>(message_batch_id) -> JSONLDecoder[MessageBatchIndividualResponse]</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/anthropic/resources/beta/messages/batches.py">results</a>(message_batch_id) -> <a href="./src/anthropic/types/beta/messages/beta_message_batch_individual_response.py">JSONLDecoder[BetaMessageBatchIndividualResponse]</a></code>
4 changes: 2 additions & 2 deletions src/anthropic/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)(
Expand All @@ -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)(
Expand Down
4 changes: 2 additions & 2 deletions src/anthropic/resources/beta/messages/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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,
)


Expand Down
36 changes: 5 additions & 31 deletions src/anthropic/resources/messages/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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,
)


Expand Down Expand Up @@ -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,
)


Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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,
)
6 changes: 2 additions & 4 deletions tests/api_resources/beta/messages/test_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
BetaDeletedMessageBatch,
)

# pyright: reportDeprecated=false

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
23 changes: 4 additions & 19 deletions tests/api_resources/messages/test_batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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(
"",
)

0 comments on commit 5dd88bf

Please sign in to comment.