o
    +i                     @  s  d dl mZ d dlmZmZ d dlmZ d dlZddlm	Z	 ddl
mZmZmZmZmZmZmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddgZ5G dd deZ6G dd deZ7G dd dZ8G dd dZ9G dd dZ:G dd  d Z;dS )!    )annotations)ListIterable)chainN   )_legacy_response)BodyOmitQueryHeadersNotGivenomit	not_given)is_givenmaybe_transformstrip_not_givenasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)SyncPage	AsyncPage)AnthropicError)AsyncPaginatormake_request_options)JSONLDecoderAsyncJSONLDecoder)batch_list_paramsbatch_create_params)AnthropicBetaParam)BetaMessageBatch)BetaDeletedMessageBatch)"BetaMessageBatchIndividualResponseBatchesAsyncBatchesc                	   @     e Zd Zed.ddZed/ddZeddded	d0ddZeddded	d1ddZ	eeeedddedd2d$d%Z
eddded	d3d'd(Zeddded	d1d)d*Zeddded	d4d,d-ZdS )5r%   returnBatchesWithRawResponsec                 C     t | S a  
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
        )r)   self r.   f/var/www/html/psymed-ai/venv/lib/python3.10/site-packages/anthropic/resources/beta/messages/batches.pywith_raw_response      zBatches.with_raw_responseBatchesWithStreamingResponsec                 C  r*   z
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
        )r2   r,   r.   r.   r/   with_streaming_response(      zBatches.with_streaming_responseNbetasextra_headersextra_query
extra_bodytimeoutrequests%Iterable[batch_create_params.Request]r7   List[AnthropicBetaParam] | Omitr8   Headers | Noner9   Query | Noner:   Body | Noner;   'float | httpx.Timeout | None | NotGivenr"   c             	   C  sv   i t dt|rdtdd |D dgnti|pi }ddi|p$i }| jdtd|itjt	||||dt
d	S )
  
        Send a batch of Message creation requests.

        The Message Batches API can be used to process multiple Messages API requests at
        once. Once a Message Batch is created, it begins processing immediately. Batches
        can take up to 24 hours to complete.

        Learn more about the Message Batches API in our
        [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)

        Args:
          requests: List of requests for prompt completion. Each is an individual request to create
              a Message.

          betas: Optional header to specify the beta version(s) you want to use.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        anthropic-beta,c                 s      | ]}t |V  qd S Nstr.0er.   r.   r/   	<genexpr>X       z!Batches.create.<locals>.<genexpr>message-batches-2024-09-24/v1/messages/batches?beta=truer<   r8   r9   r:   r;   bodyoptionscast_to)r   r   joinr   r   _postr   r    BatchCreateParamsr   r"   r-   r<   r7   r8   r9   r:   r;   r.   r.   r/   create1   s(   $
zBatches.createmessage_batch_idrI   c                C     |s	t d|i tdt|rdtdd |D dgnti|p%i }ddi|p-i }| jd| dt||||d	td
S )  This endpoint is idempotent and can be used to poll for Message Batch
        completion.

        To access the results of a Message Batch, make a request to the
        `results_url` field in the response.

        Learn more about the Message Batches API in our
        [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)

        Args:
          message_batch_id: ID of the Message Batch.

          betas: Optional header to specify the beta version(s) you want to use.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        ?Expected a non-empty value for `message_batch_id` but received rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM      rN   z#Batches.retrieve.<locals>.<genexpr>rO   /v1/messages/batches/
?beta=truerQ   rT   rU   	
ValueErrorr   r   rV   r   r   _getr   r"   r-   r[   r7   r8   r9   r:   r;   r.   r.   r/   retrievei   *   "

zBatches.retrieveafter_id	before_idlimitr7   r8   r9   r:   r;   ri   
str | Omitrj   rk   
int | OmitSyncPage[BetaMessageBatch]c          	      C     i t dt|rdtdd |D dgnti|pi }ddi|p$i }| jdtt t||||t	|||dt
jdtd	S )
4  List all Message Batches within a Workspace.

        Most recently created batches are
        returned first.

        Learn more about the Message Batches API in our
        [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)

        Args:
          after_id: ID of the object to use as a cursor for pagination. When provided, returns the
              page of results immediately after this object.

          before_id: ID of the object to use as a cursor for pagination. When provided, returns the
              page of results immediately before this object.

          limit: Number of items to return per page.

              Defaults to `20`. Ranges from `1` to `1000`.

          betas: Optional header to specify the beta version(s) you want to use.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM      rN   zBatches.list.<locals>.<genexpr>rO   rP   ri   rj   rk   r8   r9   r:   r;   querypagerT   model)r   r   rV   r   r   _get_api_listr   r"   r   r   r   BatchListParams	r-   ri   rj   rk   r7   r8   r9   r:   r;   r.   r.   r/   list   <   +
