o
    ϖi;                     @   sR  d dl mZmZmZmZmZ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 d dlmZmZmZmZ d dlmZmZ zd dlmZ W n eyW   d d	lZY nw erfd d
lmZ d dlmZ G dd deZ G dd deZ!dddee"ef de fddZ#G dd deZ$G dd deZ%dee"ee"e"f e f de"fddZ&d	S )    )TYPE_CHECKINGAnyDictOptionalTuple	TypedDictUnion)Unpack
deprecated)Account)async_encode_jsonencode_json)Page)
Prediction_create_prediction_body!_create_prediction_request_params_json_to_prediction)	NamespaceResource)v1N)Client)Predictionsc                   @   s   e Zd ZU dZe Zded< eed< 	 eed< 	 G dd de	Z
ee
 ed< 	 eed	d
efddZed
efddZedddZdS )
Deploymentz6
    A deployment of a model hosted on Replicate.
    r   _clientownernamec                   @   s`   e Zd ZU dZeed< 	 eed< 	 eed< 	 eed< 	 ee ed< 	 G dd de	Z
e
ed	< d
S )zDeployment.Releasez,
        A release of a deployment.
        numbermodelversion
created_at
created_byc                   @   s.   e Zd ZU dZeed< 	 eed< 	 eed< dS )z Deployment.Release.Configurationz;
            A configuration for a deployment.
            hardwaremin_instancesmax_instancesN__name__
__module____qualname____doc__str__annotations__int r,   r,   H/home/ubuntu/.local/lib/python3.10/site-packages/replicate/deployment.pyConfigurationJ   s   
 r.   configurationN)r%   r&   r'   r(   r+   r*   r)   r   r   r   r.   r,   r,   r,   r-   Release,   s   
 r0   current_releasezUse `deployment.owner` instead.returnc                 C   s   | j S )z
        The name of the user or organization that owns the deployment.
        This attribute is deprecated and will be removed in future versions.
        )r   selfr,   r,   r-   usernameh   s   zDeployment.usernamec                 C   s   | j  d| j S )zS
        Return the qualified deployment name, in the format `owner/name`.
        /)r   r   r3   r,   r,   r-   idq   s   zDeployment.idDeploymentPredictionsc                 C   s   t | j| dS )z:
        Get the predictions for this deployment.
        )client
deployment)r8   r   r3   r,   r,   r-   predictionsx   s   zDeployment.predictionsN)r2   r8   )r%   r&   r'   r(   pydanticPrivateAttrr   r*   r)   r   r0   r   propertyr
   r5   r7   r;   r,   r,   r,   r-   r      s"   
 7r   c                   @   sL  e Zd ZU dZded< 	d*deeddf dee fd	d
Z		d*deeddf dee fddZ
dedefddZdedefddZG dd deZdee defddZdee defddZG dd deddZdededee defdd Zdededee defd!d"Zdededefd#d$Zdededefd%d&Zed+d(d)ZdS ),Deploymentsz:
    Namespace for operations related to deployments.
    r   r   .cursorellipsisNr2   c                    s^   |du rt d jd|du rdn|}| } fdd|d D |d< tt d	i |S )
\
        List all deployments.

        Returns:
            A page of Deployments.
        Ncursor cannot be NoneGET./v1/deploymentsc                       g | ]}t  j|qS r,   _json_to_deploymentr   .0resultr3   r,   r-   
<listcomp>       z$Deployments.list.<locals>.<listcomp>resultsr,   )
ValueErrorr   _requestjsonr   r   r4   r@   respobjr,   r3   r-   list   s   

zDeployments.listc                    sf   |du r	t d jd|du rdn|I dH }| } fdd|d D |d< tt d	i |S )
rB   NrC   rD   .rE   c                    rF   r,   rG   rI   r3   r,   r-   rL      rM   z*Deployments.async_list.<locals>.<listcomp>rN   r,   )rO   r   _async_requestrQ   r   r   rR   r,   r3   r-   
async_list   s   



zDeployments.async_listr   c                 C   s:   | dd\}}| jdd| d| }t| j| S )
        Get a deployment by name.

        Args:
            name: The name of the deployment, in the format `owner/model-name`.
        Returns:
            The model.
        r6      rD   /v1/deployments/)splitr   rP   rH   rQ   r4   r   r   rS   r,   r,   r-   get   s   
zDeployments.getc                    sB   | dd\}}| jdd| d| I dH }t| j| S )rX   r6   rY   rD   rZ   N)r[   r   rV   rH   rQ   r\   r,   r,   r-   	async_get   s   

zDeployments.async_getc                   @   sL   e Zd ZU dZeed< 	 eed< 	 eed< 	 eed< 	 eed< 	 eed< dS )	z"Deployments.CreateDeploymentParamsz;
        Parameters for creating a new deployment.
        r   r   r   r!   r"   r#   Nr$   r,   r,   r,   r-   CreateDeploymentParams   s   
 r_   paramsc                 K   sR   | dd }rd|v r|dd\}}||d< | jjdd|d}t| j| S z
        Create a new deployment.

        Args:
            params: Configuration for the new deployment.
        Returns:
            The newly created Deployment.
        r   Nr6   rY   POSTrE   rQ   )r]   r[   r   rP   rH   rQ   r4   r`   r   _rS   r,   r,   r-   create   s   
