o
    wi                     @  s  d Z ddlmZ ddlZddlmZmZmZmZ ddl	m	Z	 ddl
mZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZ ddlmZ ddlm 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dl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 erddl7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZF ddlGmHZH edZIedd d@d#d$ZJG d%d& d&e"d'eKf ZLG d(d) d)e"d* ZMG d+d, d,ZNG d-d. d.e#d/ ZOG d0d1 d1e#d/ ZPG d2d3 d3ZQG d4d5 d5eeI ZRG d6d7 d7eeI ZSG d8d9 d9e#d: ZTG d;d< d<e#d: ZUG d=d> d>e#d? ZVdS )Az}W&B Public API for Artifact objects.

This module provides classes for interacting with W&B artifacts and their
collections.
    )annotationsN)
CollectionIterableMappingSequence)copy)	lru_cache)TYPE_CHECKINGAnyClassVarListLiteralTypeVar)override)gql)always_list)
ConnectionConnectionWithTotalEdge)nameof)normalize_exceptions)RelayPaginatorSizedRelayPaginator)UnsupportedError)termlog)wandb_internal_pb2)
Deprecatedserver_supports)ArtifactCollectionData)warn_and_record_deprecation   )File)
gql_compat)Document)RetryingClient)ArtifactAliasFragmentArtifactCollectionFragmentArtifactFragmentArtifactTypeFragmentFileFragment)ArtifactCollectionConnectionArtifactFileConnectionArtifactTypeConnectionArtifact)RunTNode)maxsizereturn$dict[Literal['logged', 'used'], str]c                  C  s   ddl m} m} || dS )zLazily import and cache the run artifact GQL query strings.

    This keeps import-time light and only loads the generated GQL
    when RunArtifacts is actually used.
    r   RUN_INPUT_ARTIFACTS_GQLRUN_OUTPUT_ARTIFACTS_GQL)loggedused)wandb.sdk.artifacts._generatedr6   r7   r5    r;   O/home/ubuntu/.local/lib/python3.10/site-packages/wandb/apis/public/artifacts.py_run_artifacts_mode_to_gql:   s   
r=   c                      sP   e Zd ZU dZdZded< ded< 	dd fddZdddZdddZ  Z	S )_ArtifactCollectionAliasesz`An internal iterator of collection alias names.

    <!-- lazydoc-ignore-init: internal -->
    NClassVar[Document | None]QUERYz(Connection[ArtifactAliasFragment] | Nonelast_response  clientr%   collection_idstrper_pageintc                   sB   | j d u rddlm} t|t| _ d|i}t j|||d d S )Nr   )ARTIFACT_COLLECTION_ALIASES_GQLid	variablesrF   )r@   r:   rH   r   typesuper__init__)selfrC   rD   rF   rH   rK   	__class__r;   r<   rN   R   s
   
z#_ArtifactCollectionAliases.__init__r3   Nonec                 C  sn   ddl m}m} | jj| j| jd}||}|j }r!|j	 }s-t
dtt| dt| || _d S )Nr   )r&   ArtifactCollectionAliasesvariable_valuesUnable to parse  response data)r:   r&   rS   rC   executer@   rK   model_validateartifact_collectionaliases
ValueErrorr   rL   r   rA   )rO   r&   rS   dataresultcollconnr;   r;   r<   _update_response`   s   
z+_ArtifactCollectionAliases._update_responsenoder&   c                 C  s   |j S N)aliasrO   rb   r;   r;   r<   _converto   s   z#_ArtifactCollectionAliases._convert)rB   )rC   r%   rD   rE   rF   rG   r3   rR   )rb   r&   r3   rE   )
__name__
__module____qualname____doc__r@   __annotations__rN   ra   rf   __classcell__r;   r;   rP   r<   r>   I   s   
 
r>   r&   c                      sT   e Zd ZU dZdZded< ded< 	dd fddZedddZdddZ	  Z
S )ArtifactTypeszsAn lazy iterator of `ArtifactType` objects for a specific project.

    <!-- lazydoc-ignore-init: internal -->
    Nr?   r@   zArtifactTypeConnection | NonerA   2   rC   r%   entityrE   projectrF   rG   c                   sP   | j d u rddlm} t|t| _ || _|| _||d}t j|||d d S )Nr   )PROJECT_ARTIFACT_TYPES_GQL)rp   rq   rJ   )	r@   r:   rr   r   rL   rp   rq   rM   rN   )rO   rC   rp   rq   rF   rr   rK   rP   r;   r<   rN   |   s   

