o
    iS                     @   s"  d dl Z d dl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 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( e )e j*dZ+G dd dZ,G dd dZ-dS )    N)JSONDecodeError   )ApiError)AsyncClientWrapperSyncClientWrapper)AsyncHttpResponseHttpResponse)jsonable_encoder)RequestOptions)'convert_and_respect_annotation_metadata)construct_type)BadRequestError)ForbiddenError)InternalServerError)NotFoundError)ServiceUnavailableError)UnauthorizedError   )Batch)CancelBatchResponse)CreateBatchResponse)GetBatchResponse)ListBatchesResponse.c                   @      e Zd ZdefddZddddddeje deje deje d	eje	 d
e
e f
ddZddded	eje	 d
e
e fddZddded	eje	 d
e
e fddZddded	eje	 d
e
e fddZdS )RawBatchesClientclient_wrapperc                C   
   || _ d S N_client_wrapperselfr    r"   _/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cohere/batches/raw_client.py__init__      
zRawBatchesClient.__init__N	page_size
page_tokenorder_byrequest_optionsr'   r(   r)   r*   returnc             	   C   s*  | j jjdd|||d|d}zd|j  krdk r0n ntttt| d}t	||dW S |jd	krPt
t|jttjtj ttjtj | dd
|jdkrptt|jttjtj ttjtj | dd
|jdkrtt|jttjtj ttjtj | dd
|jdkrtt|jttjtj ttjtj | dd
|jdkrtt|jttjtj ttjtj | dd
|jdkrtt|jttjtj ttjtj | dd
| }W n ty	   t|jt|j|jdw t|jt|j|d)a  
        List the batches for the current user

        Parameters
        ----------
        page_size : typing.Optional[int]
            The maximum number of batches to return. The service may return fewer than
            this value.
            If unspecified, at most 50 batches will be returned.
            The maximum value is 1000; values above 1000 will be coerced to 1000.

        page_token : typing.Optional[str]
            A page token, received from a previous `ListBatches` call.
            Provide this to retrieve the subsequent page.

        order_by : typing.Optional[str]
            Batches can be ordered by creation time or last updated time.
            Use `created_at` for creation time or `updated_at` for last updated time.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ListBatchesResponse]
            A successful response.
        
v2/batchesGETr'   r(   r)   methodparamsr*      ,  type_object_responsedata  headersbody          status_coder<   r=   )r   httpx_clientrequestrD   typingcastr   r   jsonr   r   dictr<   OptionalAnyr   r   r   r   r   r   r   textr!   r'   r(   r)   r*   	_response_data_response_jsonr"   r"   r#   list!   s   #
























zRawBatchesClient.listr*   rF   c             	   C   s4  | j jjddt|tddddi|td}zd|j  kr d	k r5n ntt	t
t	| d
}t||dW S |jdkrUtt|jttjtj t
tjtj | d
d|jdkrutt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d|jdkrtt|jttjtj t
tjtj | d
d| }W n ty   t|jt|j|jdw t|jt|j|d)ag  
        Creates and executes a batch from an uploaded dataset of requests

        Parameters
        ----------
        request : Batch

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[CreateBatchResponse]
            A successful response.
        r,   POSTwriter6   
annotation	directioncontent-typeapplication/jsonr0   rI   r<   r*   omitr2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   r   r   OMITrD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   r!   rF   r*   rO   rP   rQ   r"   r"   r#   create   s   
























