o
    j6h                     @  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    m/var/www/html/chefvision.cloud.itp360.com/venv/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   
TunedModel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 )N_polling_retrypollingretry)r   refreshcancelr    r!   r   )getattr
_operation_refresh_cancel_result_type_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)_refresh_and_updater5   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metadatatotal_stepsdoner8   completed_stepsnresult)r6   r3   barr=   r   r   r   wait_barr   s   	z"CreateTunedModelOperation.wait_barrB   protos.TunedModelc                   s   t |}t | d S r   )r   decode_tuned_modelsuper
set_result)r6   rB   	__class__r   r   rH      s   
z$CreateTunedModelOperation.set_result)r   r&   )r	   r   )r	   r9   )rB   rE   )__name__
__module____qualname__classmethodr   r4   propertyr   r8   rD   rH   __classcell__r   r   rI   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.)r=   )	functoolspartialr   r   cancel_operation)	r   r   r   r    r!   rQ   r3   r+   r,   r   r   r   r"      s   
r"   )r	   r
   )r   r   r	   r   )r   r   )
__future__r   rR   typingr   google.generativeair   r   r   google.generativeai.typesr   google.api_corer   operation_lib	tqdm.autoautor<   r   r   r   	Operationr   r"   r   r   r   r   <module>   s   	
R