
    
!i+*                        S SK Jr  S SKrS SKrS SKJrJr  S SKJr  S SK	J
r
  S SK	Jr  S SKJr  S SKJr  S	rS
r " S S5      rg)    )annotationsN)IterableOptional)protos)caching_types)content_types)get_default_cache_client)field_mask_pb2usermodelc            	         \ rS rSrSrS r\SS j5       r\SS j5       r\SS j5       r	\SS j5       r
\SS j5       r\SS	 j5       r\SS
 j5       rS r\r\SS j5       rS r\SSSSSSSS.                 SS jj5       r\SSSSSSSS.                 SS jj5       r\SS j5       r\SS S jj5       rS!S jrSSS.     S"S jjrSrg)#CachedContent    zCached content resource.c                    [        5       nSU;  a  SU-   n[        R                  " US9nUR                  U5      nX@l        g)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        U/home/james-whalen/.local/lib/python3.13/site-packages/google/generativeai/caching.py__init__CachedContent.__init__#   sC     *+D($t+D00d;,,W5    c                .    U R                   R                  $ N)r   r   r   s    r   r   CachedContent.name4   s    {{r   c                .    U R                   R                  $ r    )r   r   r!   s    r   r   CachedContent.model8   s    {{   r   c                .    U R                   R                  $ r    )r   display_namer!   s    r   r&   CachedContent.display_name<   s    {{'''r   c                .    U R                   R                  $ r    )r   usage_metadatar!   s    r   r)   CachedContent.usage_metadata@   s    {{)))r   c                .    U R                   R                  $ r    )r   create_timer!   s    r   r,   CachedContent.create_timeD       {{&&&r   c                .    U R                   R                  $ r    )r   update_timer!   s    r   r0   CachedContent.update_timeH   r.   r   c                .    U R                   R                  $ r    )r   expire_timer!   s    r   r3   CachedContent.expire_timeL   r.   r   c                   [         R                  " SU R                   SU R                   SU R                   SS SU R
                  R                   SS S	U R                   S
U R                   SU R                   S35      $ )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,   r0   r3   r!   s    r   __str__CachedContent.__str__P   s    yyk "

| $#001 2  #u %**.*=*=*O*O)P Q !--. /!--. /!--. /
 	
r   c                ~    U R                  U 5      n[        R                  " 5       Ul        UR	                  U5        U$ )zKCreates an instance of CachedContent form an object, without calling `get`.)__new__r   r   r   _update)clsobjr   s      r   	_from_objCachedContent._from_objb   s3     {{3**,Sr   c                    [        U[        5      (       a  UR                  n[        U[        5      (       d  [	        U5      R                  USS9nUR                  5        H  u  p#[        U R                  X#5        M     g)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?   CachedContent._updatej   s_    g}--nnG'4((7m++GTY+ZG!--/JCDKK, *r   N)r&   system_instructioncontentstoolstool_configttlr3   c                  U(       a  U(       a  [        S5      eSU ;  a  SU -   n U(       a  [        U5      S:  a  [        S5      eU(       a  [        R                  " U5      n[        R                  " U5      nU(       a  UR                  5       nU(       a  [        R                  " U5      nU(       a8  [        R                  " U5      nUS   R                  (       d  [        US   l        [        R                  " U5      n[        R                  " U5      n[        R                  " U UUUUUUUS9n	[        R                  " U	S9$ )	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&   rP   rQ   rR   rS   rT   r3   )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&   rP   rQ   rR   rS   rT   r3   	tools_libr[   s
             r   _prepare_create_request%CachedContent._prepare_create_requestu   s    ;^  e%EC-3Z[[!.!9!9:L!M!55e<	!**,I'66{CK$00:HB<$$$.!++C0#;;KH--%1##	
 00OOr   c                   [        5       n	U R                  UUUUUUUUS9n
U	R                  U
5      n[        R	                  U5      nU$ )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.
rZ   )r	   ri   create_cached_contentr   rB   )r@   r   r&   rP   rQ   rR   rS   rT   r3   r   r   r   results                r   createCachedContent.create   sa    D *+--%1## . 	
 //8((2r   c                    [        5       nSU;  a  SU-   n[        R                  " US9nUR                  U5      n[        R                  U5      nU$ )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   rB   )r@   r   r   r   r   rm   s         r   getCachedContent.get   sS     *+D($t+D00d;,,W5((2r   c              #     #    [        5       n[        R                  " US9nUR                  U5       H  n[        R                  U5      nUv   M     g7f)zLists `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.
)	page_sizeN)r	   r   ListCachedContentsRequestlist_cached_contentsr   rB   )r@   rt   r   r   r[   s        r   listCachedContent.list   sK      *+22YG$99'BN*44^DN   Cs   AAc                v    [        5       n[        R                  " U R                  S9nUR	                  U5        g)z!Deletes `CachedContent` resource.r   N)r	   r   DeleteCachedContentRequestr   delete_cached_content)r   r   r   s      r   deleteCachedContent.delete  s/    )+33C$$W-r   )rT   r3   c                  [        5       nU(       a  U(       a  [        S5      e[        R                  " U5      n[        R                  " U5      n[
        R                  " U R                  UUS9n[        R                  " 5       nU(       a  UR                  R                  S5        O.U(       a  UR                  R                  S5        O[        S5      e[
        R                  " XES9nUR                  U5      nU R                  U5        g)a(  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.
rV   )r   rT   r3   rT   r3   zQBad update name: Only `ttl`  or `expire_time` can be updated for `CachedContent`.)r[   update_maskN)r	   r\   r   re   rf   r   r   r   r
   	FieldMaskpathsappendUpdateCachedContentRequestupdate_cached_contentr?   )r   rT   r3   r   rL   
field_maskr   
updated_ccs           r   updateCachedContent.update  s     *+;^  ++C0#;;KH&&#
 $--/
##E*##M2c  337c11':
Z r   )r   )returnstr)r   z"protos.CachedContent.UsageMetadata)r   zdatetime.datetime)rA   z+CachedContent | protos.CachedContent | dictr   r   )r   r   r&   
str | NonerP   #Optional[content_types.ContentType]rQ   $Optional[content_types.ContentsType]rR   +Optional[content_types.FunctionLibraryType]rS   &Optional[content_types.ToolConfigType]rT    Optional[caching_types.TTLTypes]r3   'Optional[caching_types.ExpireTimeTypes]r   z!protos.CreateCachedContentRequest)r   r   r&   r   rP   r   rQ   r   rR   r   rS   r   rT   r   r3   r   r   r   )r   r   r   r   )   )rt   zOptional[int]r   zIterable[CachedContent])r   None)rT   r   r3   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r&   r)   r,   r0   r3   r;   __repr__classmethodrB   r?   staticmethodri   rn   rq   rw   r|   r   __static_attributes__ r   r   r   r       s+   ""     ! ! ( ( * * ' ' ' ' ' '
  H 	-  $(BF9==A>B04?C4P4P !4P @	4P
 74P ;4P <4P .4P =4P 
+4P 4Pl 
 $(BF9==A>B04?C00 !	0
 @0 70 ;0 <0 .0 =0 
0 0d  & ! !" 15?C	- .- =	-
 
- -r   r   )
__future__r   datetimer8   typingr   r   google.generativeair   google.generativeai.typesr   r   google.generativeai.clientr	   google.protobufr
   rd   _MODEL_ROLEr   r   r   r   <module>r      s8    #   % & 3 3 ? *
Z Zr   