o
    pkj/                     @   s  d dl mZ d dlZd dlZd dlZd dlZd dl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 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mZ ddlmZm Z  e!dZ"	d8dede	e#e$ef e%f dee#e$ef  de#e$ef fddZ&	d8dede	e#e$ef e%f dee#e$ef  de#e$ef fddZ'	d8de	e#e$ef e%f dee#e$ef  de#e$ef fddZ(	d8de	e#e$ef e%f dee#e$ef  de#e$ef fddZ)	d8de	e#e$ef e%f dee#e$ef  de#e$ef fddZ*	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd d!Z+	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd"d#Z,	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd$d%Z-	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd&d'Z.	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd(d)Z/	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd*d+Z0	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd,d-Z1	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd.d/Z2	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd0d1Z3	d8de	e#e$ef e%f dee#e$ef  de#e$ef fd2d3Z4G d4d5 d5ej5Z6G d6d7 d7ej5Z7dS )9    )cached_propertyN)AnyOptionalUnion)	urlencode   )_api_module)_common)_extra_utils)_transformers)types)BaseApiClient)get_value_by_path)set_value_by_path),_UploadToFileSearchStoreOperation_from_mldev)AsyncDocuments	Documents)
AsyncPagerPagerzgoogle_genai.filesearchstores
api_clientfrom_objectparent_objectreturnc              	   C   s\   i }t |dgd urt|dgt |dg t |dgd ur,t|dgt| t |dg |S )Ndisplay_namedisplayNameembedding_modelembeddingModel)getvsetvtt_modelr   r   r   	to_object r#   ]/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/google/genai/file_search_stores.py%_CreateFileSearchStoreConfig_to_mldev)   s   r%   c                 C   s,   i }t |dgd urt| t |dg| |S Nconfig)r   r%   r!   r#   r#   r$   )_CreateFileSearchStoreParameters_to_mldev=   s   r(   c                 C   s0   i }t | dgd urt|ddgt | dg |S )Nforce_queryr   r   r   r   r"   r#   r#   r$   %_DeleteFileSearchStoreConfig_to_mldevK   s   r-   c                 C   R   i }t | dgd urt|ddgt | dg t | dgd ur'tt | dg| |S )Nname_urlr'   )r   r   r-   r,   r#   r#   r$   )_DeleteFileSearchStoreParameters_to_mldevW   s   r1   c                 C   s0   i }t | dgd urt|ddgt | dg |S )Nr/   r0   r+   r,   r#   r#   r$   &_GetFileSearchStoreParameters_to_mldevg   s   r2   c                 C   s^   i }t | dgd urt|dgdd t | dgD  t | dgd ur-t|dgt | dg |S )Ncustom_metadatacustomMetadatac                 S      g | ]}|qS r#   r#   .0itemr#   r#   r$   
<listcomp>|       z._ImportFileConfig_to_mldev.<locals>.<listcomp>chunking_configchunkingConfigr+   r,   r#   r#   r$   _ImportFileConfig_to_mldevr   s   
r=   c                 C   s   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur;t|dgt | dg t | dgd urNt|dgt | dg t | dgd urdt|dgtt | dg| |S )Nr/   metadatadoneerrorresponse)r   r   _ImportFileResponse_from_mldevr,   r#   r#   r$   _ImportFileOperation_from_mldev   s$   rC   c                 C   sx   i }t | dgd urt|ddgt | dg t | dgd ur)t|dgt | dg t | dgd ur:tt | dg| |S )Nfile_search_store_namer0   	file_namefileNamer'   )r   r   r=   r,   r#   r#   r$   _ImportFileParameters_to_mldev   s   
rG   c                 C   sz   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur;t|dgt | dg |S )NsdkHttpResponsesdk_http_responseparentdocumentNamedocument_namer+   r,   r#   r#   r$   rB      s   rB   c                 C   sX   i }t | dgd urt|ddgt | dg t | dgd ur*t|ddgt | dg |S )N	page_sizer*   pageSize
page_token	pageTokenr+   r,   r#   r#   r$   $_ListFileSearchStoresConfig_to_mldev   s   
rQ   c                 C   s*   i }t | dgd urtt | dg| |S r&   )r   rQ   r,   r#   r#   r$   (_ListFileSearchStoresParameters_to_mldev   s   rR   c                 C   s   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur@t|dgdd t | dgD  |S )	NrH   rI   nextPageTokennext_page_tokenfileSearchStoresfile_search_storesc                 S   r5   r#   r#   r6   r#   r#   r$   r9     r:   z<_ListFileSearchStoresResponse_from_mldev.<locals>.<listcomp>r+   r,   r#   r#   r$   (_ListFileSearchStoresResponse_from_mldev   s   rW   c                 C   s   i }t | dgd urt|dgt | dg t | dgd ur(t|dgt | dg t | dgd ur@t|dgdd t | dgD  t | d	gd urSt|d
gt | d	g |S )N	mime_typemimeTyper   r   r3   r4   c                 S   r5   r#   r#   r6   r#   r#   r$   r9     r:   z;_UploadToFileSearchStoreConfig_to_mldev.<locals>.<listcomp>r;   r<   r+   r,   r#   r#   r$   '_UploadToFileSearchStoreConfig_to_mldev  s$   
rZ   c                 C   r.   )NrD   r0   r'   )r   r   rZ   r,   r#   r#   r$   +_UploadToFileSearchStoreParameters_to_mldev$  s   
r[   c                 C   s.   i }t | dgd urt|dgt | dg |S )NrH   rI   r+   r,   r#   r#   r$   4_UploadToFileSearchStoreResumableResponse_from_mldev8  s   r\   c                	   @   p  e Zd ZedefddZdddeej dej	fddZ
ddd	edeej dej	fd
dZddd	edeej ddfddZdddeej dejfddZdddedeej dejfddZdddededeej dejfddZdddedeeeje ejf deej dejfddZdddedeej  de!fddZ"dddeej de#ej	 fddZ$dS )FileSearchStoresr   c                 C   
   t | jS N)r   _api_clientselfr#   r#   r$   	documentsG     
