o
    i @                  	   @   s  d dl Z d dlZd dlmZmZmZ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	lmZ ed
Z	ddeeeef ef deeeef  deeef fddZ	ddeeeef ef deeeef  deeef fddZ	ddeeeef ef deeeef  deeef fddZ	ddeeeef ef deeeef  deeef fddZG dd de
jZG dd de
jZdS )    N)AnyOptionalTypeVarUnion)	urlencode   )_api_module)_common)types)get_value_by_path)set_value_by_pathzgoogle_genai.operationsfrom_objectparent_objectreturnc                 C   sV   i }t | dgd urt|dgt | dg t | dgd ur)t|ddgt | dg |S )Noperation_nameoperationNameresource_name_urlresourceNamegetvsetvr   r   	to_object r   ]/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/google/genai/operations.py*_FetchPredictOperationParameters_to_vertex!   s   
r   c                 C   0   i }t | dgd urt|ddgt | dg |S Nr   r   r   r   r   r   r   r    _GetOperationParameters_to_mldev3      
r   c                 C   r   r   r   r   r   r   r   !_GetOperationParameters_to_vertexB   r    r!   c                 C   s0   i }t | dgd urt|ddgt | dg |S )Noperation_idr   r   r   r   r   r   (_GetProjectOperationParameters_to_vertexQ   s   r#   c                	   @      e Zd Zdddedeej defddZdddededeej	 defd	d
Z
dddedeej dejfddZedejdZdddedeej defddZdS )
OperationsNconfigr   r'   r   c                C   s   t j||d}| jjrt|}|d}|rd|}nd}nt|}|d}|r0d|}nd}|d}|rB| dt| }|	dd  d }|j
d urY|j
jd urY|j
j}t|}t|}| jd|||}	|	jssi }
|
S t|	j}
|
S Nr   r'   r   z{operationName}_query?r'   get)r
   _GetOperationParameters_api_clientvertexair!   r,   
format_mapr   r   popr'   http_optionsr	   convert_to_dictencode_unserializable_typesrequestbodyjsonloadsselfr   r'   parameter_modelrequest_dictrequest_url_dictpathquery_paramsr2   responseresponse_dictr   r   r   _get_videos_operation`   s<   






z Operations._get_videos_operationr   c                C   s   t j|||d}| jjstdt|}|d}|r!d|}nd}|d}|r3| dt| }|	dd  d }	|j
d urJ|j
jd urJ|j
j}	t|}t|}| jd|||	}
|
jsdi }|S t|
j}|S 	Nr   r   r'   6This method is only supported in the Vertex AI client.r   z${resourceName}:fetchPredictOperationr*   r+   r'   post)r
    _FetchPredictOperationParametersr.   r/   
ValueErrorr   r,   r0   r   r1   r'   r2   r	   r3   r4   r5   r6   r7   r8   r:   r   r   r'   r;   r<   r=   r>   r?   r2   r@   rA   r   r   r   _fetch_predict_videos_operation   s>   





z*Operations._fetch_predict_videos_operationr"   c                C   s   t j||d}| jjstdt|}|d}|r d|}nd}|d}|r2| dt| }|	dd  d }|j
d urI|j
jd urI|j
j}t|}t|}| jd|||}	|	jsai nt|	j}
t jj|
| d	}| j| |S 
N)r"   r'   rE   r   zoperations/{operation_id}r*   r+   r'   r,   )r@   kwargs)r
   _GetProjectOperationParametersr.   r/   rH   r#   r,   r0   r   r1   r'   r2   r	   r3   r4   r5   r6   r7   r8   ProjectOperation_from_response
model_dump_verify_responser:   r"   r'   r;   r<   r=   r>   r?   r2   r@   rA   return_valuer   r   r   _get   s8   




zOperations._getTbound	operationc          
      C   s   |j }|s	td| jjre|dd }t }t|tr2|	dd}|dur1tjdi t|}nt|tj
rH|durH|jdurD|jnt }tj|d}| j|||d}|j|dd	}	| j|	 |	S | j||d
}|j|dd	}	| j|	 |	S z Gets the status of an operation.zOperation name is empty.z/operations/r   r2   N)r2   rD   T)is_vertex_air)   Fr   )namerH   r.   r/   
rpartitionr
   HttpOptions
isinstancedictr,   GetOperationConfigr2   FetchPredictOperationConfigrJ   from_api_responserQ   rB   
r:   rX   r'   r   r   r2   dict_optionsfetch_operation_configrA   response_operationr   r   r   r,      sL   	

zOperations.get__name__
__module____qualname__strr   r
   GetOperationConfigOrDictr   rB   !FetchPredictOperationConfigOrDictrJ   rN   rT   r   	OperationrU   r,   r   r   r   r   r%   ^   sH    
6
6
1r%   c                	   @   r$   )AsyncOperationsNr&   r   r'   r   c                   s   t j||d}| jjr t|}|d}|rd|}nd}nt|}|d}|r1d|}nd}|d}|rC| dt| }|	dd  d }|j
d urZ|j
jd urZ|j
j}t|}t|}| jd|||I d H }	|	jswi }
|
S t|	j}
|
S r(   )r
   r-   r.   r/   r!   r,   r0   r   r   r1   r'   r2   r	   r3   r4   async_requestr6   r7   r8   r9   r   r   r   rB   /  sB   







z%AsyncOperations._get_videos_operationr   c                   s   t j|||d}| jjstdt|}|d}|r"d|}nd}|d}|r4| dt| }|	dd  d }	|j
d urK|j
jd urK|j
j}	t|}t|}| jd|||	I d H }
|
jshi }|S t|
j}|S rC   )r
   rG   r.   r/   rH   r   r,   r0   r   r1   r'   r2   r	   r3   r4   rp   r6   r7   r8   rI   r   r   r   rJ   b  s@   






z/AsyncOperations._fetch_predict_videos_operationr"   c                   s   t j||d}| jjstdt|}|d}|r!d|}nd}|d}|r3| dt| }|	dd  d }|j
d urJ|j
jd urJ|j
j}t|}t|}| jd|||I d H }	|	jsei nt|	j}
t jj|
| d	}| j| |S rK   )r
   rM   r.   r/   rH   r#   r,   r0   r   r1   r'   r2   r	   r3   r4   rp   r6   r7   r8   rN   rO   rP   rQ   rR   r   r   r   rT     s>   





zAsyncOperations._getrU   rV   rX   c          
         s   |j }|s
td| jjrc|dd }t }t|tr3|	dd}|dur2tjdi t|}nt|tj
rI|durI|jdurE|jnt }tj|d}| j|||dI dH }|j|dd	}	|	S | j||d
I dH }|j|dd	}	|	S rY   )r[   rH   r.   r/   r\   r
   r]   r^   r_   r,   r`   r2   ra   rJ   rb   rB   rc   r   r   r   r,     sJ   

zAsyncOperations.getrg   r   r   r   r   ro   -  sH    
8
6
3ro   )N)r7   loggingtypingr   r   r   r   urllib.parser    r   r	   r
   r   r   r   r   	getLoggerloggerr_   rk   objectr   r   r!   r#   
BaseModuler%   ro   r   r   r   r   <module>   sZ   








 P