zDeployments.createc                    sZ   | dd }rd|v r|dd\}}||d< | jjdd|dI dH }t| j| S ra   )r]   r[   r   rV   rH   rQ   rd   r,   r,   r-   async_create  s   zDeployments.async_createc                   @   s8   e Zd ZU dZeed< 	 eed< 	 eed< 	 eed< dS )z"Deployments.UpdateDeploymentParamszA
        Parameters for updating an existing deployment.
        r   r!   r"   r#   Nr$   r,   r,   r,   r-   UpdateDeploymentParams&  s   
 rh   F)totaldeployment_ownerdeployment_namec                 K   s.   | j jdd| d| |d}t| j | S )&  
        Update an existing deployment.

        Args:
            deployment_owner: The owner of the deployment.
            deployment_name: The name of the deployment.
            params: Configuration updates for the deployment.
        Returns:
            The updated Deployment.
        PATCHrZ   r6   rc   )r   rP   rH   rQ   r4   rj   rk   r`   rS   r,   r,   r-   update7  s   zDeployments.updatec                    s6   | j jdd| d| |dI dH }t| j | S )rl   rm   rZ   r6   rc   N)r   rV   rH   rQ   rn   r,   r,   r-   async_updateP  s   zDeployments.async_updatec                 C   s$   | j dd| d| }|jdkS )z
        Delete an existing deployment.

        Args:
            deployment_owner: The owner of the deployment.
            deployment_name: The name of the deployment.
        DELETErZ   r6      )r   rP   status_coder4   rj   rk   rS   r,   r,   r-   deletei  s
   
zDeployments.deletec                    s,   | j dd| d| I dH }|jdkS )z
        Delete an existing deployment asynchronously.

        Args:
            deployment_owner: The owner of the deployment.
            deployment_name: The name of the deployment.
        rq   rZ   r6   Nrr   )r   rV   rs   rt   r,   r,   r-   async_deletew  s   

zDeployments.async_deleteDeploymentsPredictionsc                 C   s   t | jdS )z2
        Get predictions for deployments.
        r9   )rw   r   r3   r,   r,   r-   r;     s   zDeployments.predictions).)r2   rw   )r%   r&   r'   r(   r*   r   r)   r   r   rU   rW   r]   r^   r   r_   r	   rf   rg   rh   ro   rp   boolru   rv   r>   r;   r,   r,   r,   r-   r?      s^   
 




r?   r9   r   rQ   r2   c                 C   s   t di |}| |_|S )Nr,   )r   r   )r9   rQ   r:   r,   r,   r-   rH     s   rH   c                       s|   e Zd ZU dZeed< dddeddf fdd	Zd
eee	f de
d defddZd
eee	f de
d defddZ  ZS )r8   zJ
    Namespace for operations related to predictions in a deployment.
    _deploymentr9   r   r:   r2   Nc                    s   t  j|d || _d S )Nrx   )super__init__rz   )r4   r9   r:   	__class__r,   r-   r|     s   
zDeploymentPredictions.__init__inputr`   "Predictions.CreatePredictionParamsc                 K   s   | dd}| dd}|durt|| j|d}tdd|d|}t|d}| jjdd| jj d	| jj d
fd|i|}t	| j|
 S >
        Create a new prediction with the deployment.
        waitNfile_encoding_strategyr9   r   r   r   r   rb   rZ   r6   /predictionsrQ   r,   )popr   r   r   r   rP   rz   r   r   r   rQ   r4   r   r`   r   r   bodyextrasrS   r,   r,   r-   rf     s*   	zDeploymentPredictions.createc                    s   | dd}| dd}|durt|| j|dI dH }tdd|d|}t|d}| jjdd| jj d	| jj d
fd|i|I dH }t	| j|
 S r   )r   r   r   r   r   rV   rz   r   r   r   rQ   r   r,   r,   r-   rg     s,   	z"DeploymentPredictions.async_create)r%   r&   r'   r(   r   r*   r|   r   r)   r   r	   r   rf   rg   __classcell__r,   r,   r}   r-   r8     s$   
 

 
r8   c                   @   s   e Zd ZdZdeeeeef ef deee	f de
d defddZdeeeeef ef deee	f de
d defd	d
ZdS )rw   zI
    Namespace for operations related to predictions in deployments.
    r:   r   r`   r   r2   c           
      K   s   | dd}| dd}t|}|durt|| j|d}td	d|d|}t|d}| jjd|fd|i|}	t| j|	 S 
r   r   Nr   r   r   r   rb   rQ   r,   )	r   &_create_prediction_url_from_deploymentr   r   r   r   rP   r   rQ   
r4   r:   r   r`   r   r   urlr   r   rS   r,   r,   r-   rf     s   

zDeploymentsPredictions.createc           
         s   | dd}| dd}t|}|dur t|| j|dI dH }td	d|d|}t|d}| jjd|fd|i|I dH }	t| j|	 S r   )	r   r   r   r   r   r   rV   r   rQ   r   r,   r,   r-   rg     s   

 z#DeploymentsPredictions.async_createN)r%   r&   r'   r(   r   r)   r   r   r   r   r	   r   rf   rg   r,   r,   r,   r-   rw     s(    


rw   r:   c                 C   s   d\}}t | tr| j| j}}nt | tr | d | d }}nt | tr-| dd\}}|d u s5|d u r9tdd| d| dS )N)NNr   rY   r6   zadeployment must be a Deployment, a tuple of (owner, name), or a string in the format 'owner/name'rZ   r   )
isinstancer   r   r   tupler)   r[   rO   )r:   r   r   r,   r,   r-   r     s   


r   )'typingr   r   r   r   r   r   r   typing_extensionsr	   r
   replicate.accountr   replicate.helpersr   r   replicate.paginationr   replicate.predictionr   r   r   r   replicate.resourcer   r   r<   r   ImportErrorreplicate.clientr   r   r   r?   r)   rH   r8   rw   r   r,   r,   r,   r-   <module>   s6   $ f  K<