o
    0Xxi                  	   @   s  d dl 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 	didedeeef dedefddZ	didedeeef dedefddZ	didedeeef dedefddZ	didedeeef dedefddZ	didedeeef dedefddZ	didedeeef dedefddZ	didedeeef dedefddZ	didedeeef dedefdd Z	didedeeef dedefd!d"Z	didedeeef dedefd#d$Z	didedeeef dedefd%d&Z 	didedeeef dedefd'd(Z!	didedeeef dedefd)d*Z"	didedeeef dedefd+d,Z#	didedeeef dedefd-d.Z$	didedeeef dedefd/d0Z%	didedeeef dedefd1d2Z&	didedeeef dedefd3d4Z'	didedeeef dedefd5d6Z(	didedeeef dedefd7d8Z)	didedeeef dedefd9d:Z*	didedeeef dedefd;d<Z+	didedeeef dedefd=d>Z,	didedeeef dedefd?d@Z-	didedeeef dedefdAdBZ.	didedeeef dedefdCdDZ/	didedeeef dedefdEdFZ0	didedeeef dedefdGdHZ1	didedeeef dedefdIdJZ2	didedeeef dedefdKdLZ3	didedeeef dedefdMdNZ4	didedeeef dedefdOdPZ5	didedeeef dedefdQdRZ6	didedeeef dedefdSdTZ7	didedeeef dedefdUdVZ8	didedeeef dedefdWdXZ9	didedeeef dedefdYdZZ:	didedeeef dedefd[d\Z;	didedeeef dedefd]d^Z<	didedeeef dedefd_d`Z=	didedeeef dedefdadbZ>	didedeeef dedefdcddZ?G dedf dfej@ZAG dgdh dhej@ZBdS )j    )OptionalUnion)	urlencode   )_api_module)_common)_transformers)types)	ApiClient)get_value_by_path)set_value_by_path)
AsyncPagerPagerN
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(   R/home/air/biblejyuku/back/venv/lib/python3.10/site-packages/google/genai/caches.py_Part_to_mldev   s8   

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!   r#   r%   r&   r(   r(   r)   _Part_to_vertexJ   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>       
z%_Content_to_mldev.<locals>.<listcomp>roler,   r   r   r   r(   r4   r)   _Content_to_mldevv      
	r9   c                    r.   )Nr/   c                    r0   r(   )r-   r1   r4   r(   r)   r5      r6   z&_Content_to_vertex.<locals>.<listcomp>r7   r,   r8   r(   r4   r)   _Content_to_vertex   r:   r;   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 t |dgd ur9tdt |d	gd urEtd