zFileSearchStores.documentsNr'   r'   c             	   C   s*  t j|d}| jjrtdt| j|}|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sbi nt|j}	t jj|	t|ddrdt|j
d
dt|j
ddt|j
dddini d}
| j|
 |
S zCreates a File Search Store.

    Args:
      config (CreateFileSearchStoreConfig | None): Optional parameters for the
        request.

    Returns:
      FileSearchStore
    rf   iThis method is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.r0   rU   r*   ?r'   Npostresponse_schemaresponse_json_schemainclude_all_fieldsrk   rl   rm   rA   kwargs)r    _CreateFileSearchStoreParametersra   vertexai
ValueErrorr(   get
format_mapr   popr'   http_optionsr	   convert_to_dictencode_unserializable_typesrequestbodyjsonloadsFileSearchStore_from_responsegetattr_verify_responserc   r'   parameter_modelrequest_dictrequest_url_dictpathquery_paramsrw   rA   response_dictreturn_valuer#   r#   r$   createK  s`   





zFileSearchStores.creater/   c             	   C   s(  t j||d}| jjr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|
t|ddrdt|j
d
dt|j
ddt|j
dddini d}| j| |S aR  Gets metadata about a FileSearchStore.

    Args:
      name (str): The resource name of the FileSearchStore. Example:
        `FileSearchStores/my-file-search-store-123`
      config (GetFileSearchStoreConfig | None): Optional parameters for the
        request.

    Returns:
      A FileSearchStore object containing the metadata.
    r/   r'   rh   r0   {name}r*   ri   r'   Nrt   rk   rl   rm   rn   ro   )r   _GetFileSearchStoreParametersra   rr   rs   r2   rt   ru   r   rv   r'   rw   r	   rx   ry   rz   r{   r|   r}   r~   r   r   r   rc   r/   r'   r   r   r   r   r   rw   rA   r   r   r#   r#   r$   rt     sZ   





