
    ; i+*                        d dl mZ d dlZd dlZ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	Zd
Z G d d          ZdS )    )annotationsN)IterableOptional)protos)caching_types)content_types)get_default_cache_client)field_mask_pb2usermodelc            	         e Zd ZdZd Zed2d            Zed2d            Zed2d            Zed3d	            Z	ed4d            Z
ed4d            Zed4d            Zd ZeZed5d            Zd Zeddddddddd6d%            Zeddddddddd7d&            Zed8d(            Zed9d:d-            Zd;d/Zddd0d<d1ZdS )=CachedContentzCached content resource.c                    t                      }d|vrd|z   }t          j        |          }|                    |          }|| _        dS )zFetches a `CachedContent` resource.

        Identical to `CachedContent.get`.

        Args:
            name: The resource name referring to the cached content.
        cachedContents/nameN)r	   r   GetCachedContentRequestget_cached_content_proto)selfr   clientrequestresponses        s/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/caching.py__init__zCachedContent.__init__#   sU     *++D(($t+D0d;;;,,W55    returnstrc                    | j         j        S N)r   r   r   s    r   r   zCachedContent.name4   s    {r   c                    | j         j        S r    )r   r   r!   s    r   r   zCachedContent.model8   s    {  r   c                    | j         j        S r    )r   display_namer!   s    r   r$   zCachedContent.display_name<   s    {''r   "protos.CachedContent.UsageMetadatac                    | j         j        S r    )r   usage_metadatar!   s    r   r'   zCachedContent.usage_metadata@   s    {))r   datetime.datetimec                    | j         j        S r    )r   create_timer!   s    r   r*   zCachedContent.create_timeD       {&&r   c                    | j         j        S r    )r   update_timer!   s    r   r-   zCachedContent.update_timeH   r+   r   c                    | j         j        S r    )r   expire_timer!   s    r   r/   zCachedContent.expire_timeL   r+   r   c                    t          j        d| j         d| j         d| j         dd d| j        j         dd d	| j         d
| j         d| j	         d          S )Nz1            CachedContent(
                name='z',
                model='z!',
                display_name='z"',
                usage_metadata={z*
                    'total_token_count': z,
                }z,
                create_time=z,
                update_time=z,
                expire_time=z
            ))