zArtifactTypes.__init__r3   rR   c                 C  r   ddl m} ddlm} | jj| j| jd}||}|j	 }r%|j
 }s1tdtt| d||| _dS ):Fetch and validate the response data for the current page.r   )ProjectArtifactTypes)r-   rT   rV   rW   N)r:   ru   &wandb.sdk.artifacts._models.paginationr-   rC   rX   r@   rK   rY   rq   artifact_typesr\   r   rL   rA   )rO   ru   r-   r]   r^   projr`   r;   r;   r<   ra      s   
zArtifactTypes._update_responserb   r)   ArtifactTypec                 C  s   t | j| j| j|j|dS )N)rC   rp   rq   	type_nameattrs)ry   rC   rp   rq   namere   r;   r;   r<   rf      s   zArtifactTypes._convertro   )rC   r%   rp   rE   rq   rE   rF   rG   rg   )rb   r)   r3   ry   rh   ri   rj   rk   r@   rl   rN   r   ra   rf   rm   r;   r;   rP   r<   rn   s   s   
 rn   )r)   ry   c                   @  sx   e Zd ZU dZded< 	d&d'ddZd(ddZed)ddZed)ddZ	e
			d*d+ddZd,d"d#Zd)d$d%ZdS )-ry   a  An artifact object that satisfies query based on the specified type.

    Args:
        client: The client instance to use for querying W&B.
        entity: The entity (user or team) that owns the project.
        project: The name of the project to query for artifact types.
        type_name: The name of the artifact type.
        attrs: Optional attributes to initialize the ArtifactType.
            If omitted, the object will load its attributes from W&B upon
            initialization.

    <!-- lazydoc-ignore-init: internal -->
    r)   _attrsNrC   r%   rp   rE   rq   rz   r{   ArtifactTypeFragment | Nonec                 C  s<   ddl m} || _|| _|| _|| _||p|  | _d S )Nr   )r)   )	r:   r)   rC   rp   rq   rL   rY   loadr   )rO   rC   rp   rq   rz   r{   r)   r;   r;   r<   rN      s   zArtifactType.__init__r3   c           
      C  sv   ddl m}m}m} t|}| j| j| jd}| jj	||d}|
|}|j }r.|j }	s6td| j|
|	S )z_Load the artifact type attributes from W&B.

        <!-- lazydoc-ignore: internal -->
        r   )PROJECT_ARTIFACT_TYPE_GQLr)   ProjectArtifactType)rp   rq   rL   rT   Could not find artifact type )r:   r   r)   r   r   rp   rq   rL   rC   rX   rY   artifact_typer\   )
rO   r   r)   r   gql_opgql_varsr]   r^   rx   r   r;   r;   r<   r      s   

zArtifactType.loadc                 C     | j jS )z+The unique identifier of the artifact type.)r   rI   rO   r;   r;   r<   rI         zArtifactType.idc                 C  r   )zThe name of the artifact type.)r   r|   r   r;   r;   r<   r|      r   zArtifactType.namero   filtersMapping[str, Any] | Noneorder
str | NonerF   rG   ArtifactCollectionsc              	   C  s   t | j| j| j||| j|dS )aA  Get all artifact collections associated with this artifact type.

        Args:
            filters (dict): Optional mapping of filters to apply to the query.
            order (str): Optional string to specify the order of the results.
                If you prepend order with a + order is ascending (default).
                If you prepend order with a - order is descending.
                The default order is the collection ID in descending order.
            per_page (int): The number of artifact collections to fetch per page.
                Default is 50.
        )rp   rq   r   r   rz   rF   )r   rC   rp   rq   rL   )rO   r   r   rF   r;   r;   r<   collections   s   zArtifactType.collectionsr|   ArtifactCollectionc                 C  s   t | j| j| j|| jdS )zGet a specific artifact collection by name.

        Args:
            name (str): The name of the artifact collection to retrieve.
        )rp   rq   r|   rL   )r   rC   rp   rq   rL   rO   r|   r;   r;   r<   
collection  s   zArtifactType.collectionc                 C  s   d| j  dS )Nz<ArtifactType >)rL   r   r;   r;   r<   __repr__  s   zArtifactType.__repr__rc   )
rC   r%   rp   rE   rq   rE   rz   rE   r{   r   )r3   r)   r3   rE   NNro   )r   r   r   r   rF   rG   r3   r   )r|   rE   r3   r   )rh   ri   rj   rk   rl   rN   r   propertyrI   r|   r   r   r   r   r;   r;   r;   r<   ry      s"   
 

ry   c                      sX   e Zd ZU dZdZded< ded< 			dd  fddZed!ddZd"ddZ	  Z
S )#r   a  Artifact collections of a specific type in a project.

    Args:
        client: The client instance to use for querying W&B.
        entity: The entity (user or team) that owns the project.
        project: The name of the project to query for artifact collections.
        type_name: The name of the artifact type for which to fetch collections.
        filters: Optional mapping of filters to apply to the query.
        order: Optional string to specify the order of the results.
            If you prepend order with a + order is ascending (default).
            If you prepend order with a - order is descending.
        per_page: The number of artifact collections to fetch per page. Default is 50.

    <!-- lazydoc-ignore-init: internal -->
    Nr?   r@   #ArtifactCollectionConnection | NonerA   ro   rC   r%   rp   rE   rq   rz   r   r   r   r   rF   rG   c                   s   | j d u rddlm} t|t| _ |d us|d ur$t|tjs$td|| _	|| _
|| _|| _|| _||||| }	r@t|	nd d}
t j||
|d d S )Nr   )&ARTIFACT_TYPE_ARTIFACT_COLLECTIONS_GQLFiltering and ordering of artifact collections is not supported on this wandb server version. Please upgrade your server version or contact support at support@wandb.com.)rp   rq   rL   r   r   rJ   )r@   r:   r   r   rL   r   pb&ARTIFACT_COLLECTIONS_FILTERING_SORTINGr   rp   rq   rz   r   r   jsondumpsrM   rN   )rO   rC   rp   rq   rz   r   r   rF   r   frK   rP   r;   r<   rN   *  s*   

zArtifactCollections.__init__r3   rR   c                 C  s|   ddl m} ddlm} | jj| j| jd}||}|j	 }r*|j
 }r*|j }s6tdtt| d||| _dS )rt   r   )ArtifactTypeArtifactCollections)r+   rT   rV   rW   N)r:   r   rv   r+   rC   rX   r@   rK   rY   rq   r   artifact_collectionsr\   r   rL   rA   )rO   r   r+   r]   r^   rx   r   r`   r;   r;   r<   ra   Q  s   