zFileSearchStores.getc          	      C   s   t j||d}| jjr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	||| dS 
a  Deletes a FileSearchStore.

    Args:
      name (str): The resource name of the FileSearchStore. Example:
        `FileSearchStores/my-file-search-store-123`
      config (DeleteFileSearchStoreConfig | None): Optional parameters for the
        request.

    Returns:
      None
    r   rh   r0   r   r*   ri   r'   Ndelete)r    _DeleteFileSearchStoreParametersra   rr   rs   r1   rt   ru   r   rv   r'   rw   r	   rx   ry   rz   	rc   r/   r'   r   r   r   r   r   rw   r#   r#   r$   r     s0   




zFileSearchStores.deletec             	   C   s6  t j|d}| jjrtdt|}|d}|rd|}nd}|d}|r1| dt| }|	dd  d }|j
d urH|j
jd urH|j
j}t|}t|}| jd|||}|js`i nt|j}	| jjsnt|	}	t jj|	t|dd rdt|j
d	d t|j
d
d t|j
dd dini d}
| j|
 |
S Nrf   rh   r0   rU   r*   ri   r'   rt   rk   rl   rm   rn   ro   )r   _ListFileSearchStoresParametersra   rr   rs   rR   rt   ru   r   rv   r'   rw   r	   rx   ry   rz   r{   r|   r}   rW   ListFileSearchStoresResponser   r   r   r   r#   r#   r$   _list  s\   





zFileSearchStores._listrD   c             	   C   sh  t j||d}| jjr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|||}	|d urtt|d	d rtt j|	d
}
| j|
 |
S |	jsyi nt|	j}| jjst|}t jj|t|dd rdt|j
dd t|j
dd t|j
dd dini d}
| j|
 |
S NrD   r'   rh   r0   z>upload/v1beta/{file_search_store_name}:uploadToFileSearchStorer*   ri   r'   rj   should_return_http_response)rI   rk   rl   rm   rn   ro   )r   "_UploadToFileSearchStoreParametersra   rr   rs   r[   rt   ru   r   rv   r'   rw   r	   rx   ry   rz   r   (UploadToFileSearchStoreResumableResponser   r{   r|   r}   r\   r   rc   rD   r'   r   r   r   r   r   rw   rA   r   r   r#   r#   r$   _upload_to_file_search_store`  s   






z-FileSearchStores._upload_to_file_search_storerE   c             	   C   s:  t j|||d}| jjr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sbi nt|
j}| jjspt|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}| j| |S a  Imports a File from File Service to a FileSearchStore.

    This is a long-running operation, see aip.dev/151

    Args:
      file_search_store_name (str): The resource name of the FileSearchStore.
        Example: `fileSearchStores/my-file-search-store-123`
      file_name (str): The resource name of the File to import. Example:
        `files/abc-123`
      config (ImportFileConfig | None): Optional parameters for the request.

    Returns:
      ImportFileOperation.
    )rD   rE   r'   rh   r0   z#{file_search_store_name}:importFiler*   ri   r'   Nrj   rk   rl   rm   rn   ro   )r   _ImportFileParametersra   rr   rs   rG   rt   ru   r   rv   r'   rw   r	   rx   ry   rz   r{   r|   r}   rC   ImportFileOperationr   r   r   rc   rD   rE   r'   r   r   r   r   r   rw   rA   r   r   r#   r#   r$   import_file  sh   





zFileSearchStores.import_filefilec                C   sB  | j jrtd|du ri }nt|trt|}n|jdd}tj||d|dd\}}}i ||dd}| j	|t
jdi |d	}	|	jdu s]|	jjdu s]d
|	jjvrad|	jjvratdd
|	jjv rn|	jjd
 }
n|	jjd }
t|tjr| j j||
||d}nt|}| j j||
||d}t|j}t
jj|i dS )a~  Calls the API to upload a file to the given file search store.

    Args:
      file_search_store_name: The resource name of the FileSearchStore. Example:
        `fileSearchStores/file-search-store-123`
      file: A path to the file or an `IOBase` object to be uploaded. If it's an
        IOBase object, it must be opened in blocking (the default) mode and
        binary mode. In other words, do not use non-blocking mode or text mode.
        The given stream must be seekable, that is, it must be able to call
        `seek()` on 'path'.
      config: Optional parameters to set `display_name`, `mime_type`, and
        others.
    =This method is only supported in the Gemini Developer client.NTexclude_unsetrw   rX   user_http_optionsuser_mime_typerw   r   r   x-goog-upload-urlX-Goog-Upload-URL`Failed to upload file to file search store. Upload URL was not returned from the upload request.rw   ro   r#   )ra   rr   rs   
isinstancedict
model_dumpr
   prepare_resumable_uploadrt   r   r   UploadToFileSearchStoreConfigrI   headersKeyErrorioIOBaseupload_fileosfspathr   r|    UploadToFileSearchStoreOperationr   rc   rD   r   r'   user_config_dictrw   
size_bytes_final_config_dictrA   
upload_urlupload_responsefs_pathr   r#   r#   r$   upload_to_file_search_store  s`   



