o
    Zh                     @  s   d dl mZ d dl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dd
dZdddddZdddddZG dd dejZddddZdS )    )annotationsN)Iterator)protosclient)model_types)	operationreturn#Iterator[CreateTunedModelOperation]c                   s0    du rt    fdd jdddD }|S )z$Calls the API to list all operationsNc                 3  s    | ]	}t | V  qd S N)CreateTunedModelOperation
from_proto).0opr    U/var/www/html/lang_env/lib/python3.10/site-packages/google/generativeai/operations.py	<genexpr>%   s
    

z"list_operations.<locals>.<genexpr> )namefilter_)
client_libget_default_operations_clientlist_operations)r   
operationsr   r   r   r      s   
r   r   strr   c                C  s(   |du rt  }|j| d}t||S )z)Calls the API to get a specific operationNr   )r   r   get_operationr   r   )r   r   r   r   r   r   r   -   s   r   c                C  s   |du rt  }|j| dS )z,Calls the API to delete a specific operationNr   )r   r   delete_operation)r   r   r   r   r   r   6   s   r   c                      sX   e Zd Zedd ZedddZedd	d
Zdd ZdddZ	d fddZ
  ZS )r   c                 C  s   t t||tjtjdS )z
        result = getattr(proto, 'result', None)
        if result is not None:
            if result.value == b'':
                del proto.result
        )clsr   operations_clientresult_typemetadata_type)
from_gapicr   r   Z
TunedModelZCreateTunedModelMetadata)r   protor   r   r   r   r   A   s   	z$CreateTunedModelOperation.from_protor   operation_lib.Operationc                 C  sd   t |dd }t |dd }|d urd|i}n|d urd|i}ni }| d|j|j|j|j|jd|S )NZ_pollingZ_retrypollingretry)r   refreshcancelr    r!   r   )getattr
_operationZ_refreshZ_cancelZ_result_typeZ_metadata_type)r   r   r%   r&   kwargsr   r   r   from_core_operationR   s    

z-CreateTunedModelOperation.from_core_operationr	   r   c                 C  s   | j jS r   )r*   r   selfr   r   r   r   j   s   zCreateTunedModelOperation.namec                 C  s   |    dS )z5Refresh the current statuses in metadata/result/errorN)Z_refresh_and_updater-   r   r   r   updaten   s   z CreateTunedModelOperation.update)Iterator[protos.CreateTunedModelMetadata]c                 k  sn    t j d| jjdd|}|  s&| j}|| jj|j  |V  |  r| j}|| jj|j  |  S )zA tqdm wait bar, yields `Operation` statuses until complete.

        Args:
            **kwargs: passed through to `tqdm.auto.tqdm(..., **kwargs)`

        Yields:
            Operation statuses as `protos.CreateTunedModelMetadata` objects.
        r   )totalinitialNr   )tqdmmetadataZtotal_stepsdoner/   Zcompleted_stepsnresult)r.   r+   barr4   r   r   r   wait_barr   s   	z"CreateTunedModelOperation.wait_barr7   protos.TunedModelc                   s   t |}t | d S r   )r   Zdecode_tuned_modelsuper
set_result)r.   r7   	__class__r   r   r<      s   
z$CreateTunedModelOperation.set_result)r   r$   )r	   r   )r	   r0   )r7   r:   )__name__
__module____qualname__classmethodr   r,   propertyr   r/   r9   r<   __classcell__r   r   r=   r   r   @   s    

)grpc_metadatac          	      K  s@   t j|j|j|d}t j|j|j|d}| |||||fi |S )zD`google.api_core.operation.from_gapic`, patched to allow subclasses.)r4   )	functoolspartialr   r   Zcancel_operation)	r   r   r   r    r!   rE   r+   r'   r(   r   r   r   r"      s   
r"   )r	   r
   )r   r   r	   r   )r   r   )
__future__r   rF   typingr   Zgoogle.generativeair   r   r   Zgoogle.generativeai.typesr   Zgoogle.api_corer   Zoperation_libZ	tqdm.autoautor3   r   r   r   Z	Operationr   r"   r   r   r   r   <module>   s   	
R