z$ArtifactCollections._update_responserb   r'   ArtifactCollection | Nonec                 C  0   |j sd S t| j|j jj|j j|j|jj|dS N)rC   rp   rq   r|   rL   r{   rq   r   rC   rp   r|   rL   re   r;   r;   r<   rf   d     zArtifactCollections._convertr   )rC   r%   rp   rE   rq   rE   rz   rE   r   r   r   r   rF   rG   rg   rb   r'   r3   r   r~   r;   r;   rP   r<   r     s   
 'r   )r'   r   c                      sX   e Zd ZU dZdZded< ded< 			dd fddZed ddZd!ddZ	  Z
S )"ProjectArtifactCollectionsa  Artifact collections in a project.

    Args:
        client: The client instance to use for querying W&B.
        entity: The entity (user or team) that owns the project.
        project: The name of the project to query for artifact collections.
        filters: Optional mapping of filters to apply to the query.
        order: Optional string to specify the order of the results.
            If you prepend order with a + order is ascending (default).
            If you prepend order with a - order is descending.
        per_page: The number of artifact collections to fetch per page. Default is 50.

    <!-- lazydoc-ignore-init: internal -->
    Nr?   r@   r   rA   ro   rC   r%   rp   rE   rq   r   r   r   r   rF   rG   c                   s   |d us|d urt |tjstd| jd u r=ddlm} t |tjr%d ndh}t |tjr0d ndh}	t||	|dt| _|| _	|| _
