o
    ß­j½  ã                   @  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   © ú[/var/www/html/CropPilot/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 )zúA 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ù