textwrapdedentr   r   r$   r'   total_token_countr*   r-   r/   r!   s    r   __str__zCachedContent.__str__P   s    y  
   $0	 
 !$  +/*=*O    "-  "-  "-  
 
 	
r   obj+CachedContent | protos.CachedContent | dictc                    |                      |           }t          j                    |_        |                    |           |S )zKCreates an instance of CachedContent form an object, without calling `get`.)__new__r   r   r   _update)clsr7   r   s      r   	_from_objzCachedContent._from_objb   s<     {{3*,,Sr   c                   t          |t                    r|j        }t          |t                    s$t	          |                              |d          }|                                D ]\  }}t          | j        ||           dS )zFUpdates this instance inplace, does not call the API's `update` methodF)including_default_value_fieldsN)
isinstancer   r   dicttypeto_dictitemssetattr)r   updateskeyvalues       r   r;   zCachedContent._updatej   s    g}-- 	%nG'4(( 	[7mm++GTY+ZZG!--// 	- 	-JCDKe,,,,	- 	-r   N)r$   system_instructioncontentstoolstool_configttlr/   r   r$   
str | NonerI   #Optional[content_types.ContentType]rJ   $Optional[content_types.ContentsType]rK   +Optional[content_types.FunctionLibraryType]rL   &Optional[content_types.ToolConfigType]rM    Optional[caching_types.TTLTypes]r/   'Optional[caching_types.ExpireTimeTypes]!protos.CreateCachedContentRequestc          
     J   |r|rt          d          d| vrd| z   } |r"t          |          dk    rt          d          |rt          j        |          }t          j        |          }|r|                                }|rt          j        |          }|r3t          j        |          }|d         j        st          |d         _        t          j        |          }t          j        |          }t          j        | |||||||          }	t          j        |	          S )	z&Prepares a CreateCachedContentRequest.LExclusive arguments: Please provide either `ttl` or `expire_time`, not both./zmodels/   z;`display_name` must be no more than 128 unicode characters.r   r$   rI   rJ   rK   rL   rM   r/   )cached_content)
ValueErrorlenr   
to_contentto_function_libraryto_prototo_tool_configto_contentsrole
_USER_ROLEr   to_optional_ttlto_optional_expire_timer   r   CreateCachedContentRequest)
r   r$   rI   rJ   rK   rL   rM   r/   	tools_libr\   s
             r   _prepare_create_requestz%CachedContent._prepare_create_requestu   s^     	; 	^   e%E 	\C--33Z[[[ 	N!.!9:L!M!M!5e<<	 	-!**,,I 	D'6{CCK 	/$0::HB<$ /$.!+C00#;KHH-%1##	
 	
 	
 0OOOOr   c          
         t                      }	|                     ||||||||          }
|	                    |
          }t                              |          }|S )a  Creates `CachedContent` resource.

        Args:
            model: The name of the `model` to use for cached content creation.
                   Any `CachedContent` resource can be only used with the
                   `model` it was created for.
            display_name: The user-generated meaningful display name
                          of the cached content. `display_name` must be no
                          more than 128 unicode characters.
            system_instruction: Developer set system instruction.
            contents: Contents to cache.
            tools: A list of `Tools` the model may use to generate response.
            tool_config: Config to apply to all tools.
            ttl: TTL for cached resource (in seconds). Defaults to 1 hour.
                 `ttl` and `expire_time` are exclusive arguments.
            expire_time: Expiration time for cached resource.
                         `ttl` and `expire_time` are exclusive arguments.

        Returns:
            `CachedContent` resource with specified name.
        r[   )r	   rj   create_cached_contentr   r=   )r<   r   r$   rI   rJ   rK   rL   rM   r/   r   r   r   results                r   createzCachedContent.create   so    D *++--%1## . 	
 	
 //88((22r   r   c                    t                      }d|vrd|z   }t          j        |          }|                    |          }t                              |          }|S )zFetches required `CachedContent` resource.

        Args:
            name: The resource name referring to the cached content.

        Returns:
            `CachedContent` resource with specified `name`.
        r   r   )r	   r   r   r   r   r=   )r<   r   r   r   r   rm   s         r   getzCachedContent.get   sb     *++D(($t+D0d;;;,,W55((22r      	page_sizeOptional[int]Iterable[CachedContent]c              #     K   t                      }t          j        |          }|                    |          D ] }t                              |          }|V  !dS )a.  Lists `CachedContent` objects associated with the project.

        Args:
            page_size: The maximum number of permissions to return (per page).
            The service may return fewer `CachedContent` objects.

        Returns:
            A paginated list of `CachedContent` objects.
        )rr   N)r	   r   ListCachedContentsRequestlist_cached_contentsr   r=   )r<   rr   r   r   r\   s        r   listzCachedContent.list   so       *++2YGGG$99'BB 	! 	!N*44^DDN     	! 	!r   Nonec                    t                      }t          j        | j                  }|                    |           dS )z!Deletes `CachedContent` resource.r   N)r	   r   DeleteCachedContentRequestr   delete_cached_content)r   r   r   s      r   deletezCachedContent.delete  s;    )++3CCC$$W---r   )rM   r/   c                  t                      }|r|rt          d          t          j        |          }t          j        |          }t          j        | j        ||          }t          j	                    }|r|j
                            d           n,|r|j
                            d           nt          d          t          j        ||          }|                    |          }|                     |           dS )aX  Updates requested `CachedContent` resource.

        Args:
            ttl: TTL for cached resource (in seconds). Defaults to 1 hour.
                 `ttl` and `expire_time` are exclusive arguments.
            expire_time: Expiration time for cached resource.
                         `ttl` and `expire_time` are exclusive arguments.
        rW   )r   rM   r/   rM   r/   zQBad update name: Only `ttl`  or `expire_time` can be updated for `CachedContent`.)r\   update_maskN)r	   r]   r   rf   rg   r   r   r   r
   	FieldMaskpathsappendUpdateCachedContentRequestupdate_cached_contentr;   )r   rM   r/   r   rF   
field_maskr   
updated_ccs           r   updatezCachedContent.update  s"    *++ 	; 	^   +C00#;KHH&#
 
 
 $-//
 	##E**** 	##M2222d   37Xbccc11'::
Z   r   )r   r   )r   r%   )r   r(   )r7   r8   r   r   )r   r   r$   rN   rI   rO   rJ   rP   rK   rQ   rL   rR   rM   rS   r/   rT   r   rU   )r   r   r$   rN   rI   rO   rJ   rP   rK   rQ   rL   rR   rM   rS   r/   rT   r   r   )r   r   r   r   )rq   )rr   rs   r   rt   )r   ry   )rM   rS   r/   rT   r   ry   )__name__
__module____qualname____doc__r   propertyr   r   r$   r'   r*   r-   r/   r6   __repr__classmethodr=   r;   staticmethodrj   rn   rp   rx   r}   r    r   r   r   r       sU       ""  "       X  ! ! ! X! ( ( ( X( * * * X* ' ' ' X' ' ' ' X' ' ' ' X'
 
 
  H   [	- 	- 	-  $(BF9==A>B04?C4P 4P 4P 4P 4P \4Pl 
 $(BF9==A>B04?C0 0 0 0 0 [0d    [& ! ! ! ! [!"    15?C	- - - - - - - -r   r   )
__future__r   datetimer3   typingr   r   google.generativeair   google.generativeai.typesr   r   google.generativeai.clientr	   google.protobufr
   re   _MODEL_ROLEr   r   r   r   <module>r      s    # " " " " "   % % % % % % % % & & & & & & 3 3 3 3 3 3 3 3 3 3 3 3 ? ? ? ? ? ? * * * * * *
Z Z Z Z Z Z Z Z Z Zr   