|| _|| _|||| }
rUt|
nd d}t j|||d d S )	Nr   r   ) PROJECT_ARTIFACT_COLLECTIONS_GQL
totalCountr   )omit_variablesomit_fields)rp   rq   r   r   rJ   )r   r   r   r   r@   r:   r   r#   rL   rp   rq   r   r   r   r   rM   rN   )rO   rC   rp   rq   r   r   rF   r   r   r   r   rK   rP   r;   r<   rN     s>   	


z#ProjectArtifactCollections.__init__r3   rR   c                 C  rs   )rt   r   )r   )#ProjectArtifactCollectionConnectionrT   rV   rW   N)r:   r   rv   r   rC   rX   r@   rK   rY   rq   r   r\   r   rL   rA   )rO   r   r   r]   r^   rx   r`   r;   r;   r<   ra     s   
z+ProjectArtifactCollections._update_responserb   r'   r   c                 C  r   r   r   re   r;   r;   r<   rf     r   z#ProjectArtifactCollections._convertr   )rC   r%   rp   rE   rq   rE   r   r   r   r   rF   rG   rg   r   r~   r;   r;   rP   r<   r   q  s   
 3r   c                   @  s  e Zd ZU dZded< 	 ded< 	 		dTdUddZdVddZedWddZedWddZ	edWddZ
edXdYd#d$ZedZd&d'ZedWd(d)Zed[d*d+Zd\d-d.Zed]d0d1Zd^d3d4Zed_d5d6Zed[d7d8Zejd`d:d8ZedZd;d<Zejdad?d<ZedWd@dAZejdbdBdAZedCdD ZejdcdEdDZd_dFdGZd_dHdIZdddLdMZdddNdOZed_dPdQZdWdRdSZdS )er   a  An artifact collection that represents a group of related artifacts.

    Args:
        client: The client instance to use for querying W&B.
        entity: The entity (user or team) that owns the project.
        project: The name of the project to query for artifact collections.
        name: The name of the artifact collection.
        type: The type of the artifact collection (e.g., "dataset", "model").
        organization: Optional organization name if applicable.
        attrs: Optional mapping of attributes to initialize the artifact collection.
            If not provided, the object will load its attributes from W&B upon
            initialization.

    <!-- lazydoc-ignore-init: internal -->
    r   _saved_currentNrC   r%   rp   rE   rq   r|   rL   organizationr   r{   !ArtifactCollectionFragment | Nonec                 C  s*   || _ | |p| |||| || _d S rc   )rC   _update_datar   r   )rO   rC   rp   rq   r|   rL   r   r{   r;   r;   r<   rN     s   

zArtifactCollection.__init__fragmentr'   r3   rR   c                 C  s"   t |}|| _|jdd| _dS )zUpdate the saved/current state of this collection with the given fragment.

        Can be used after receiving a GraphQL response with ArtifactCollection data.
        T)deepN)r   from_fragmentr   
model_copyr   )rO   r   	validatedr;   r;   r<   r     s   
zArtifactCollection._update_datac                 C  r   )z1The unique identifier of the artifact collection.)r   rI   r   r;   r;   r<   rI   	  r   zArtifactCollection.idc                 C  r   )z0The entity (user or team) that owns the project.)r   rp   r   r;   r;   r<   rp     r   zArtifactCollection.entityc                 C  r   )z2The project that contains the artifact collection.)r   rq   r   r;   r;   r<   rq     r   zArtifactCollection.projectro   rF   rG   	Artifactsc                 C  s"   t | j| j| j| jj| jj|dS )z$Get all artifacts in the collection.)rC   rp   rq   collection_namerL   rF   )r   rC   rp   rq   r   r|   rL   )rO   rF   r;   r;   r<   	artifacts  s   zArtifactCollection.artifacts	list[str]c                 C  sT   | j jdu r$tt| j| jd}| j jd|id| _ | jjd|id| _t| j jS )zCThe aliases for all artifact versions contained in this collection.N)rD   r[   )update)r   r[   listr>   rC   rI   r   r   )rO   r[   r;   r;   r<   r[   &  s   zArtifactCollection.aliasesc                 C  r   )z-The creation date of the artifact collection.)r   
created_atr   r;   r;   r<   r   2  r   zArtifactCollection.created_atc                 C  r   )z;The date at which the artifact collection was last updated.)r   
updated_atr   r;   r;   r<   r   7  r   zArtifactCollection.updated_attype_c                 C  sv   ddl m}m} t|}||||d}| jj||d}	||	}
|
jr2|
j }r2|j }r2|j	 }s9t
d||S )zuFetch and return the validated artifact collection data from W&B.

        <!-- lazydoc-ignore: internal -->
        r   )PROJECT_ARTIFACT_COLLECTION_GQLProjectArtifactCollection)rp   rq   rL   r|   rT   r   )r:   r   r   r   rC   rX   rY   rq   r   rZ   r\   )rO   rp   rq   r   r|   r   r   r   r   r]   r^   rx   r   r   r;   r;   r<   r   <  s   