t |dgd urQtdt |dgd ur]tdt |dgd uritdt |dgd urutdt |dgd urtdt |dgd urtdt |dgd urtdt |dgd urtdt |dgd urtdt |dgd urtd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r2t|d$gt |d$g t |d%gd urFt|d%gt |d%g |S )&N	min_itemsz3min_items parameter is not supported in Gemini API.examplez1example parameter is not supported in Gemini API.property_orderingpropertyOrderingpatternz1pattern parameter is not supported in Gemini API.minimumz1minimum parameter is not supported in Gemini API.defaultz1default parameter is not supported in Gemini API.any_ofz0any_of parameter is not supported in Gemini API.
max_lengthz4max_length parameter is not supported in Gemini API.titlez/title 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_itemsz3max_items parameter is not supported in Gemini API.maximumz1maximum parameter is not supported in Gemini API.nullablez2nullable parameter is not supported in Gemini API.max_propertiesz8max_properties parameter is not supported in Gemini API.typedescriptionenumformatitems
propertiesrequiredr"   r&   r(   r(   r)   _Schema_to_mldev   sd   
rS   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<   minItemsr=   r>   r?   r@   rA   rB   rC   anyOfrD   	maxLengthrE   rF   	minLengthrG   minPropertiesrH   maxItemsrI   rJ   rK   maxPropertiesrL   rM   rN   rO   rP   rQ   rR   r,   r&   r(   r(   r)   _Schema_to_vertex   sd   
r[   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.rM   name
parametersr"   r&   r(   r(   r)   _FunctionDeclaration_to_mldev@  s   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 )Nr\   rM   r]   r^   )r#   r%   r[   r&   r(   r(   r)   _FunctionDeclaration_to_vertexU  s    r`   c                 C      i }|S Nr(   r&   r(   r(   r)   _GoogleSearch_to_mldevp     rc   c                 C   ra   rb   r(   r&   r(   r(   r)   _GoogleSearch_to_vertexz  rd   re   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dynamicThresholdr,   r&   r(   r(   r)    _DynamicRetrievalConfig_to_mldev     
rk   c                 C   rf   rg   r,   r&   r(   r(   r)   !_DynamicRetrievalConfig_to_vertex  rl   rm   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%   rk   r&   r(   r(   r)   _GoogleSearchRetrieval_to_mldev     

rr   c                 C   rn   ro   )r#   r%   rm   r&   r(   r(   r)    _GoogleSearchRetrieval_to_vertex  rs   rt   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                    r0   r(   )r_   r1   r4   r(   r)   r5     r6   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$   rc   rr   r8   r(   r4   r)   _Tool_to_mldev  s@   
	

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 )Nru   rv   c                    r0   r(   )r`   r1   r4   r(   r)   r5   	  r6   z#_Tool_to_vertex.<locals>.<listcomp>rw   rx   ry   rz   r{   r|   r}   )r#   r%   re   rt   r8   r(   r4   r)   _Tool_to_vertex  s@   
	

r   c                 C   rf   Nrh   allowed_function_namesallowedFunctionNamesr,   r&   r(   r(   r)   _FunctionCallingConfig_to_mldev,  rl   r   c                 C   rf   r   r,   r&   r(   r(   r)    _FunctionCallingConfig_to_vertex?  rl   r   c                 C   rn   Nfunction_calling_configfunctionCallingConfig)r#   r%   r   r&   r(   r(   r)   _ToolConfig_to_mldevR  rs   r   c                 C   rn   r   )r#   r%   r   r&   r(   r(   r)   _ToolConfig_to_vertexf  rs   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                    r0   r(   )r9   r1   r4   r(   r)   r5     r6   z7_CreateCachedContentConfig_to_mldev.<locals>.<listcomp>system_instructionsystemInstructiontoolsc                    r0   r(   )r~   r1   r4   r(   r)   r5     r6   tool_config
toolConfig)r#   r%   t
t_contentsr9   	t_contentr   r8   r(   r4   r)   #_CreateCachedContentConfig_to_mldevz  X   

	r   c                    r   )Nr   r   r   r   r   r   c                    r0   r(   )r;   r1   r4   r(   r)   r5     r6   z8_CreateCachedContentConfig_to_vertex.<locals>.<listcomp>r   r   r   c                    r0   r(   )r   r1   r4   r(   r)   r5     r6   r   r   )r#   r%   r   r   r;   r   r   r8   r(   r4   r)   $_CreateCachedContentConfig_to_vertex  r   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   r   r   )r#   r%   r   r   r   r&   r(   r(   r)   (_CreateCachedContentParameters_to_vertex  r   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 Nr]   _urlr   r#   r%   r   t_cached_content_namer&   r(   r(   r)   $_GetCachedContentParameters_to_mldev&     r   c              	   C   r   r   r   r&   r(   r(   r)   %_GetCachedContentParameters_to_vertex9  r   r   c              	   C   r   r   r   r&   r(   r(   r)   '_DeleteCachedContentParameters_to_mldevL  r   r   c              	   C   r   r   r   r&   r(   r(   r)   (_DeleteCachedContentParameters_to_vertex_  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   r,   r&   r(   r(   r)   #_UpdateCachedContentConfig_to_mldevr     r   c                 C   r   r   r,   r&   r(   r(   r)   $_UpdateCachedContentConfig_to_vertex  r   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   r   r   )r#   r%   r   r   r   r&   r(   r(   r)   (_UpdateCachedContentParameters_to_vertex  r   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	pageTokenr,   r&   r(   r(   r)   "_ListCachedContentsConfig_to_mldev     
r   c                 C   r   r   r,   r&   r(   r(   r)   #_ListCachedContentsConfig_to_vertex  r   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   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 Nr]   r   r   r   
createTimecreate_time
updateTimeupdate_timer   r   usageMetadatausage_metadatar,   r&   r(   r(   r)   _CachedContent_from_mldev      r   c                 C   r   r   r,   r&   r(   r(   r)   _CachedContent_from_vertex2  r   r   c                 C   ra   rb   r(   r&   r(   r(   r)   '_DeleteCachedContentResponse_from_mldevP  rd   r   c                 C   ra   rb   r(   r&   r(   r(   r)   (_DeleteCachedContentResponse_from_vertexZ  rd   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                    r0   r(   )r   r1   r4   r(   r)   r5   q  r6   z:_ListCachedContentsResponse_from_mldev.<locals>.<listcomp>r,   r8   r(   r4   r)   &_ListCachedContentsResponse_from_mldevd     
	r   c                    r   )Nr   r   r   r   c                    r0   r(   )r   r1   r4   r(   r)   r5     r6   z;_ListCachedContentsResponse_from_vertex.<locals>.<listcomp>r,   r8   r(   r4   r)   '_ListCachedContentsResponse_from_vertexz  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|d}nt| j|}d|d}|d}|r8| dt| }|	dd d}t
|trL|dd}nt|drT|j}t|}t|}| jd	|||}| jjrrt| j|}nt| j|}t jj||d
}	| j|	 |	S a3  Creates cached content, this call will initialize the cached

    content in the data storage, and users need to pay for the cache data
    storage.

    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   Nhttp_optionspostr\   kwargs)r	   _CreateCachedContentParameters_api_clientvertexair   
format_mapgetr   r   pop
isinstancedicthasattrr   r   convert_to_dictencode_unserializable_typesrequestr   r   CachedContent_from_response_verify_response
selfr   r   parameter_modelrequest_dictpathquery_paramsr   response_dictreturn_valuer(   r(   r)   create  sJ   




zCaches.creater]   c          
      C   r   zGets cached content configurations.

    .. code-block:: python

      await client.aio.caches.get(name= ... ) // The server-generated resource
      name.
    r]   r   {name}r   r   r   r   Nr   r   r   )r	   _GetCachedContentParametersr   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)   r     sJ   




z
Caches.getc          
      C   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   deleter   )r	   _DeleteCachedContentParametersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   DeleteCachedContentResponser   r   r  r(   r(   r)   r    sN   




zCaches.deletec          
      C   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   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(   r)   updateZ  sJ   




zCaches.updatec          	      C   s  t j|d}| jjrt| j|}d|d}nt| j|}d|d}|d}|r7| dt| }|	dd d}t
|trK|dd}nt|drS|j}t|}t|}| jd	|||}| jjrqt| 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	   _ListCachedContentsParametersr   r   r   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)   _list  sL   




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     Z    
N
A
E
B
=r   c                   @   r   )AsyncCachesNr   r   r   r   c          
           t j||d}| jjrt| j|}d|d}nt| j|}d|d}|d}|r9| dt| }|	dd d}t
|trM|dd}nt|drU|j}t|}t|}| jd	|||I dH }| jjrvt| j|}nt| j|}t jj||d
}	| j|	 |	S r   )r	   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     sL   





zAsyncCaches.creater]   c          
         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   .  sL   





zAsyncCaches.getc          
         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  k  sP   





zAsyncCaches.deletec          
         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	    sL   





zAsyncCaches.updatec          	         s  t j|d}| jjrt| j|}d|d}nt| j|}d|d}|d}|r8| dt| }|	dd d}t
|trL|dd}nt|drT|j}t|}t|}| jd	|||I dH }| jjrut| j|}nt| j|}t jj||d
}| j| |S 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    sN   





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    r  r  rb   )Ctypingr   r   urllib.parser    r   r   r   r   r	   r   r
   r   r#   r   r%   pagersr   r   r   objectr*   r-   r9   r;   rS   r[   r_   r`   rc   re   rk   rm   rr   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   
BaseModuler   r  r(   r(   r(   r)   <module>   sd  

/

/





R

R

















0

0









@

@





























!

!







  T