o
    i                     @   s  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mZ edZ	dPdeeeef ef deeeef  deeef fddZ	dPdeeeef ef deeeef  deeef fddZ	dPdeeeef ef deeeef  deeef fddZ	dPdeeeef ef deeeef  deeef fddZ	dPdedeeeef ef deeeef  deeef fddZ 	dPdedeeeef ef deeeef  deeef fddZ!	dPdedeeeef ef deeeef  deeef fddZ"	dPdedeeeef ef deeeef  deeef fd d!Z#	dPdeeeef ef deeeef  deeef fd"d#Z$	dPdeeeef ef deeeef  deeef fd$d%Z%	dPdeeeef ef deeeef  deeef fd&d'Z&	dPdeeeef ef deeeef  deeef fd(d)Z'	dPdedeeeef ef deeeef  deeef fd*d+Z(	dPdedeeeef ef deeeef  deeef fd,d-Z)	dPdeeeef ef deeeef  deeef fd.d/Z*	dPdeeeef ef deeeef  deeef fd0d1Z+	dPdeeeef ef deeeef  deeef fd2d3Z,	dPdeeeef ef deeeef  deeef fd4d5Z-	dPdeeeef ef deeeef  deeef fd6d7Z.	dPdeeeef ef deeeef  deeef fd8d9Z/	dPdeeeef ef deeeef  deeef fd:d;Z0	dPdeeeef ef deeeef  deeef fd<d=Z1	dPdeeeef ef deeeef  deeef fd>d?Z2	dPdeeeef ef deeeef  deeef fd@dAZ3	dPdeeeef ef deeeef  deeef fdBdCZ4	dPdeeeef ef deeeef  deeef fdDdEZ5	dPdeeeef ef deeeef  deeef fdFdGZ6	dPdedeeeef ef deeeef  deeef fdHdIZ7	dPdedeeeef ef deeeef  deeef fdJdKZ8G dLdM dMe	j9Z:G dNdO dOe	j9Z;dS )Q    N)AnyOptionalUnion)	urlencode   )_api_module)_common)_transformers)types)BaseApiClient)get_value_by_path)set_value_by_path)
AsyncPagerPagerzgoogle_genai.cachesfrom_objectparent_objectreturnc                 C   sl   i }t | dgd urt|dgt | dg t | dgd ur!tdt | dgd ur4t|dgt | dg |S )Ndatadisplay_name6display_name parameter is not supported in Gemini API.	mime_typemimeTypegetvsetv
ValueErrorr   r   	to_object r   Y/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/google/genai/caches.py_Blob_to_mldev$   s   r    c                    sb   i  t | dgd urt dg fddt | dgD  t | dgd ur/t dgt | dg  S )Npartsc                       g | ]}t | qS r   )_Part_to_mldev.0itemr   r   r   
<listcomp>>       z%_Content_to_mldev.<locals>.<listcomp>roler   r   r   r   r   r'   r   _Content_to_mldev5   s   

	r-   c              	      sX  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rXt|dg fddtt | dgD  t | d	gd urqt|d
gttt | d	g  t | dgd urt|dg fddt | dgD  t | dgd urt|dgt | dg t | dgd urtd S )Nttlexpire_time
expireTimer   displayNamecontentsc                    r"   r   )r-   r$   r'   r   r   r(   ]   r)   z7_CreateCachedContentConfig_to_mldev.<locals>.<listcomp>system_instructionsystemInstructiontoolsc                    r"   r   )_Tool_to_mldevr$   r'   r   r   r(   p   r)   tool_config
toolConfigkms_key_namez6kms_key_name parameter is not supported in Gemini API.)r   r   t
t_contentsr-   	t_contentr   r,   r   r'   r   #_CreateCachedContentConfig_to_mldevJ   sH   
	

	r=   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rVt|dgdd tt | dgD  t | d	gd urlt|d