zArtifactCollection.loadnew_typec           	   
   C  s   ddl m}m} ddlm} ttdddd | jj }|kr=z||| j	 W n t
y< } z	t
d|d	|d
}~ww ||| j	}|  sKt
dtd|d| t|}|| j|d}| jj|d| id || j_|| j_d
S )z5Deprecated, change type directly with `save` instead.r   !UPDATE_ARTIFACT_SEQUENCE_TYPE_GQLMoveArtifactSequenceInputvalidate_artifact_typeT) artifact_collection__change_typezZArtifactCollection.change_type(type) is deprecated, use ArtifactCollection.save() instead.)featuremessageThe current type + is an internal type and cannot be changed.Nz*Artifact collection needs to be a sequencez%Changing artifact collection type of z to artifact_sequence_iddestination_artifact_type_nameinputrT   )r:   r   r   wandb.sdk.artifacts._validatorsr   r    r   r   rL   r|   r\   is_sequencer   r   rI   rC   rX   
model_dumpr   )	rO   r   r   r   r   old_typeer   	gql_inputr;   r;   r<   change_typeU  s:   
zArtifactCollection.change_typeboolc                 C  r   )z5Return whether the artifact collection is a sequence.)r   r   r   r;   r;   r<   r   |  s   zArtifactCollection.is_sequencec                 C  s>   ddl m}m} t|  r|n|}| jj|d| jid dS )z&Delete the entire artifact collection.r   )DELETE_ARTIFACT_PORTFOLIO_GQLDELETE_ARTIFACT_SEQUENCE_GQLrI   rT   N)r:   r   r   r   r   rC   rX   rI   )rO   r   r   r   r;   r;   r<   delete  s   zArtifactCollection.deletec                 C  r   )z)A description of the artifact collection.r   descriptionr   r;   r;   r<   r     r   zArtifactCollection.descriptionr   c                 C     || j _dS )z/Set the description of the artifact collection.Nr   )rO   r   r;   r;   r<   r        c                 C  r   )z1The tags associated with the artifact collection.r   tagsr   r;   r;   r<   r     r   zArtifactCollection.tagsr   Collection[str]c                 C  r   )z5Set the tags associated with the artifact collection.Nr   )rO   r   r;   r;   r<   r     r   c                 C  r   )z$The name of the artifact collection.r   r|   r   r;   r;   r<   r|     r   zArtifactCollection.namec                 C  r   )z(Set the name of the artifact collection.Nr   r   r;   r;   r<   r|     r   c                 C  r   )z,Returns the type of the artifact collection.)r   rL   r   r;   r;   r<   rL     r   zArtifactCollection.typec                 C  s   |   std|| j_dS )z(Set the type of the artifact collection.zBType can only be changed if the artifact collection is a sequence.N)r   r\   r   rL   )rO   rL   r;   r;   r<   rL     s
   c                 C  s   ddl m}m}m}m} |  rt|}|| j| j| j	d}nt|}|| j| j| j	d}| j