zBatches.listr#   c                C  r\   )  
        Delete a Message Batch.

        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.

        Learn more about the Message Batches API in our
        [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)

        Args:
          message_batch_id: ID of the Message Batch.

          betas: Optional header to specify the beta version(s) you want to use.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        r^   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z!Batches.delete.<locals>.<genexpr>rO   r_   r`   rQ   ra   	rc   r   r   rV   r   r   _deleter   r#   re   r.   r.   r/   delete   rg   zBatches.deletec                C  r\   )r  Batches may be canceled any time before processing ends.

        Once cancellation is
        initiated, the batch enters a `canceling` state, at which time the system may
        complete any in-progress, non-interruptible requests before finalizing
        cancellation.

        The number of canceled requests is specified in `request_counts`. To determine
        which requests were canceled, check the individual results within the batch.
        Note that cancellation may not result in any canceled requests if they were
        non-interruptible.

        Learn more about the Message Batches API in our
        [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)

        Args:
          message_batch_id: ID of the Message Batch.

          betas: Optional header to specify the beta version(s) you want to use.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        r^   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM   N  rN   z!Batches.cancel.<locals>.<genexpr>rO   r_   /cancel?beta=truerQ   ra   	rc   r   r   rV   r   r   rW   r   r"   re   r.   r.   r/   cancel!  s*   (

zBatches.cancel0JSONLDecoder[BetaMessageBatchIndividualResponse]c                C  s   |s	t d|| j|d}|jstd|j ddi|p i }i tdt|r7dtdd	 |D d
gnt	i|p>i }dd
i|pFi }| j
|jt||||dtt ddS )  
        Streams the results of a Message Batch as a `.jsonl` file.

        Each line in the file is a JSON object containing the result of a single request
        in the Message Batch. Results are not guaranteed to be in the same order as
        requests. Use the `custom_id` field to match results to requests.

        Learn more about the Message Batches API in our
        [user guide](https://docs.claude.com/en/docs/build-with-claude/batch-processing)

        Args:
          message_batch_id: ID of the Message Batch.

          betas: Optional header to specify the beta version(s) you want to use.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        r^   r[   BNo `results_url` for the given batch; Has it finished processing? Acceptapplication/binaryrD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z"Batches.results.<locals>.<genexpr>rO   rQ   TrT   rU   stream)rc   rf   results_urlr   processing_statusr   r   rV   r   r   rd   r   r   r$   r-   r[   r7   r8   r9   r:   r;   batchr.   r.   r/   results^  s8   #

zBatches.results)r(   r)   )r(   r2   r<   r=   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   r"   r[   rI   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   r"   )ri   rl   rj   rl   rk   rm   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   rn   r[   rI   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   r#   )r[   rI   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   r   __name__
__module____qualname__r   r0   r4   r   r   rZ   rf   rz   r   r   r   r.   r.   r.   r/   r%      X    	<:N;Ac                	   @  r'   )5r&   r(   AsyncBatchesWithRawResponsec                 C  r*   r+   )r   r,   r.   r.   r/   r0     r1   zAsyncBatches.with_raw_response!AsyncBatchesWithStreamingResponsec                 C  r*   r3   )r   r,   r.   r.   r/   r4     r5   z$AsyncBatches.with_streaming_responseNr6   r<   r=   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r"   c             	     s   i t dt|rdtdd |D dgnti|pi }ddi|p%i }| jdtd|itjI dH t	||||d	t
d
I dH S )rC   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z&AsyncBatches.create.<locals>.<genexpr>rO   rP   r<   NrQ   rR   )r   r   rV   r   r   rW   r   r    rX   r   r"   rY   r.   r.   r/   rZ     s*   $
zAsyncBatches.creater[   rI   c                     |s
t d|i tdt|rdtdd |D dgnti|p&i }ddi|p.i }| jd| dt||||d	td
I dH S )r]   r^   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z(AsyncBatches.retrieve.<locals>.<genexpr>rO   r_   r`   rQ   ra   Nrb   re   r.   r.   r/   rf     ,   "

