o
    %g                  	   @   s  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	djdedeeef dee defddZ	djdedeeef dee defddZ	djdedeeef dee defddZ	djdedeeef dee defddZ	djdedeeef dee defddZ	djdedeeef dee defddZ	djdedeeef dee defddZ 	djdedeeef dee defd d!Z!	djdedeeef dee defd"d#Z"	djdedeeef dee defd$d%Z#	djdedeeef dee defd&d'Z$	djdedeeef dee defd(d)Z%	djdedeeef dee defd*d+Z&	djdedeeef dee defd,d-Z'	djdedeeef dee defd.d/Z(	djdedeeef dee defd0d1Z)	djdedeeef dee defd2d3Z*	djdedeeef dee defd4d5Z+	djdedeeef dee defd6d7Z,	djdedeeef dee defd8d9Z-	djdedeeef dee defd:d;Z.	djdedeeef dee defd<d=Z/	djdedeeef dee defd>d?Z0	djdedeeef dee defd@dAZ1	djdedeeef dee defdBdCZ2	djdedeeef dee defdDdEZ3	djdedeeef dee defdFdGZ4	djdedeeef dee defdHdIZ5	djdedeeef dee defdJdKZ6	djdedeeef dee defdLdMZ7	djdedeeef dee defdNdOZ8	djdedeeef dee defdPdQZ9	djdedeeef dee defdRdSZ:	djdedeeef dee defdTdUZ;	djdedeeef dee defdVdWZ<	djdedeeef dee defdXdYZ=	djdedeeef dee defdZd[Z>	djdedeeef dee defd\d]Z?	djdedeeef dee defd^d_Z@	djdedeeef dee defd`daZA	djdedeeef dee defdbdcZB	djdedeeef dee defdddeZCG dfdg dgejDZEG dhdi diejDZFdS )k    N)AnyOptionalUnion)	urlencode   )_api_module)_common)_transformers)types)BaseApiClient)get_value_by_path)set_value_by_path)
AsyncPagerPagerzgoogle_genai.caches
api_clientfrom_objectparent_objectreturnc                 C   sP  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 t |dgd urt|dgt |dg t |dgd urt|dgt |dg |S )Nvideo_metadataz8video_metadata parameter is not supported in Gemini API.thoughtcode_execution_resultcodeExecutionResultexecutable_codeexecutableCode	file_datafileDatafunction_callfunctionCallfunction_responsefunctionResponseinline_data
inlineDatatextgetv
ValueErrorsetvr   r   r   	to_object r)   U/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/google/genai/caches.py_Part_to_mldev!   s8   

r+   c                    d   i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg S )Npartsc                       g | ]}t  |qS r)   )r+   .0itemr   r(   r)   r*   
<listcomp>W       
z%_Content_to_mldev.<locals>.<listcomp>roler$   r&   r   r   r   r)   r2   r*   _Content_to_mldevM      
	r8   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t |dgd ur2tdt |d	gd ur>td
t |dgd urJtdt |dgd urVtdt |dgd urit|dgt |dg t |dgd ur|t|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 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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r>t|dgt |dg t |dgd urRt|dgt |dg t |d gd urft|d gt |d g t |d!gd urzt|d!gt |d!g |S )"Nexamplez1example parameter is not supported in Gemini API.patternz1pattern parameter is not supported in Gemini API.defaultz1default parameter is not supported in Gemini API.
max_lengthz4max_length parameter is not supported in Gemini API.
min_lengthz4min_length parameter is not supported in Gemini API.min_propertiesz8min_properties parameter is not supported in Gemini API.max_propertiesz8max_properties parameter is not supported in Gemini API.any_ofanyOfdescriptionenumformatitems	max_itemsmaxItemsmaximum	min_itemsminItemsminimumnullable
propertiesproperty_orderingpropertyOrderingrequiredtitletyper#   r'   r)   r)   r*   _Schema_to_mldevc   sd   
rT   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 |S )Nresponsez2response parameter is not supported in Gemini API.rC   name
parametersr#   r'   r)   r)   r*   _FunctionDeclaration_to_mldev   s   rX   c                 C      i }|S Nr)   r'   r)   r)   r*   _GoogleSearch_to_mldev      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 Nmodedynamic_thresholddynamicThresholdr6   r'   r)   r)   r*    _DynamicRetrievalConfig_to_mldev      
rb   c                 C   6   i }t |dgd urt|dgt| t |dg| |S Ndynamic_retrieval_configdynamicRetrievalConfig)r$   r&   rb   r'   r)   r)   r*   _GoogleSearchRetrieval_to_mldev      