gtt | d	g t | dgd urt|dg fddt | dgD  t | dgd urt|dgt | dg t | dgd urt|ddgt | dg  S )Nr.   r/   r0   r   r1   r2   c                 S      g | ]}|qS r   r   r$   r   r   r   r(          z8_CreateCachedContentConfig_to_vertex.<locals>.<listcomp>r3   r4   r5   c                    r"   r   )_Tool_to_vertexr$   r'   r   r   r(      r)   r7   r8   r9   encryption_spec
kmsKeyName)r   r   r:   r;   r<   r,   r   r'   r   $_CreateCachedContentConfig_to_vertex   sH   

	
rC   
api_clientc              	   C   X   i }t |dgd urt|dgt| t |dg t |dgd ur*tt |dg| |S Nmodelconfig)r   r   r:   t_caches_modelr=   rD   r   r   r   r   r   r   '_CreateCachedContentParameters_to_mldev      rK   c              	   C   rE   rF   )r   r   r:   rI   rC   rJ   r   r   r   (_CreateCachedContentParameters_to_vertex   rL   rM   c              	   C   8   i }t |dgd urt|ddgt| t |dg |S Nname_urlr   r   r:   t_cached_content_namerJ   r   r   r   '_DeleteCachedContentParameters_to_mldev      rT   c              	   C   rN   rO   rR   rJ   r   r   r   (_DeleteCachedContentParameters_to_vertex   rU   rV   c                 C   .   i }t | dgd urt|dgt | dg |S NsdkHttpResponsesdk_http_responser+   r   r   r   r   '_DeleteCachedContentResponse_from_mldev      r[   c                 C   rW   rX   r+   r   r   r   r   (_DeleteCachedContentResponse_from_vertex
  r\   r]   c                 C   sl   i }t | dgd urtdt | dgd ur!t|dgt | dg t | dgd ur4t|dgt | dg |S )Nr   r   file_urifileUrir   r   r   r   r   r   r   r   r   _FileData_to_mldev  s   ra   c                 C   s  i }t | dgd urtdt | dgd ur!t|dgt | dg t | dgd ur4t|dgt | dg t | dgd urGt|dgt | dg t | dgd urZt|dgt | dg t | dgd urmt|dgt | dg t | d	gd urt|d