zRawBatchesClient.createidc             	   C   s*  | j jjdt| d|d}zd|j  krdk r0n ntttt|	 d}t
||dW S |jdkrPtt|jttjtj ttjtj |	 dd	|jd
krptt|jttjtj ttjtj |	 dd	|jdkrtt|jttjtj ttjtj |	 dd	|jdkrtt|jttjtj ttjtj |	 dd	|jdkrtt|jttjtj ttjtj |	 dd	|jdkrtt|jttjtj ttjtj |	 dd	|	 }W n ty	   t|jt|j|jdw t|jt|j|d)aG  
        Retrieves a batch

        Parameters
        ----------
        id : str
            The batch ID.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[GetBatchResponse]
            A successful response.
        v2/batches/r-   r0   r*   r2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   r	   rD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   r!   r`   r*   rO   rP   rQ   r"   r"   r#   retrieve  s   























zRawBatchesClient.retrievec             	   C   s,  | j jjdt| dd|d}zd|j  krdk r1n ntttt|	 d}t
||dW S |jd	krQtt|jttjtj ttjtj |	 dd
|jdkrqtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|	 }W n ty
   t|jt|j|jdw t|jt|j|d)aU  
        Cancels an in-progress batch

        Parameters
        ----------
        id : str
            The batch ID.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[CancelBatchResponse]
            A successful response.
        ra   :cancelrT   rb   r2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   r	   rD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   rc   r"   r"   r#   cancelu  s   























zRawBatchesClient.cancel)__name__
__module____qualname__r   r$   rG   rK   intstrr
   r   r   rR   r   r   r_   r   rd   r   rf   r"   r"   r"   r#   r      R    

n
jr   c                   @   r   )AsyncRawBatchesClientr   c                C   r   r   r   r    r"   r"   r#   r$     r%   zAsyncRawBatchesClient.__init__Nr&   r'   r(   r)   r*   r+   c             	      s2  | j jjdd|||d|dI dH }zd|j  krdk r4n ntttt| d}t	||d	W S |jd
krTt
t|jttjtj ttjtj | dd|jdkrttt|jttjtj ttjtj | dd|jdkrtt|jttjtj ttjtj | dd|jdkrtt|jttjtj ttjtj | dd|jdkrtt|jttjtj ttjtj | dd|jdkrtt|jttjtj ttjtj | dd| }W n ty   t|jt|j|jdw t|jt|j|d)a  
        List the batches for the current user

        Parameters
        ----------
        page_size : typing.Optional[int]
            The maximum number of batches to return. The service may return fewer than
            this value.
            If unspecified, at most 50 batches will be returned.
            The maximum value is 1000; values above 1000 will be coerced to 1000.

        page_token : typing.Optional[str]
            A page token, received from a previous `ListBatches` call.
            Provide this to retrieve the subsequent page.

        order_by : typing.Optional[str]
            Batches can be ordered by creation time or last updated time.
            Use `created_at` for creation time or `updated_at` for last updated time.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ListBatchesResponse]
            A successful response.
        r,   r-   r.   r/   Nr2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   rD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   rN   r"   r"   r#   rR     s   #
























zAsyncRawBatchesClient.listrS   rF   c             	      s<  | j jjddt|tddddi|tdI dH }zd	|j  kr$d
k r9n ntt	t
t	| d}t||dW S |jdkrYtt|jttjtj t
tjtj | dd|jdkrytt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd|jdkrtt|jttjtj t
tjtj | dd| }W n ty   t|jt|j|jdw t|jt|j|d)al  
        Creates and executes a batch from an uploaded dataset of requests

        Parameters
        ----------
        request : Batch

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[CreateBatchResponse]
            A successful response.
        r,   rT   rU   rV   rY   rZ   r[   Nr2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   r   r   r]   rD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   r^   r"   r"   r#   r_   a  s   
























zAsyncRawBatchesClient.creater`   c             	      s2  | j jjdt| d|dI dH }zd|j  krdk r4n ntttt|	 d}t
||dW S |jd	krTtt|jttjtj ttjtj |	 dd
|jdkrttt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|jdkrtt|jttjtj ttjtj |	 dd
|	 }W n ty   t|jt|j|jdw t|jt|j|d)aL  
        Retrieves a batch

        Parameters
        ----------
        id : str
            The batch ID.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[GetBatchResponse]
            A successful response.
        ra   r-   rb   Nr2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   r	   rD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   rc   r"   r"   r#   rd     s   























zAsyncRawBatchesClient.retrievec             	      s4  | j jjdt| dd|dI dH }zd|j  kr dk r5n ntttt|	 d}t
||d	W S |jd
krUtt|jttjtj ttjtj |	 dd|jdkrutt|jttjtj ttjtj |	 dd|jdkrtt|jttjtj ttjtj |	 dd|jdkrtt|jttjtj ttjtj |	 dd|jdkrtt|jttjtj ttjtj |	 dd|jdkrtt|jttjtj ttjtj |	 dd|	 }W n ty   t|jt|j|jdw t|jt|j|d)aZ  
        Cancels an in-progress batch

        Parameters
        ----------
        id : str
            The batch ID.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[CancelBatchResponse]
            A successful response.
        ra   re   rT   rb   Nr2   r3   r4   r7   r:   r;   r>   r?   r@   rA   rB   rC   )r   rE   rF   r	   rD   rG   rH   r   r   rI   r   r   rJ   r<   rK   rL   r   r   r   r   r   r   r   rM   rc   r"   r"   r#   rf   7  s   























zAsyncRawBatchesClient.cancel)rg   rh   ri   r   r$   rG   rK   rj   rk   r
   r   r   rR   r   r   r_   r   rd   r   rf   r"   r"   r"   r#   rm     rl   rm   ).rG   json.decoderr   core.api_errorr   core.client_wrapperr   r   core.http_responser   r   core.jsonable_encoderr	   core.request_optionsr
   core.serializationr   core.unchecked_base_modelr   errors.bad_request_errorr   errors.forbidden_errorr   errors.internal_server_errorr   errors.not_found_errorr    errors.service_unavailable_errorr   errors.unauthorized_errorr   types.batchr   types.cancel_batch_responser   types.create_batch_responser   types.get_batch_responser   types.list_batches_responser   rH   rL   r]   r   rm   r"   r"   r"   r#   <module>   s4      E