rh   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t |dgd ur@tdgt t |dg t |d	gd urWtd
gt t |d	g t |dgd urjtdgt |dg S )Nfunction_declarationsfunctionDeclarationsc                    r.   r)   )rX   r/   r2   r)   r*   r3     r4   z"_Tool_to_mldev.<locals>.<listcomp>	retrievalz3retrieval parameter is not supported in Gemini API.google_searchgoogleSearchgoogle_search_retrievalgoogleSearchRetrievalcode_executioncodeExecution)r$   r&   r%   r[   rh   r7   r)   r2   r*   _Tool_to_mldev   s@   
	

rs   c                 C   r]   Nr_   allowed_function_namesallowedFunctionNamesr6   r'   r)   r)   r*   _FunctionCallingConfig_to_mldev%  rc   rw   c                 C   rd   Nfunction_calling_configfunctionCallingConfig)r$   r&   rw   r'   r)   r)   r*   _ToolConfig_to_mldev8  ri   r{   c                    R  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rZt|dg fddt t |dgD  t |d	gd urut|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 t |dg S )Nttlexpire_time
expireTimedisplay_namedisplayNamecontentsc                    r.   r)   )r8   r/   r2   r)   r*   r3   `  r4   z7_CreateCachedContentConfig_to_mldev.<locals>.<listcomp>system_instructionsystemInstructiontoolsc                    r.   r)   )rs   r/   r2   r)   r*   r3   w  r4   tool_config
toolConfig)r$   r&   t
t_contentsr8   	t_contentr{   r7   r)   r2   r*   #_CreateCachedContentConfig_to_mldevL  X   

	r   c              	   C   d   i }t |dgd urt|dgt| t |dg t |dgd ur0t|dgt| t |dg| |S Nmodelconfig)r$   r&   r   t_caches_modelr   r'   r)   r)   r*   '_CreateCachedContentParameters_to_mldev      r   c              	   C   ^   i }t |dgd urt|ddgt| t |dg t |dgd ur-t|dgt |dg |S NrV   _urlr   r$   r&   r   t_cached_content_namer'   r)   r)   r*   $_GetCachedContentParameters_to_mldev     r   c              	   C   r   r   r   r'   r)   r)   r*   '_DeleteCachedContentParameters_to_mldev  r   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~   r   r6   r'   r)   r)   r*   #_UpdateCachedContentConfig_to_mldev     r   c              	   C   f   i }t |dgd urt|ddgt| t |dg t |dgd ur1t|dgt| t |dg| |S r   )r$   r&   r   r   r   r'   r)   r)   r*   '_UpdateCachedContentParameters_to_mldev      r   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	pageTokenr6   r'   r)   r)   r*   "_ListCachedContentsConfig_to_mldev     
r   c                 C   6   i }t |dgd urt|dgt| t |dg| |S Nr   )r$   r&   r   r'   r)   r)   r*   &_ListCachedContentsParameters_to_mldev     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rat|d	gt |dg 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 |S )Nr   videoMetadatar   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r6   r'   r)   r)   r*   _Part_to_vertex  s8   

r   c                    r,   )Nr-   c                    r.   r)   )r   r/   r2   r)   r*   r3   O  r4   z&_Content_to_vertex.<locals>.<listcomp>r5   r6   r7   r)   r2   r*   _Content_to_vertexE  r9   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rat|dgt |dg 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 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rt|dgt |dg t |dgd ur!t|dgt |dg t |dgd ur5t|dgt |dg t |dgd urIt|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 |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;   r<   r=   	maxLengthr>   	minLengthr?   minPropertiesr@   maxPropertiesrA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   r6   r'   r)   r)   r*   _Schema_to_vertex[  sd   
r   c                 C   s   i }t |dgd urt|dgt| 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rRt|dgt |dg |S )NrU   rC   rV   rW   )r$   r&   r   r'   r)   r)   r*   _FunctionDeclaration_to_vertex  s    r   c                 C   rY   rZ   r)   r'   r)   r)   r*   _GoogleSearch_to_vertex  r\   r   c                 C   r]   r^   r6   r'   r)   r)   r*   !_DynamicRetrievalConfig_to_vertex  rc   r   c                 C   rd   re   )r$   r&   r   r'   r)   r)   r*    _GoogleSearchRetrieval_to_vertex  ri   r   c                    s   i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg t |dgd urGtdgt t |dg t |dgd ur^td	gt t |dg t |d
gd urqtdgt |d
g S )Nrj   rk   c                    r.   r)   )r   r/   r2   r)   r*   r3      r4   z#_Tool_to_vertex.<locals>.<listcomp>rl   rm   rn   ro   rp   rq   rr   )r$   r&   r   r   r7   r)   r2   r*   _Tool_to_vertex  s@   
	

r   c                 C   r]   rt   r6   r'   r)   r)   r*    _FunctionCallingConfig_to_vertex#  rc   r   c                 C   rd   rx   )r$   r&   r   r'   r)   r)   r*   _ToolConfig_to_vertex6  ri   r   c                    r|   )Nr}   r~   r   r   r   r   c                    r.   r)   )r   r/   r2   r)   r*   r3   ^  r4   z8_CreateCachedContentConfig_to_vertex.<locals>.<listcomp>r   r   r   c                    r.   r)   )r   r/   r2   r)   r*   r3   u  r4   r   r   )r$   r&   r   r   r   r   r   r7   r)   r2   r*   $_CreateCachedContentConfig_to_vertexJ  r   r   c              	   C   r   r   )r$   r&   r   r   r   r'   r)   r)   r*   (_CreateCachedContentParameters_to_vertex  r   r   c              	   C   r   r   r   r'   r)   r)   r*   %_GetCachedContentParameters_to_vertex  r   r   c              	   C   r   r   r   r'   r)   r)   r*   (_DeleteCachedContentParameters_to_vertex  r   r   c                 C   r   r   r6   r'   r)   r)   r*   $_UpdateCachedContentConfig_to_vertex  r   r   c              	   C   r   r   )r$   r&   r   r   r   r'   r)   r)   r*   (_UpdateCachedContentParameters_to_vertex  r   r   c                 C   r   r   r6   r'   r)   r)   r*   #_ListCachedContentsConfig_to_vertex  r   r   c                 C   r   r   )r$   r&   r   r'   r)   r)   r*   '_ListCachedContentsParameters_to_vertex  r   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t |dg t |dgd urNt|dgt |dg t |dgd urat|dgt |dg t |d	gd urtt|d
gt |d	g t |dgd urt|dgt |dg |S NrV   r   r   r   
createTimecreate_time
updateTimeupdate_timer   r~   usageMetadatausage_metadatar6   r'   r)   r)   r*   _CachedContent_from_mldev      r   c                 C   rY   rZ   r)   r'   r)   r)   r*   '_DeleteCachedContentResponse_from_mldev5  r\   r   c                    d   i t |dgd urtdgt |dg t |dgd ur0tdg fddt |dgD  S )NnextPageTokennext_page_tokencachedContentscached_contentsc                    r.   r)   )r   r/   r2   r)   r*   r3   L  r4   z:_ListCachedContentsResponse_from_mldev.<locals>.<listcomp>r6   r7   r)   r2   r*   &_ListCachedContentsResponse_from_mldev?     
	r   c                 C   r   r   r6   r'   r)   r)   r*   _CachedContent_from_vertexU  r   r   c                 C   rY   rZ   r)   r'   r)   r)   r*   (_DeleteCachedContentResponse_from_vertexs  r\   r   c                    r   )Nr   r   r   r   c                    r.   r)   )r   r/   r2   r)   r*   r3     r4   z;_ListCachedContentsResponse_from_vertex.<locals>.<listcomp>r6   r7   r)   r2   r*   '_ListCachedContentsResponse_from_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r   r   r   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jr{t| j|	}	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',
          },
      )
    r   r   r   r   r   ?r   NpostrU   kwargs)r
   _CreateCachedContentParameters_api_clientvertexair   get
format_mapr   r   popr   http_optionsr   convert_to_dictencode_unserializable_typesrequestr   r   CachedContent_from_response
model_dump_verify_responseselfr   r   parameter_modelrequest_dictrequest_url_dictpathquery_paramsr   response_dictreturn_valuer)   r)   r*   create  sT   





zCaches.createrV   c                C   r   )
zGets cached content configurations.

    .. code-block:: python

      client.caches.get(name= ... ) // The server-generated resource name.
    rV   r   r   {name}r   r   r   Nr   r   )r
   _GetCachedContentParametersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rV   r   r   r   r   r   r   r   r   r   r)   r)   r*   r     sT   





z
Caches.getc                C   r   )
zDeletes cached content.

    Usage:

    .. code-block:: python

      client.caches.delete(name= ... ) // The server-generated resource name.
    r   r   r   r   r   r   Ndeleter   )r
   _DeleteCachedContentParametersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   DeleteCachedContentResponser   r   r   r   r)   r)   r*   r  0  sX   





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   r   r   r   r   r   Npatchr   )r
   _UpdateCachedContentParametersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   r)   r*   update|  sT   





zCaches.updatec          
      C   s$  t j|d}| jjr t| j|}|d}|rd|}nd}nt| j|}|d}|r3d|}nd}|d}|rE| dt| }|	dd d}|j
dur\|j
jdur\|j
j}t|}t|}| jd|||}| jjrzt| j|}nt| j|}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   r   r   r   r   r   Nr   r   )r
   _ListCachedContentsParametersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ListCachedContentsResponser   r   r   
r   r   r   r   r   r   r   r   r   r   r)   r)   r*   _list  sV   





zCaches._listc                C   s   t d| j| j|d|S Nr   r   )r   r
  r   r   r)   r)   r*   list  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    
W
L
P
N
Ir   c                   @   r   )AsyncCachesNr   r   r   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jrt| j|	}	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   r   r   r   r   r   Nr   r   )r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   async_requestr   r   r   r   r   r   r   r)   r)   r*   r     sV   






zAsyncCaches.createrV   c                   r  )
zGets cached content configurations.

    .. code-block:: python

      await client.aio.caches.get(name= ... ) // The server-generated resource
      name.
    r   r   r   r   r   r   Nr   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   q  sV   






zAsyncCaches.getc                   r  )
zDeletes cached content.

    Usage:

    .. code-block:: python

      await client.aio.caches.delete(name= ... ) // The server-generated
      resource name.
    r   r   r   r   r   r   Nr  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    sZ   






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   r   r   r   r   r   Nr  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    sV   






zAsyncCaches.updatec          
         s,  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|||I dH }| jjr~t| j|}nt| j|}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   r   r   r   r   r   Nr   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
  T  sX   






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    sZ    
W
M
Q
N
Ir  rZ   )Gloggingtypingr   r   r   urllib.parser    r   r   r	   r   r
   r   r   r   r$   r   r&   pagersr   r   	getLoggerloggerdictobjectr+   r8   rT   rX   r[   rb   rh   rs   rw   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   r   r   r   r   r   
BaseModuler   r  r)   r)   r)   r*   <module>   sj  


/



R









0





@















/



R









0





@















!





!



   