j|d| id | jj| j_| jj	| j_	| jj| j_d S )Nr   )UPDATE_ARTIFACT_PORTFOLIO_GQLUPDATE_ARTIFACT_SEQUENCE_GQLUpdateArtifactPortfolioInputUpdateArtifactSequenceInput)r   r|   r   )artifact_portfolio_idr|   r   r   rT   )r:   r   r   r   r   r   r   rI   r|   r   rC   rX   r   r   r   r   )rO   r   r   r   r   r   r   r;   r;   r<   _update_collection  s$   z%ArtifactCollection._update_collectionc                 C  sP   ddl m}m} t|}|| j| jd}| jj|d| id | j	j| j
_d S )Nr   r   r   r   rT   )r:   r   r   r   rI   rL   rC   rX   r   r   r   )rO   r   r   r   r   r;   r;   r<   _update_sequence_type  s   z(ArtifactCollection._update_sequence_type	tag_namesIterable[str]c                 C  V   ddl m}m} t|}|| j| j| jjdd |D d}| jj	|d|
 id d S )Nr   ) ADD_ARTIFACT_COLLECTION_TAGS_GQL+CreateArtifactCollectionTagAssignmentsInputc                 S     g | ]}d |iqS tagNamer;   .0tagr;   r;   r<   
<listcomp>      z0ArtifactCollection._add_tags.<locals>.<listcomp>entity_nameproject_nameartifact_collection_namer   r   rT   )r:   r   r   r   rp   rq   r   r|   rC   rX   r   )rO   r   r   r   r   r   r;   r;   r<   	_add_tags     zArtifactCollection._add_tagsc                 C  r   )Nr   )#DELETE_ARTIFACT_COLLECTION_TAGS_GQL+DeleteArtifactCollectionTagAssignmentsInputc                 S  r   r   r;   r   r;   r;   r<   r     r   z3ArtifactCollection._delete_tags.<locals>.<listcomp>r   r   rT   )r:   r   r  r   rp   rq   r   r|   rC   rX   r   )rO   r   r   r  r   r   r;   r;   r<   _delete_tags  r   zArtifactCollection._delete_tagsc           
   
   C  s:  ddl m} | jj }| j }kr]z||| j W n ty5 } zt|}td| jd| |d}~ww z||| j W n ty\ } zd|d}td| jd| |d}~ww |   |  rm||krm| 	  t
| jj }t
| jj }kr||  }r| | ||  }	r| |	 t|| j_dS dS )z4Persist any changes made to the artifact collection.r   r   z#Failed to save artifact collection z: Nr   r   )r   r   r   rL   r|   r\   rE   r   r   r   setr   r   r   r  r   )
rO   r   r   r   r   reasonnew_tagsold_tags
added_tagsdeleted_tagsr;   r;   r<   save  sD    

zArtifactCollection.savec                 C  s   d| j  d| j dS )Nz<ArtifactCollection  ()>)r|   rL   r   r;   r;   r<   r   $     zArtifactCollection.__repr__)NN)rC   r%   rp   rE   rq   rE   r|   rE   rL   rE   r   r   r{   r   )r   r'   r3   rR   r   r}   )rF   rG   r3   r   r3   r   )r3   r   )
rp   rE   rq   rE   r   rE   r|   rE   r3   r'   )r   rE   r3   rR   )r3   r   rg   )r   r   r3   rR   )r   r   r3   rR   )r|   rE   r3   rR   )rL   rE   r3   rR   )r   r   r3   rR   )rh   ri   rj   rk   rl   rN   r   r   rI   rp   rq   r   r   r[   r   r   r   r   r   r   r   setterr   r|   rL   r   r   r   r  r	  r   r;   r;   r;   r<   r     sj   
 	



&




!r   c                   @     e Zd ZU ded< dS )_ArtifactEdgeGenericrE   versionNrh   ri   rj   rl   r;   r;   r;   r<   r  (     
 r  c                   @  r  )_ArtifactConnectionGenericzList[_ArtifactEdgeGeneric]edgesNr  r;   r;   r;   r<   r  ,  r  r  c                      sh   e Zd ZU dZded< ded< 				d%d& fddZed'ddZed(d d!Zed)d#d$Z	  Z
S )*r   au  An iterable collection of artifact versions associated with a project.

    Optionally pass in filters to narrow down the results based on specific criteria.

    Args:
        client: The client instance to use for querying W&B.
        entity: The entity (user or team) that owns the project.
        project: The name of the project to query for artifacts.
        collection_name: The name of the artifact collection to query.
        type: The type of the artifacts to query. Common examples include
            "dataset" or "model".
        filters: Optional mapping of filters to apply to the query.
        order: Optional string to specify the order of the results.
        per_page: The number of artifact versions to fetch per page. Default is 50.
        tags: Optional string or list of strings to filter artifacts by tags.

    <!-- lazydoc-ignore-init: internal -->
    r$   r@   z!_ArtifactConnectionGeneric | NonerA   Nro   rC   r%   rp   rE   rq   r   rL   r   r   r   r   rF   rG   r   str | list[str] | Nonec
                   s   ddl m}
 t|