zAsyncBatches.retrieverh   ri   rl   rj   rk   rm   =AsyncPaginator[BetaMessageBatch, AsyncPage[BetaMessageBatch]]c          	      C  ro   )
rp   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM   Q  rN   z$AsyncBatches.list.<locals>.<genexpr>rO   rP   rq   rr   rt   )r   r   rV   r   r   rw   r   r"   r   r   r   rx   ry   r.   r.   r/   rz   #  r{   zAsyncBatches.listr#   c                  r   )r|   r^   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z&AsyncBatches.delete.<locals>.<genexpr>rO   r_   r`   rQ   ra   Nr}   re   r.   r.   r/   r   m  r   zAsyncBatches.deletec                  r   )r   r^   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z&AsyncBatches.cancel.<locals>.<genexpr>rO   r_   r   rQ   ra   Nr   re   r.   r.   r/   r     s,   (

zAsyncBatches.cancel5AsyncJSONLDecoder[BetaMessageBatchIndividualResponse]c                  s   |s
t d|| j|dI dH }|jstd|j ddi|p$i }i tdt|r;dtd	d
 |D dgnt	i|pBi }ddi|pJi }| j
|jt||||dtt ddI dH S )r   r^   r   Nr   r   r   rD   rE   c                 s  rF   rG   rH   rJ   r.   r.   r/   rM     rN   z'AsyncBatches.results.<locals>.<genexpr>rO   rQ   Tr   )rc   rf   r   r   r   r   r   rV   r   r   rd   r   r   r$   r   r.   r.   r/   r     s:   #

zAsyncBatches.results)r(   r   )r(   r   r   r   )ri   rl   rj   rl   rk   rm   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   r   r   )r[   rI   r7   r>   r8   r?   r9   r@   r:   rA   r;   rB   r(   r   r   r.   r.   r.   r/   r&     r   c                   @     e Zd ZdddZdS )	r)   batchesr%   r(   Nonec                 C  P   || _ t|j| _t|j| _t|j| _t|j| _t|j| _d S rG   )_batchesr   to_raw_response_wrapperrZ   rf   rz   r   r   r-   r   r.   r.   r/   __init__$      
zBatchesWithRawResponse.__init__Nr   r%   r(   r   r   r   r   r   r.   r.   r.   r/   r)   #      r)   c                   @  r   )	r   r   r&   r(   r   c                 C  r   rG   )r   r   async_to_raw_response_wrapperrZ   rf   rz   r   r   r   r.   r.   r/   r   9  r   z$AsyncBatchesWithRawResponse.__init__Nr   r&   r(   r   r   r.   r.   r.   r/   r   8  r   r   c                   @  r   )	r2   r   r%   r(   r   c                 C  F   || _ t|j| _t|j| _t|j| _t|j| _t|j| _d S rG   )r   r   rZ   rf   rz   r   r   r   r.   r.   r/   r   N      
z%BatchesWithStreamingResponse.__init__Nr   r   r.   r.   r.   r/   r2   M  r   r2   c                   @  r   )	r   r   r&   r(   r   c                 C  r   rG   )r   r   rZ   rf   rz   r   r   r   r.   r.   r/   r   c  r   z*AsyncBatchesWithStreamingResponse.__init__Nr   r   r.   r.   r.   r/   r   b  r   r   )<
__future__r   typingr   r   	itertoolsr   httpx r   _typesr   r	   r
   r   r   r   r   _utilsr   r   r   r   _compatr   	_resourcer   r   	_responser   r   
paginationr   r   _exceptionsr   _base_clientr   r   _decoders.jsonlr   r   types.beta.messagesr   r    types.anthropic_beta_paramr!   &types.beta.messages.beta_message_batchr"   .types.beta.messages.beta_deleted_message_batchr#   :types.beta.messages.beta_message_batch_individual_responser$   __all__r%   r&   r)   r   r2   r   r.   r.   r.   r/   <module>   s@   $      