
    rh                        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Zdddd
ZddddZ G d d	ej(                        ZdddZy)    )annotationsN)Iterator)protos)client)model_types)	operationc                l      t        j                           fd j                  dd      D        }|S )z$Calls the API to list all operationsc              3  J   K   | ]  }t         j                  |        y wN)CreateTunedModelOperation
from_proto).0opr   s     q/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/google/generativeai/operations.py	<genexpr>z"list_operations.<locals>.<genexpr>%   s&       	",,R8s    # )namefilter_)
client_libget_default_operations_clientlist_operations)r   
operationss   ` r   r   r      s?     ~99;((b"(=J
     r   c               ~    |t        j                         }|j                  |       }t        j	                  ||      S )z)Calls the API to get a specific operationr   )r   r   get_operationr   r   )r   r   r   s      r   r   r   -   s;    ~99;			4		(B$//F;;r   c               R    |t        j                         }|j                  |       S )z,Calls the API to delete a specific operationr   )r   r   delete_operation)r   r   s     r   r   r   6   s+     ~99;"""--r   c                  f     e Zd Zed        Ze	 	 dd       Zedd       Zd Zd	dZ	d
 fdZ
 xZS )r   c                b    t        t        ||t        j                  t        j                        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   s      r   r   z$CreateTunedModelOperation.from_protoA   s,     )$)) 99
 	
r   c           	         t        |dd       }t        |dd       }|d|i}n	|d|i}ni } | d|j                  |j                  |j                  |j                  |j
                  d|S )N_polling_retrypollingretry)r   refreshcancelr#   r$    )getattr
_operation_refresh_cancel_result_type_metadata_type)r!   r   r,   r-   kwargss        r   from_core_operationz-CreateTunedModelOperation.from_core_operationR   s    
 )Z6	8T2)Fu%FF 
**&&$$!..#22
 
 	
r   c                .    | j                   j                  S r   )r2   r   selfs    r   r   zCreateTunedModelOperation.namej   s    ###r   c                $    | j                          y)z5Refresh the current statuses in metadata/result/errorN)_refresh_and_updater:   s    r   updatez CreateTunedModelOperation.updaten   s      "r   c              +    K   t        j                   d| j                  j                  dd|}| j                         sS| j                  }|j	                  | j                  j
                  |j                  z
         | | j                         sS| j                  }|j	                  | j                  j
                  |j                  z
         | j                         S w)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initialr0   )tqdmmetadatatotal_stepsdoner>   completed_stepsnresult)r;   r7   barrC   s       r   wait_barz"CreateTunedModelOperation.wait_barr   s      iiMdmm77MfM ))+}}HJJt}}44suu<=N ))+ ==

4==0035589{{}s   BC AC c                N    t        j                  |      }t        |   |       y r   )r   decode_tuned_modelsuper
set_result)r;   rH   	__class__s     r   rN   z$CreateTunedModelOperation.set_result   s     //76"r   )r   zoperation_lib.Operation)returnstr)rP   z)Iterator[protos.CreateTunedModelMetadata])rH   zprotos.TunedModel)__name__
__module____qualname__classmethodr   r8   propertyr   r>   rJ   rN   __classcell__)rO   s   @r   r   r   @   sY    
 
  
*
 
. $ $#(# #r   )grpc_metadatac                   t        j                  |j                  |j                  |      }t        j                  |j                  |j                  |      } | |||||fi |S )zD`google.api_core.operation.from_gapic`, patched to allow subclasses.)rC   )	functoolspartialr   r   cancel_operation)	r!   r   r"   r#   r$   rX   r7   r.   r/   s	            r   r%   r%      sd     ''-G **F
 y'6;PPPr   )rP   z#Iterator[CreateTunedModelOperation])r   rQ   rP   r   )r   rQ   )
__future__r   rZ   typingr   google.generativeair   r   r   google.generativeai.typesr   google.api_corer   operation_lib	tqdm.autoautorB   r   r   r   	Operationr   r%   r0   r   r   <module>rf      s]    #   & 4 1 6  #   (, < +/ .H# 7 7 H#d Qr   