| _|| _|| _|| _|| _|d u rddin|| _t	|	p&g | _
|| _| j| j| j| j| jt| jd}t j|||d d S )Nr   )PROJECT_ARTIFACTS_GQLstate	COMMITTED)rp   rq   r   rL   r   r   rJ   )r:   r  r   r@   rp   r   rL   rq   r   r   r   r   r   r   rM   rN   )rO   rC   rp   rq   r   rL   r   r   rF   r   r  rK   rP   r;   r<   rN   I  s"   

zArtifacts.__init__r3   rR   c           	      C  s   ddl m}m} | jj| j| jd}||}|j }r+|j	 }r+|j
 }r+|j }s7tdtt| dt| || _d S )Nr   )r(   ProjectArtifactsrT   rV   rW   )r:   r(   r  rC   rX   r@   rK   rY   rq   r   rZ   r   r\   r   rL   r  rA   )	rO   r(   r  r]   r^   rx   r   r   r`   r;   r;   r<   ra   j  s"   
zArtifacts._update_responseedge&_ArtifactEdgeGeneric[ArtifactFragment]r/   c                 C  sH   ddl m} ddlm} |j|| j| j| j d|j d|j	| j
dS )Nr   FullArtifactPathr.   :prefixrq   r|   pathsrc_artrC   )r   r  wandb.sdk.artifacts.artifactr/   _from_attrsrp   rq   r   r  rb   rC   )rO   r  r  r/   r;   r;   r<   rf     s   zArtifacts._convertlist[Artifact]c                   sF   j  }du r	g S fdd|jD }tjpg   fdd|D S )zxConvert the raw response data into a list of wandb.Artifact objects.

        <!-- lazydoc-ignore: internal -->
        Nc                 3  s     | ]}|j r |V  qd S rc   )rb   rf   )r   r  r   r;   r<   	<genexpr>  s    z,Artifacts.convert_objects.<locals>.<genexpr>c                   s   g | ]
}  |jr|qS r;   )issubsetr   )r   art)required_tagsr;   r<   r     s    z-Artifacts.convert_objects.<locals>.<listcomp>)rA   r  r  r   )rO   r`   r   r;   )r+  rO   r<   convert_objects  s
   zArtifacts.convert_objects)NNro   N)rC   r%   rp   rE   rq   rE   r   rE   rL   rE   r   r   r   r   rF   rG   r   r  rg   )r  r  r3   r/   )r3   r'  )rh   ri   rj   rk   rl   rN   r   ra   rf   r,  rm   r;   r;   rP   r<   r   0  s   
 	!r   )r(   r/   c                      sR   e Zd ZU dZded< ded< 		dd fddZedddZdddZ  Z	S )RunArtifactsztAn iterable collection of artifacts associated with a specific run.

    <!-- lazydoc-ignore-init: internal -->
    r$   r@   z,ConnectionWithTotal[ArtifactFragment] | NonerA   r8   ro   rC   r%   runr0   modeLiteral['logged', 'used']rF   rG   c                   s^   zt  | }W n ty   tdw t|| _|| _|j|j|jd}t	 j
|||d d S )Nzmode must be logged or used)rp   rq   r.  rJ   )r=   LookupErrorr\   r   r@   r.  rp   rq   rI   rM   rN   )rO   rC   r.  r/  rF   	query_strrK   rP   r;   r<   rN     s   
zRunArtifacts.__init__r3   rR   c                 C  s@   ddl m} | jj| j| jd}|d d d }||| _d S )Nr   )RunArtifactConnectionrT   rq   r.  r   )rv   r3  rC   rX   r@   rK   rY   rA   )rO   r3  r]   
inner_datar;   r;   r<   ra     s   zRunArtifacts._update_responserb   r(   Artifact | Nonec                 C  sb   ddl m} ddlm} |jjd u rd S |j||jjjj|jjj|jj d|j	 d|| j
dS )Nr   r  r.   z:vr   r"  )r   r  r%  r/   artifact_sequencerq   r&  rp   r|   version_indexrC   )rO   rb   r  r/   r;   r;   r<   rf     s   
zRunArtifacts._convert)r8   ro   )rC   r%   r.  r0   r/  r0  rF   rG   rg   )rb   r(   r3   r5  )
rh   ri   rj   rk   rl   rN   r   ra   rf   rm   r;   r;   rP   r<   r-    s   
 	r-  c                      sj   e Zd ZU dZded< ded< 		d!d" fddZed#ddZed$ddZ	d%ddZ
