
    rh+*                        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y)    )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dd       Zedd       Zedd       Zedd       Z	edd       Z
edd       Zedd	       Zd
 ZeZedd       Zd Zedddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zedddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zedd       Zeddd       ZddZddd	 	 	 	 	 d dZy)!CachedContentzCached content resource.c                    t               }d|vrd|z   }t        j                  |      }|j                  |      }|| _        y)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        n/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/google/generativeai/caching.py__init__zCachedContent.__init__#   sE     *+D($t+D00d;,,W5    c                .    | 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   c                .    | j                   j                  S r   )r   usage_metadatar   s    r   r$   zCachedContent.usage_metadata@   s    {{)))r   c                .    | 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    yyk "

| $#001 2  #u %**.*=*=*O*O)P Q !--. /!--. /!--. /
 	
r   c                |    | j                  |       }t        j                         |_        |j	                  |       |S )zKCreates an instance of CachedContent form an object, without calling `get`.)__new__r   r   r   _update)clsobjr   s      r   	_from_objzCachedContent._from_objb   s3     {{3**,Sr   c                    t        |t              r|j                  }t        |t              st	        |      j                  |d      }|j                         D ]  \  }}t        | j                  ||        y)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   r5   zCachedContent._updatej   sb    g}-nnG'4(7m++GTY+ZG!--/ 	-JCDKKe,	-r   N)r"   system_instructioncontentstoolstool_configttlr+   c          
     4   |r|rt        d      d| vrd| z   } |rt        |      dkD  rt        d      |rt        j                  |      }t        j                  |      }|r|j                         }|rt        j                  |      }|r2t        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"   rD   rE   rF   rG   rH   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"   rD   rE   rF   rG   rH   r+   	tools_librO   s
             r   _prepare_create_requestz%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          
         t               }	| j                  ||||||||      }
|	j                  |
      }t        j	                  |      }|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.
        rN   )r	   r]   create_cached_contentr   r8   )r6   r   r"   rD   rE   rF   rG   rH   r+   r   r   r   results                r   createzCachedContent.create   sa    D *+--%1## . 	
 //8((2r   c                    t               }d|vrd|z   }t        j                  |      }|j                  |      }t        j                  |      }|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   r8   )r6   r   r   r   r   r`   s         r   getzCachedContent.get   sS     *+D($t+D00d;,,W5((2r   c              #     K   t               }t        j                  |      }|j                  |      D ]  }t        j                  |      }|  yw)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.
        )	page_sizeN)r	   r   ListCachedContentsRequestlist_cached_contentsr   r8   )r6   re   r   r   rO   s        r   listzCachedContent.list   sP      *+22YG$99'B 	!N*44^DN  	!s   AAc                z    t               }t        j                  | j                        }|j	                  |       y)z!Deletes `CachedContent` resource.r   N)r	   r   DeleteCachedContentRequestr   delete_cached_content)r   r   r   s      r   deletezCachedContent.delete  s/    )+33C$$W-r   )rH   r+   c                  t               }|r|rt        d      t        j                  |      }t        j                  |      }t        j                  | j                  ||      }t        j                         }|r|j                  j                  d       n)|r|j                  j                  d       nt        d      t        j                  ||      }|j                  |      }| j                  |       y)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.
        rJ   )r   rH   r+   rH   r+   zQBad update name: Only `ttl`  or `expire_time` can be updated for `CachedContent`.)rO   update_maskN)r	   rP   r   rY   rZ   r   r   r   r
   	FieldMaskpathsappendUpdateCachedContentRequestupdate_cached_contentr5   )r   rH   r+   r   rA   
field_maskr   
updated_ccs           r   updatezCachedContent.update  s     *+;^  ++C0#;;KH&&#
 $--/
##E*##M2c  337Xbc11':
Z r   )returnstr)rw   z"protos.CachedContent.UsageMetadata)rw   zdatetime.datetime)r7   z+CachedContent | protos.CachedContent | dictrw   r   )r   rx   r"   
str | NonerD   #Optional[content_types.ContentType]rE   $Optional[content_types.ContentsType]rF   +Optional[content_types.FunctionLibraryType]rG   &Optional[content_types.ToolConfigType]rH    Optional[caching_types.TTLTypes]r+   'Optional[caching_types.ExpireTimeTypes]rw   z!protos.CreateCachedContentRequest)r   rx   r"   ry   rD   rz   rE   r{   rF   r|   rG   r}   rH   r~   r+   r   rw   r   )r   rx   rw   r   )   )re   zOptional[int]rw   zIterable[CachedContent])rw   None)rH   r~   r+   r   rw   r   )__name__
__module____qualname____doc__r   propertyr   r   r"   r$   r&   r)   r+   r2   __repr__classmethodr8   r5   staticmethodr]   ra   rc   rh   rl   rv    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   datetimer/   typingr   r   google.generativeair   google.generativeai.typesr   r   google.generativeai.clientr	   google.protobufr
   rX   _MODEL_ROLEr   r   r   r   <module>r      s8    #   % & 3 3 ? *
Z Zr   