z,FileSearchStores.upload_to_file_search_storemedia_idc                C   s   | j jrtd|d}d|vrtd|d| d}d}|r2t|tr0tjd
i |}n|}d}|rDt|dgdurDt|dg}| j j	||d	}|S a  Downloads media using a Media ID.

    The media_id has the format:
      fileSearchStores/<store>/media/<blob_id>

    This is mapped to the DownloadMedia RPC which expects:
      GET /{name=fileSearchStores/*/media/*}

    Args:
      media_id: The Media ID from grounding metadata.
      config: Optional configuration for the download.

    Returns:
      bytes: The media data.
    r   /z/media/zInvalid media_id format: z;. Expected format: fileSearchStores/<store>/media/<blob_id>z
?alt=mediaNrw   r   r#   )
ra   rr   rs   lstripr   r   r   DownloadMediaConfigr   download_filerc   r   r'   clean_idr   config_modelrw   datar#   r#   r$   download_mediab  s.   



zFileSearchStores.download_mediac                C   s   | j }td|| j |d|S )a  Lists FileSearchStores.

    Args:
      config (ListFileSearchStoresConfig): Optional configuration for the list
        request.

    Returns:
      A Pager object that contains one page of file search stores. When
      iterating over
      the pager, it automatically fetches the next page if there are more.

    Usage:

    .. code-block:: python
      for file_search_store in client.file_search_stores.list():
        print(f"file search store: {file_search_store.name} -
        {file_search_store.display_name}")
    rV   rf   )r   r   rc   r'   list_requestr#   r#   r$   list  s   
zFileSearchStores.list)%__name__
__module____qualname__r   r   rd   r   r   !CreateFileSearchStoreConfigOrDictr~   r   strGetFileSearchStoreConfigOrDictrt   !DeleteFileSearchStoreConfigOrDictr    ListFileSearchStoresConfigOrDictr   r   #UploadToFileSearchStoreConfigOrDictr   r   ImportFileConfigOrDictr   r   r   r   PathLiker   r   r   r   DownloadMediaConfigOrDictbytesr   r   r   r#   r#   r#   r$   r^   E  s    
Q
S
8
F
_
`
Q
5r^   c                	   @   r]   )AsyncFileSearchStoresr   c                 C   r_   r`   )r   ra   rb   r#   r#   r$   rd     re   zAsyncFileSearchStores.documentsNrf   r'   c             	      s2  t j|d}| jjrtdt| j|}|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sfi nt|j}	t jj|	t|ddrdt|j
d
dt|j
ddt|j
dddini d}
| j|
 |
S rg   )r   rq   ra   rr   rs   r(   rt   ru   r   rv   r'   rw   r	   rx   ry   async_requestr{   r|   r}   r~   r   r   r   r   r#   r#   r$   r     sb   






zAsyncFileSearchStores.creater/   c             	      s0  t j||d}| jjr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|
t|ddrdt|j
d
dt|j
ddt|j
dddini d}| j| |S r   )r   r   ra   rr   rs   r2   rt   ru   r   rv   r'   rw   r	   rx   ry   r   r{   r|   r}   r~   r   r   r   r   r#   r#   r$   rt     s`   






zAsyncFileSearchStores.getc          	         s   t j||d}| jjr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  dS r   )r   r   ra   rr   rs   r1   rt   ru   r   rv   r'   rw   r	   rx   ry   r   r   r#   r#   r$   r   Y  s6   




zAsyncFileSearchStores.deletec             	      s>  t j|d}| jjr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|||I d H }|jsdi nt|j}	| jjsrt|	}	t jj|	t|dd rdt|j
d	d t|j
d
d t|j
dd dini d}
| j|
 |
S r   )r   r   ra   rr   rs   rR   rt   ru   r   rv   r'   rw   r	   rx   ry   r   r{   r|   r}   rW   r   r   r   r   r   r#   r#   r$   r     sb   






zAsyncFileSearchStores._listrD   c             	      sp  t j||d}| jjr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 }	|d urxt|d	d rxt j|	d
}
| j|
 |
S |	js}i nt|	j}| jjst|}t jj|t|dd rdt|j
dd t|j
dd t|j
dd dini d}
| j|
 |
S r   )r   r   ra   rr   rs   r[   rt   ru   r   rv   r'   rw   r	   rx   ry   r   r   r   r   r{   r|   r}   r\   r   r   r#   r#   r$   r     s   







z2AsyncFileSearchStores._upload_to_file_search_storerE   c             	      sB  t j|||d}| jjr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sfi nt|
j}| jjstt|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}| j| |S r   )r   r   ra   rr   rs   rG   rt   ru   r   rv   r'   rw   r	   rx   ry   r   r{   r|   r}   rC   r   r   r   r   r   r#   r#   r$   r   0  sj   






z!AsyncFileSearchStores.import_filer   c                   sV  | j jr	td|du ri }nt|trt|}n|jdd}tj||d|dd\}}}i ||dd}| j	|t
jdi |d	I dH }	|	jdu sa|	jjdu sad
|	jjvred|	jjvretdd
|	jjv rr|	jjd
 }
n|	jjd }
t|tjr| j j||
||dI dH }nt|}| j j||
||dI dH }t|j}t
jj|i dS )au  Calls the API to upload a file to the given file search store.

    Args:
      file_search_store_name: The resource name of the FileSearchStore. Example:
        `fileSearchStores/file-search-store-123`
      file: A path to the file or an `IOBase` object to be uploaded. If it's an
        IOBase object, it must be opened in blocking (the default) mode and
        binary mode. In other words, do not use non-blocking mode or text mode.
        The given stream must be seekable, that is, it must be able to call
        `seek()` on 'path'.
      config: Optional parameters to set `display_name`, `mime_type` and others.
    r   NTr   rw   rX   r   r   r   r   r   r   r   ro   r#   )ra   rr   rs   r   r   r   r
   r   rt   r   r   r   rI   r   r   r   r   async_upload_filer   r   r   r|   r   r   r   r#   r#   r$   r     sb   



z1AsyncFileSearchStores.upload_to_file_search_storer   c                   s   | j jr	td|d}d|vrtd|d| d}d}|r3t|tr1tjd
i |}n|}d}|rEt|dgdurEt|dg}| j j	||d	I dH }|S r   )
ra   rr   rs   r   r   r   r   r   r   async_download_filer   r#   r#   r$   r     s0   



z$AsyncFileSearchStores.download_mediac                   s$   | j }td|| j |dI dH |S )a7  Lists FileSearchStores asynchronously.

    Args:
      config (ListFileSearchStoresConfig): Optional parameters for the request,
        such as page_size.

    Returns:
      A Pager object that contains one page of FileSearchStores. When iterating
      over
      the pager, it automatically fetches the next page if there are more.

    Usage:

    .. code-block:: python
      async for file_search_store in await client.aio.file_search_stores.list():
        print(f"file search store: {file_search_store.name} -
        {file_search_store.display_name}")
    rV   rf   N)r   r   r   r#   r#   r$   r     s   zAsyncFileSearchStores.list)%r   r   r   r   r   rd   r   r   r   r~   r   r   r   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#   r#   r#   r$   r     s    
Q
U
:
H
_
`
P
5r   r`   )8	functoolsr   r   r|   loggingr   typingr   r   r   urllib.parser    r   r	   r
   r   r   r   ra   r   r   r   r   r   _operations_convertersr   rd   r   r   pagersr   r   	getLoggerloggerr   r   objectr%   r(   r-   r1   r2   r=   rC   rG   rB   rQ   rR   rW   rZ   r[   r\   
BaseModuler^   r   r#   r#   r#   r$   <module>   s*  






























    t