gt | d	g |S )Nbehaviorz1behavior parameter is not supported in Vertex AI.descriptionrP   
parametersparameters_json_schemaparametersJsonSchemaresponseresponse_json_schemaresponseJsonSchemar`   r   r   r   r   _FunctionDeclaration_to_vertex(  s0   

rj   c              	   C   rN   rO   rR   rJ   r   r   r   $_GetCachedContentParameters_to_mldevM  rU   rk   c              	   C   rN   rO   rR   rJ   r   r   r   %_GetCachedContentParameters_to_vertex]  rU   rl   c                 C   sF   i }t | dgd urtdt | dgd ur!t|dgt | dg |S )Nauth_configz5auth_config parameter is not supported in Gemini API.enable_widgetenableWidgetr`   r   r   r   r   _GoogleMaps_to_mldevm  s   rp   c                 C   s^   i }t | dgd urtdt | dgd urtdt | dgd ur-t|dgt | dg |S )Nexclude_domainsz9exclude_domains parameter is not supported in Gemini API.blocking_confidencez=blocking_confidence parameter is not supported in Gemini API.time_range_filtertimeRangeFilterr`   r   r   r   r   _GoogleSearch_to_mldev{  s   ru   c                 C   X   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_size_querypageSize
page_token	pageTokenr+   r   r   r   r   "_ListCachedContentsConfig_to_mldev     
r}   c                 C   rv   rw   r+   r   r   r   r   #_ListCachedContentsConfig_to_vertex  r~   r   c                 C   *   i }t | dgd urtt | dg| |S NrH   )r   r}   r   r   r   r   &_ListCachedContentsParameters_to_mldev  s   r   c                 C   r   r   )r   r   r   r   r   r   '_ListCachedContentsParameters_to_vertex  s   r   c                 C      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 )	NrY   rZ   nextPageTokennext_page_tokencachedContentscached_contentsc                 S   r>   r   r   r$   r   r   r   r(     r?   z:_ListCachedContentsResponse_from_mldev.<locals>.<listcomp>r+   r   r   r   r   &_ListCachedContentsResponse_from_mldev     r   c                 C   r   )	NrY   rZ   r   r   r   r   c                 S   r>   r   r   r$   r   r   r   r(     r?   z;_ListCachedContentsResponse_from_vertex.<locals>.<listcomp>r+   r   r   r   r   '_ListCachedContentsResponse_from_vertex  r   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rQt|dgtt | dg| t | d	gd urdt|d
gt | d	g t | dgd urzt|dgtt | dg| t | dgd urt|dgt | dg t | dgd urt|dgt | dg t | dgd urt|dgt | dg t | dgd urt|dgt | dg |S )Nfunction_callfunctionCallcode_execution_resultcodeExecutionResultexecutable_codeexecutableCode	file_datafileDatafunction_responsefunctionResponseinline_data
inlineDatatextthoughtthought_signaturethoughtSignaturevideo_metadatavideoMetadata)r   r   ra   r    r   r   r   r   r#     sT   


r#   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t | dgd ur9t|dgt | dg t | d	gd urLt|d
gt | d	g t | dgd ur_t|dgt | dg t | dgd urrt|dgt | dg t | dgd ur~tdt | dgd urt|dgtt | dg| t | dgd urt|dgtt | dg| t | dgd urt|dgt | dg |S )Nfunction_declarationsfunctionDeclarationsc                 S   r>   r   r   r$   r   r   r   r(   E  r?   z"_Tool_to_mldev.<locals>.<listcomp>	retrievalz3retrieval parameter is not supported in Gemini API.google_search_retrievalgoogleSearchRetrievalcomputer_usecomputerUsefile_search
fileSearchcode_executioncodeExecutionenterprise_web_searchz?enterprise_web_search parameter is not supported in Gemini API.google_maps
googleMapsgoogle_searchgoogleSearchurl_context
urlContext)r   r   r   rp   ru   r   r   r   r   r6   <  sP   
r6   c                    s  i  t | dgd urt dg fddt | dgD  t | dgd ur/t dgt | dg t | dgd urBt dgt | dg t | dgd urUt d	gt | dg t | d
gd uratdt | dgd urtt dgt | dg t | dgd urt dgt | dg t | dgd urt dgt | dg t | dgd urt dgt | dg t | dgd urt dgt | dg  S )Nr   r   c                    r"   r   )rj   r$   r'   r   r   r(   }  r)   z#_Tool_to_vertex.<locals>.<listcomp>r   r   r   r   r   r   z4file_search parameter is not supported in Vertex AI.r   r   r   enterpriseWebSearchr   r   r   r   r   r   r   r,   r   r'   r   r@   t  sH   

	

r@   c                 C   T   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 |S Nr.   r/   r0   r+   r   r   r   r   #_UpdateCachedContentConfig_to_mldev     r   c                 C   r   r   r+   r   r   r   r   $_UpdateCachedContentConfig_to_vertex  r   r   c              	   C   Z   i }t |dgd urt|ddgt| t |dg t |dgd ur+tt |dg| |S NrP   rQ   rH   )r   r   r:   rS   r   rJ   r   r   r   '_UpdateCachedContentParameters_to_mldev     r   c              	   C   r   r   )r   r   r:   rS   r   rJ   r   r   r   (_UpdateCachedContentParameters_to_vertex  r   r   c                   @      e Z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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ejfddZdddeej dejfddZdddeej deej fddZdS )CachesNrH   rG   rH   r   c                C     t j||d}| jjr!t| j|}|d}|rd|}nd}nt| j|}|d}|r4d|}nd}|d}|rF| dt| }|	dd d}|j
dur]|j
jdur]|j
j}t|}t|}| jd|||}	|	jsui nt|	j}
t jj|
| d	}| j| |S )
a  Creates a cached contents resource.

    Usage:

    .. code-block:: python

      contents = ... // Initialize the content to cache.
      response = client.caches.create(
          model= ... // The publisher model id
          contents=contents,
          config={
              'display_name': 'test cache',
              'system_instruction': 'What is the sum of the two pdfs?',
              'ttl': '86400s',
          },
      )
    rG   rH   rQ   r   ry   ?rH   Npostrg   kwargs)r
   _CreateCachedContentParameters_api_clientvertexairM   get
format_maprK   r   poprH   http_optionsr   convert_to_dictencode_unserializable_typesrequestbodyjsonloadsCachedContent_from_response
model_dump_verify_responseselfrG   rH   parameter_modelrequest_dictrequest_url_dictpathquery_paramsr   rg   response_dictreturn_valuer   r   r   create  sL   





zCaches.createrP   c                C   r   )
zGets cached content configurations.

    .. code-block:: python

      client.caches.get(name= ... ) // The server-generated resource name.
    rP   rH   rQ   {name}ry   r   rH   Nr   r   )r
   _GetCachedContentParametersr   r   rl   r   r   rk   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   rH   r   r   r   r   r   r   rg   r   r   r   r   r   r   A  sH   





z
Caches.getc                C   sJ  t j||d}| jjr!t| j|}|d}|rd|}nd}nt| j|}|d}|r4d|}nd}|d}|rF| dt| }|	dd d}|j
dur]|j
jdur]|j
j}t|}t|}| jd|||}	|	jsui nt|	j}
| jjrt|
}
| jjst|
}
t jj|
| d	}t j|	jd
|_| j| |S )zDeletes cached content.

    Usage:

    .. code-block:: python

      client.caches.delete(name= ... ) // The server-generated resource name.
    r   rQ   r   ry   r   rH   Ndeleter   headers)r
   _DeleteCachedContentParametersr   r   rV   r   r   rT   r   r   rH   r   r   r   r   r   r   r   r   r]   r[   DeleteCachedContentResponser   r   HttpResponser   rZ   r   r   r   r   r   r     sZ   





zCaches.deletec                C   r   )
zUpdates cached content configurations.

    .. code-block:: python

      response = client.caches.update(
          name= ... // The server-generated resource name.
          config={
              'ttl': '7600s',
          },
      )
    r   rQ   r   ry   r   rH   Npatchr   )r
   _UpdateCachedContentParametersr   r   r   r   r   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   update  sL   





zCaches.updatec                C   s@  t j|d}| jjrt|}|d}|rd|}nd}nt|}|d}|r/d|}nd}|d}|rA| dt| }|	dd d}|j
durX|j
jdurX|j
j}t|}t|}| jd|||}|jspi nt|j}	| jjr~t|	}	| jjst|	}	t jj|	| d	}
t j|jd
|
_| j|
 |
S )zLists cached content configurations.

    .. code-block:: python

      cached_contents = client.caches.list(config={'page_size': 2})
      for cached_content in cached_contents:
        print(cached_content)
    r   rQ   r   ry   r   rH   Nr   r   r   )r
   _ListCachedContentsParametersr   r   r   r   r   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   ListCachedContentsResponser   r   r   r   rZ   r   r   rH   r   r   r   r   r   r   rg   r   r   r   r   r   _list  sL   





zCaches._listc                C   s   t d| j| j|d|S Nr   r   )r   r   r   rH   r   r   r   listZ  s   
zCaches.list)__name__
__module____qualname__strr   r
   CreateCachedContentConfigOrDictr   r   GetCachedContentConfigOrDictr   DeleteCachedContentConfigOrDictr   r   UpdateCachedContentConfigOrDictr   ListCachedContentsConfigOrDictr   r   r   r   r   r   r   r   r     sZ    
R
E
Q
I
Dr   c                   @   r   )AsyncCachesNr   rG   rH   r   c                   "  t j||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd d}|j
dur^|j
jdur^|j
j}t|}t|}| jd|||I dH }	|	jsyi nt|	j}
t jj|
| d	}| j| |S )
a  Creates a cached contents resource.

    Usage:

    .. code-block:: python

      contents = ... // Initialize the content to cache.
      response = await client.aio.caches.create(
          model= ... // The publisher model id
          contents=contents,
          config={
              'display_name': 'test cache',
              'system_instruction': 'What is the sum of the two pdfs?',
              'ttl': '86400s',
          },
      )
    r   rQ   r   ry   r   rH   Nr   r   )r
   r   r   r   rM   r   r   rK   r   r   rH   r   r   r   r   async_requestr   r   r   r   r   r   r   r   r   r   r   r   g  sN   






zAsyncCaches.createrP   c                   r   )
zGets cached content configurations.

    .. code-block:: python

      await client.aio.caches.get(name= ... ) // The server-generated resource
      name.
    r   rQ   r   ry   r   rH   Nr   r   )r
   r   r   r   rl   r   r   rk   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     sN   






zAsyncCaches.getc                   sR  t j||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd d}|j
dur^|j
jdur^|j
j}t|}t|}| jd|||I dH }	|	jsyi nt|	j}
| jjrt|
}
| jjst|
}
t jj|
| d	}t j|	jd
|_| j| |S )zDeletes cached content.

    Usage:

    .. code-block:: python

      await client.aio.caches.delete(name= ... ) // The server-generated
      resource name.
    r   rQ   r   ry   r   rH   Nr   r   r   )r
   r   r   r   rV   r   r   rT   r   r   rH   r   r   r   r   r   r   r   r   r]   r[   r   r   r   r   r   rZ   r   r   r   r   r   r     s\   






zAsyncCaches.deletec                   r   )
zUpdates cached content configurations.

    .. code-block:: python

      response = await client.aio.caches.update(
          name= ... // The server-generated resource name.
          config={
              'ttl': '7600s',
          },
      )
    r   rQ   r   ry   r   rH   Nr   r   )r
   r   r   r   r   r   r   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   G  sN   






zAsyncCaches.updatec                   sH  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|||I dH }|jsti nt|j}	| jjrt|	}	| jjst|	}	t jj|	| d	}
t j|jd
|
_| j|
 |
S )zLists cached content configurations.

    .. code-block:: python

      cached_contents = await client.aio.caches.list(config={'page_size': 2})
      async for cached_content in cached_contents:
        print(cached_content)
    r   rQ   r   ry   r   rH   Nr   r   r   )r
   r   r   r   r   r   r   r   r   r   rH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rZ   r   r   r   r   r   r     sR   






zAsyncCaches._listc                   s    t d| j| j|dI d H |S r   )r   r   r   r   r   r   r     s   zAsyncCaches.list)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   e  sZ    
R
H
R
I
Fr   )N)<r   loggingtypingr   r   r   urllib.parser    r   r   r	   r:   r
   r   r   r   r   r   r   pagersr   r   	getLoggerloggerdictr   objectr    r-   r=   rC   rK   rM   rT   rV   r[   r]   ra   rj   rk   rl   rp   ru   r}   r   r   r   r   r   r#   r6   r@   r   r   r   r   
BaseModuler   r   r   r   r   r   <module>   s  






7

7















(





















<

:

7







  v