d&dd Z  ZS )'ArtifactFileszVA paginator for files in an artifact.

    <!-- lazydoc-ignore-init: internal -->
    r$   r@   zArtifactFileConnection | NonerA   Nro   rC   r%   artifactr/   namesSequence[str] | NonerF   rG   c                   s   ddl m}m} ddlm} ||tj| _|| _| jr/|}|j	|j
|jdd |j|d}	n|}|j|j|j|j|d}	||tjrEd ndh}
t||
d| _t j||	|d	 d S )
Nr   )GET_ARTIFACT_FILES_GQL!GET_ARTIFACT_MEMBERSHIP_FILES_GQLr   r  )rp   rq   r   rd   	fileNames)rp   rq   r|   rL   r>  r   )r   rJ   )r:   r<  r=  wandb.sdk.artifacts._gqlutilsr   r   $ARTIFACT_COLLECTION_MEMBERSHIP_FILESquery_via_membershipr9  rp   rq   r|   splitr  source_entitysource_projectsource_namerL   TOTAL_COUNT_IN_FILE_CONNECTIONr#   r@   rM   rN   )rO   rC   r9  r:  rF   r<  r=  r   r2  rK   r   rP   r;   r<   rN     s6   

zArtifactFiles.__init__r3   rR   c                 C  s   ddl m}m} ddlm} | jj| j| jd}| j	r'|
|}|jjjj}n|
|}|jjjj}|d u rBtdtt| d|
|| _d S )Nr   )GetArtifactFilesGetArtifactMembershipFiles)r,   rT   rV   rW   )r:   rG  rH  rv   r,   rC   rX   r@   rK   rA  rY   rq   rZ   artifact_membershipfilesr   r9  r\   r   rL   rA   )rO   rG  rH  r,   r]   r^   r`   r;   r;   r<   ra     s   

zArtifactFiles._update_responser   c                 C  s   | j j| j j| j jgS )z!Returns the path of the artifact.)r9  rp   rq   r|   r   r;   r;   r<   r#  %  s   zArtifactFiles.pathrb   r*   r"   c                 C  s   t | j|jdddS )NT)exclude_unset)r{   )r"   rC   r   re   r;   r;   r<   rf   *  r  zArtifactFiles._convertrE   c                 C  sJ   d | j}zt| }W n ty   d| d Y S w d| d| dS )N/z<ArtifactFiles r   r
  r  )joinr#  lenNotImplementedError)rO   path_strtotalr;   r;   r<   r   -  s   zArtifactFiles.__repr__)Nro   )rC   r%   r9  r/   r:  r;  rF   rG   rg   r  )rb   r*   r3   r"   r   )rh   ri   rj   rk   rl   rN   r   ra   r   r#  rf   r   rm   r;   r;   rP   r<   r8    s   
 -
r8  )r*   r"   )r3   r4   )Wrk   
__future__r   r   collections.abcr   r   r   r   r   	functoolsr   typingr	   r
   r   r   r   r   typing_extensionsr   	wandb_gqlr   wandb._iterutilsr   wandb._pydanticr   r   r   wandb._strutilsr   wandb.apis.normalizer   wandb.apis.paginatorr   r   wandb.errors.errorsr   wandb.errors.termr   wandb.protor   r   wandb.proto.wandb_telemetry_pb2r   r?  r   wandb.sdk.artifacts._modelsr   wandb.sdk.lib.deprecationr    rJ  r"   utilsr#   wandb_graphql.language.astr$   wandb.apis.public.apir%   r:   r&   r'   r(   r)   r*   rv   r+   r,   r-   r%  r/    r0   r1   r=   rE   r>   rn   ry   r   r   r   r  r  r   r-  r8  r;   r;   r;   r<   <module>   sd     *3
n
]f  Sr6