o
    j6h+*                     @  s   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 dZdS )    )annotationsN)IterableOptional)protos)caching_types)content_types)get_default_cache_client)field_mask_pb2usermodelc                	   @  s  e Zd ZdZdd ZedCddZedCdd	ZedCd
dZedDddZ	edEddZ
edEddZedEddZdd ZeZedFddZdd ZedddddddddGd0d1ZedddddddddHd2d3ZedId5d6ZedJdKd;d<ZdLd>d?Zddd@dMdAdBZdS )NCachedContentzCached content resource.c                 C  s6   t  }d|vrd| }tj|d}||}|| _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response r   j/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/google/generativeai/caching.py__init__#   s   

zCachedContent.__init__returnstrc                 C     | j jS N)r   r   r   r   r   r   r   4      zCachedContent.namec                 C  r   r   )r   r   r   r   r   r   r   8   r   zCachedContent.modelc                 C  r   r   )r   display_namer   r   r   r   r    <   r   zCachedContent.display_name"protos.CachedContent.UsageMetadatac                 C  r   r   )r   usage_metadatar   r   r   r   r"   @   r   zCachedContent.usage_metadatadatetime.datetimec                 C  r   r   )r   create_timer   r   r   r   r$   D   r   zCachedContent.create_timec                 C  r   r   )r   update_timer   r   r   r   r%   H   r   zCachedContent.update_timec                 C  r   r   )r   expire_timer   r   r   r   r&   L   r   zCachedContent.expire_timec                 C  sR   t 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   r   r   r   __str__P   s*   	
zCachedContent.__str__obj+CachedContent | protos.CachedContent | dictc                 C  s"   |  | }t |_|| |S )zKCreates an instance of CachedContent form an object, without calling `get`.)__new__r   r   r   _update)clsr-   r   r   r   r   	_from_objb   s   


zCachedContent._from_objc                 C  sP   t |tr|j}t |tst|j|dd}| D ]\}}t| j|| q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valuer   r   r   r0   j   s   

zCachedContent._updateN)r    system_instructioncontentstoolstool_configttlr&   r   r    
str | Noner=   #Optional[content_types.ContentType]r>   $Optional[content_types.ContentsType]r?   +Optional[content_types.FunctionLibraryType]r@   &Optional[content_types.ToolConfigType]rA    Optional[caching_types.TTLTypes]r&   'Optional[caching_types.ExpireTimeTypes]!protos.CreateCachedContentRequestc          
   
   C  s   |r|rt dd| vrd|  } |rt|dkrt d|r#t|}t|}|r.| }|r5t|}|rFt|}|d jsFt	|d _t
|}t
|}tj| |||||||d}	tj|	d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    r=   r>   r?   r@   rA   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    r=   r>   r?   r@   rA   r&   	tools_librO   r   r   r   _prepare_create_requestu   s@   







z%CachedContent._prepare_create_requestc             
   C  s8   t  }	| j||||||||d}
|	|
}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.
        rN   )r   r]   create_cached_contentr   r2   )r1   r   r    r=   r>   r?   r@   rA   r&   r   r   r   resultr   r   r   create   s   "

zCachedContent.creater   c                 C  s:   t  }d|vrd| }tj|d}||}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   r2   )r1   r   r   r   r   r_   r   r   r   get   s   


zCachedContent.get   	page_sizeOptional[int]Iterable[CachedContent]c                 c  s8    t  }tj|d}||D ]
}t|}|V  q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.
        )rc   N)r   r   ListCachedContentsRequestlist_cached_contentsr   r2   )r1   rc   r   r   rO   r   r   r   list   s   
zCachedContent.listNonec                 C  s"   t  }tj| jd}|| dS )z!Deletes `CachedContent` resource.r   N)r   r   DeleteCachedContentRequestr   delete_cached_content)r   r   r   r   r   r   delete  s   
zCachedContent.delete)rA   r&   c                C  s   t  }|r|rtdt|}t|}tj| j||d}t	 }|r+|j
d n|r4|j
d ntdtj||d}||}| | 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.
        rJ   )r   rA   r&   rA   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_contentr0   )r   rA   r&   r   r:   
field_maskr   
updated_ccr   r   r   update  s0   



zCachedContent.update)r   r   )r   r!   )r   r#   )r-   r.   r   r   )r   r   r    rB   r=   rC   r>   rD   r?   rE   r@   rF   rA   rG   r&   rH   r   rI   )r   r   r    rB   r=   rC   r>   rD   r?   rE   r@   rF   rA   rG   r&   rH   r   r   )r   r   r   r   )rb   )rc   rd   r   re   )r   ri   )rA   rG   r&   rH   r   ri   )__name__
__module____qualname____doc__r   propertyr   r   r    r"   r$   r%   r&   r,   __repr__classmethodr2   r0   staticmethodr]   r`   ra   rh   rl   ru   r   r   r   r   r       s`    62
r   )
__future__r   datetimer)   typingr   r   google.generativeair   google.generativeai.typesr   r   google.generativeai.clientr   google.protobufr	   rX   _MODEL_ROLEr   r   r   r   r   <module>   s   