a
    ”˜ëj8¤  ã                   @  sn  d 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mZmZmZmZ ddlmZ dd	lmZmZ z$dd
lmZmZmZmZmZmZ W n2 eyÚ   dd
l mZmZmZmZmZmZ Y n0 ddl!m"Z" ddlm#Z# eeeedf Z$ee%e&df Z'G dd„ deƒZ(e%e&ee)e&e*f e(e)e&e"f f f Z+eG dd„ deƒƒZ,G dd„ deƒZ-G dd„ deƒZ.ee(e.e)e&e*f e)e&e"f f Z/G dd„ deƒZ0e0Z1G dd„ de0ƒZ2G dd„ deƒZ3G dd„ de-ƒZ4G dd„ de-ƒZ5G d d!„ d!eƒZ6G d"d#„ d#eƒZ7e7Z8G d$d%„ d%e&eƒZ9G d&d'„ d'eƒZ:e#d( Z;G d)d*„ d*ed+d,�Z<G d-d.„ d.e:ƒZ=G d/d0„ d0eƒZ>d1d2„ Z?G d3d4„ d4eƒZ@G d5d6„ d6e@ƒZAG d7d8„ d8e&eƒZBG d9d:„ d:ed+d,�ZCG d;d<„ d<e@ƒZDG d=d>„ d>eƒZEG d?d@„ d@eEƒZFG dAdB„ dBeEƒZGG dCdD„ dDeƒZHG dEdF„ dFeƒZIG dGdH„ dHed+d,�ZJG dIdJ„ dJed+d,�ZKG dKdL„ dLeIƒZLG dMdN„ dNeIƒZMG dOdP„ dPeƒZNG dQdR„ dReNƒZOeG dSdT„ dTeƒƒZPG dUdV„ dVed+d,�ZQG dWdX„ dXeƒZRG dYdZ„ dZeRƒZSG d[d\„ d\ed+d,�ZTG d]d^„ d^eƒZUe4 V¡  G d_d`„ d`eƒZWG dadb„ dbeƒZXG dcdd„ dded+d,�ZYG dedf„ dfed+d,�ZZG dgdh„ dheƒZ[G didj„ djeƒZ\G dkdl„ dleƒZ]G dmdn„ dneƒZ^G dodp„ dpeƒZ_G dqdr„ dreƒZ`G dsdt„ dte&eƒZaG dudv„ dved+d,�ZbG dwdx„ dxed+d,�ZcG dydz„ dzed+d,�ZdG d{d|„ d|ed+d,�ZeG d}d~„ d~eƒZfG dd€„ d€ed+d,�ZgG d�d‚„ d‚eƒZhG dƒd„„ d„e4ƒZiG d…d†„ d†eƒZjG d‡dˆ„ dˆeƒZkdS )‰zSchemas for the LangSmith API.é    )Úannotations)ÚIterator)ÚdatetimeÚ	timedeltaÚtimezone)ÚDecimal)ÚEnum)ÚAnyÚ
NamedTupleÚOptionalÚProtocolÚUnionÚruntime_checkable)ÚUUID)ÚNotRequiredÚ	TypedDict)Ú	BaseModelÚFieldÚPrivateAttrÚ
StrictBoolÚStrictFloatÚ	StrictInt)ÚPath)ÚLiteralNc                   @  s"   e Zd ZU dZded< ded< dS )Ú
Attachmenta©  Annotated type that will be stored as an attachment if used.

    Examples:

        .. code-block:: python

            from langsmith import traceable
            from langsmith.schemas import Attachment


            @traceable
            def my_function(bar: int, my_val: Attachment):
                # my_val will be stored as an attachment
                # bar will be stored as inputs
                return bar
    ÚstrÚ	mime_typeúUnion[bytes, Path]ÚdataN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© r%   r%   úP/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langsmith/schemas.pyr   0   s   
r   c                   @  sD   e Zd ZdZddddœdd„Zddddd	œd
d„Zddœdd„ZdS )ÚBinaryIOLikez$Protocol for binary IO-like objects.éÿÿÿÿÚintÚbytes)ÚsizeÚreturnc                 C  s   dS )zRead function.Nr%   )Úselfr+   r%   r%   r&   ÚreadO   s    zBinaryIOLike.readr   )ÚoffsetÚwhencer,   c                 C  s   dS )zSeek function.Nr%   )r-   r/   r0   r%   r%   r&   ÚseekS   s    zBinaryIOLike.seek©r,   c                 C  s   dS )zGet value function.Nr%   ©r-   r%   r%   r&   ÚgetvalueW   s    zBinaryIOLike.getvalueN)r(   )r   )r    r!   r"   r#   r.   r1   r4   r%   r%   r%   r&   r'   K   s   r'   c                   @  s^   e Zd ZU dZded< edd�Zded< edd�Zded< edd�Zded	< G d
d„ dƒZ	dS )ÚExampleBasezExample base model.r   Ú
dataset_idN©ÚdefaultúOptional[dict[str, Any]]ÚinputsÚoutputsÚmetadatac                   @  s   e Zd ZdZdZdZdS )zExampleBase.Configú#Configuration class for the schema.TN)r    r!   r"   r#   ÚfrozenÚarbitrary_types_allowedr%   r%   r%   r&   ÚConfigd   s   r@   )
r    r!   r"   r#   r$   r   r:   r;   r<   r@   r%   r%   r%   r&   r5   \   s   
r5   c                   @  s   e Zd ZU ded< ded< dS )Ú_AttachmentDictr   r   r   r   N)r    r!   r"   r$   r%   r%   r%   r&   rA   k   s   
rA   c                      s²   e Zd ZU dZded< edd„ d�Zded< ed	d
�Zded< ed	d
�Zded< ed	d
�Z	ded< d	Z
ded< d	Zded< dZded< d	Zded< d	Zded< ‡ fdd„Z‡  ZS )ÚExampleCreatez Example upload with attachments.úOptional[UUID]Úidc                   C  s   t  tj¡S ©N©r   Únowr   Úutcr%   r%   r%   r&   Ú<lambda>y   ó    zExampleCreate.<lambda>©Údefault_factoryr   Ú
created_atNr7   r9   r:   r;   r<   úOptional[Union[str, list[str]]]Úsplitz$Optional[dict[str, _AttachmentLike]]ÚattachmentsFÚboolÚuse_source_run_ioúOptional[list[str]]Úuse_source_run_attachmentsÚsource_run_idc                   s   t ƒ jf i |¤Ž dS ©zInitialize from dict.N©ÚsuperÚ__init__©r-   r   ©Ú	__class__r%   r&   rY   ƒ   s    zExampleCreate.__init__)r    r!   r"   r#   r$   r   rM   r:   r;   r<   rO   rP   rR   rT   rU   rY   Ú__classcell__r%   r%   r[   r&   rB   u   s   
rB   c                   @  s   e Zd ZU dZded< dS )ÚExampleUpsertWithAttachmentsz Example create with attachments.r   r6   Nr   r%   r%   r%   r&   r^   ‹   s   
r^   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	ÚAttachmentInfozInfo for an attachment.r   Zpresigned_urlr'   ÚreaderúOptional[str]r   Nr   r%   r%   r%   r&   r_   ‘   s   
r_   c                      sÒ   e Zd ZU dZded< edd„ d�Zded< eed	ƒd
�Zded< edd
�Z	ded< dZ
ded< edd
�Zded< edd
�Zded< edd
�Zded< d dddddœ‡ fdd„Zeddœdd„ƒZdd„ Z‡  ZS )!ÚExamplezExample model.r   rD   c                   C  s   t jdtjd�S )Nr   )Útz)r   Úfromtimestampr   rH   r%   r%   r%   r&   rI   ž   rJ   zExample.<lambda>rK   r   rM   z$00000000-0000-0000-0000-000000000000r7   r6   NúOptional[datetime]Úmodified_atrC   rU   z#Optional[dict[str, AttachmentInfo]]rP   ra   Ú	_host_urlÚ
_tenant_idr	   ÚNone)rg   rh   Úkwargsr,   c                   s"   t ƒ jf i |¤Ž || _|| _dS )úInitialize a Dataset object.N)rX   rY   rg   rh   )r-   rg   rh   rj   r[   r%   r&   rY   ©   s    zExample.__init__r2   c                 C  sL   | j rHd| j› d| j› �}| jr:| j › dt| jƒ› |› �S | j › |› �S dS )úURL of this run within the app.ú
/datasets/z/e/ú/o/N)rg   r6   rD   rh   r   )r-   Úpathr%   r%   r&   Úurl´   s    zExample.urlc                 C  s$   | j › d| j› d| j› d| j› d�S )ú5Return a string representation of the RunBase object.ú(id=z, dataset_id=z, link='ú'))r\   rD   r6   rp   r3   r%   r%   r&   Ú__repr__¾   s    zExample.__repr__)NN)r    r!   r"   r#   r$   r   rM   r   r6   rf   rU   rP   r   rg   rh   rY   Úpropertyrp   rt   r]   r%   r%   r[   r&   rb   ™   s"   
ÿ  ý	rb   c                   @  s   e Zd ZU dZded< dS )ÚExampleSearchzExample returned via search.r   rD   Nr   r%   r%   r%   r&   rv   Ã   s   
rv   c                   @  s:   e Zd ZU dZeedd�Zded< eedd�Z	ded< d	S )
ÚAttachmentsOperationsz%Operations to perform on attachments.z,Mapping of old attachment names to new names)rL   Údescriptionzdict[str, str]Úrenamez List of attachment names to keepú	list[str]ÚretainN)
r    r!   r"   r#   r   Údictry   r$   Úlistr{   r%   r%   r%   r&   rw   É   s   
ÿÿrw   c                      sž   e Zd ZU dZded< dZded< edd�Zded	< edd�Zded
< edd�Z	ded< dZ
ded< dZded< dZded< G dd„ dƒZ‡ fdd„Z‡  ZS )ÚExampleUpdatez Example update with attachments.r   rD   NrC   r6   r7   r9   r:   r;   r<   rN   rO   zOptional[Attachments]rP   zOptional[AttachmentsOperations]Úattachments_operationsc                   @  s   e Zd ZdZdZdS )zExampleUpdate.Configr=   TN©r    r!   r"   r#   r>   r%   r%   r%   r&   r@   à   s   r@   c                   s   t ƒ jf i |¤Ž dS rV   rW   rZ   r[   r%   r&   rY   å   s    zExampleUpdate.__init__)r    r!   r"   r#   r$   r6   r   r:   r;   r<   rO   rP   r   r@   rY   r]   r%   r%   r[   r&   r~   Ô   s   
r~   c                   @  s   e Zd ZdZdZdZdZdS )ÚDataTypezEnum for dataset data types.ÚkvÚllmÚchatN)r    r!   r"   r#   r‚   rƒ   r„   r%   r%   r%   r&   r�   í   s   r�   c                   @  s@   e Zd ZU dZded< dZded< dZded< G d	d
„ d
ƒZdS )ÚDatasetBasezDataset base model.r   ÚnameNra   rx   zOptional[DataType]Ú	data_typec                   @  s   e Zd ZdZdZdS )zDatasetBase.Configr=   TNr€   r%   r%   r%   r&   r@   ü   s   r@   )r    r!   r"   r#   r$   rx   r‡   r@   r%   r%   r%   r&   r…   õ   s
   
r…   )Zremove_system_messagesZconvert_to_openai_messageZconvert_to_openai_toolZremove_extra_fieldsZextract_tools_from_runc                   @  s"   e Zd ZU dZded< ded< dS )ÚDatasetTransformationz#Schema for dataset transformations.rz   ro   z%Union[DatasetTransformationType, str]Ztransformation_typeNr   r%   r%   r%   r&   rˆ     s   
rˆ   F)Útotalc                      sð   e Zd ZU dZded< ded< edd�Zded	< dZd
ed< dZd
ed< dZ	ded< dZ
ded< dZded< dZded< dZded< edd�Zded< edd�Zded< edd�Zded< d!ddddddœ‡ fdd„Zeddœdd „ƒZ‡  ZS )"ÚDatasetzDataset ORM model.r   rD   r   rM   Nr7   re   rf   úOptional[int]Úexample_countÚsession_countÚlast_session_start_timer9   Úinputs_schemaÚoutputs_schemaz%Optional[list[DatasetTransformation]]Útransformationsr<   ra   rg   rC   rh   Ú_public_pathr	   ri   )rg   rh   r’   rj   r,   c                   sT   d|v r|  d¡|d< d|v r,|  d¡|d< tƒ jf i |¤Ž || _|| _|| _dS )rk   Zinputs_schema_definitionr�   Zoutputs_schema_definitionr�   N)ÚpoprX   rY   rg   rh   r’   )r-   rg   rh   r’   rj   r[   r%   r&   rY   #  s    zDataset.__init__r2   c                 C  sV   | j rR| jr| j › | j› �S | jr@| j › dt| jƒ› d| j› �S | j › d| j› �S dS )rl   rn   rm   N)rg   r’   rh   r   rD   r3   r%   r%   r&   rp   6  s    zDataset.url)NNN)r    r!   r"   r#   r$   r   rf   rŒ   r�   rŽ   r�   r�   r‘   r<   r   rg   rh   r’   rY   ru   rp   r]   r%   r%   r[   r&   rŠ     s(   
   ürŠ   c                   @  s&   e Zd ZU dZdZded< ded< dS )ÚDatasetVersionz%Class representing a dataset version.NrS   Útagsr   Zas_of)r    r!   r"   r#   r•   r$   r%   r%   r%   r&   r”   B  s   
r”   c                   C  s   di iS )Nr<   r%   r%   r%   r%   r&   Ú_default_extraI  s    r–   c                   @  s  e Zd ZU dZded< ded< ded< ded< d	Zd
ed< eed�Zded< d	Z	ded< d	Z
ded< d	Zded< eed�Zded< d	Zded< d	Zded< d	Zded< d	Zded< eed�Zded< eddœd d!„ƒZeddœd"d#„ƒZed$dœd%d&„ƒZd'd(„ ZG d)d*„ d*ƒZd	S )+ÚRunBasea3  Base Run schema.

    A Run is a span representing a single unit of work or operation within your LLM app.
    This could be a single call to an LLM or chain, to a prompt formatting call,
    to a runnable lambda invocation. If you are familiar with OpenTelemetry,
    you can think of a run as a span.
    r   rD   r   r†   r   Ú
start_timeÚrun_typeNre   Úend_timerK   úOptional[dict]Úextrara   ÚerrorÚ
serializedúOptional[list[dict]]Úeventsr|   r:   r;   rC   Úreference_example_idÚparent_run_idrS   r•   z-Union[Attachments, dict[str, AttachmentInfo]]rP   údict[str, Any]r2   c                 C  s   | j du ri | _ | j  di ¡S ©zRetrieve the metadata (if any).Nr<   )rœ   Ú
setdefaultr3   r%   r%   r&   r<   ˆ  s    
zRunBase.metadatac                 C  s   | j  d¡S )z"Retrieve the revision ID (if any).Úrevision_id)r<   Úgetr3   r%   r%   r&   r¦   �  s    zRunBase.revision_idúOptional[float]c                 C  s   | j du rdS | j | j  ¡ S )zLatency in seconds.N)rš   r˜   Útotal_secondsr3   r%   r%   r&   Úlatency”  s    
zRunBase.latencyc                 C  s$   | j › d| j› d| j› d| j› d�S )rq   rr   z, name='z', run_type='rs   )r\   rD   r†   r™   r3   r%   r%   r&   rt   ›  s    zRunBase.__repr__c                   @  s   e Zd ZdZdZdS )zRunBase.Configr=   TN)r    r!   r"   r#   r?   r%   r%   r%   r&   r@   Ÿ  s   r@   )r    r!   r"   r#   r$   rš   r   r–   rœ   r�   rž   r    r|   r:   r;   r¡   r¢   r•   rP   ru   r<   r¦   rª   rt   r@   r%   r%   r%   r&   r—   M  s4   
ÿr—   c                      sì  e Zd ZU dZdZded< dZded< dZded< dZd	ed
< dZ	ded< dZ
ded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< dZded< d ed!< ed"d#�Zd$ed%< dZd&ed'< edd#�Zded(< dEdd)d*d+œ‡ fd,d-„Zedd.œd/d0„ƒZed1d.œd2d3„ƒZ ed1d.œd4d5„ƒZ!ed6d.œd7d8„ƒZ"ed6d.œd9d:„ƒZ#ed;d.œd<d=„ƒZ$ed;d.œd>d?„ƒZ%ed@d.œdAdB„ƒZ&ed@d.œdCdD„ƒZ'‡  Z(S )FÚRunz$Run schema when loading from the DB.NrC   Ú
session_idúOptional[list[UUID]]Úchild_run_idszOptional[list[Run]]Ú
child_runsr9   Úfeedback_statsra   Úapp_pathÚmanifest_idÚstatusr‹   Úprompt_tokensÚcompletion_tokensÚtotal_tokenszOptional[dict[str, int]]Úprompt_token_detailsÚcompletion_token_detailsre   Úfirst_token_timeúOptional[Decimal]Ú
total_costÚprompt_costÚcompletion_costzOptional[dict[str, Decimal]]Úprompt_cost_detailsÚcompletion_cost_detailsÚparent_run_idsr   Útrace_idÚ r7   r   Údotted_orderúOptional[bool]Ú
in_datasetrg   r	   ri   ©rg   rj   r,   c                   sv   |  d¡sd|  d¡i|¥}| dd¡p*i }tƒ jf i |¤d|i¤Ž || _| j ¡ sr| jsr| j 	¡ › | j
› �| _dS )úInitialize a Run object.rÁ   rD   r:   N)r§   r“   rX   rY   rg   rÃ   Ústripr¢   r˜   Ú	isoformatrD   )r-   rg   rj   r:   r[   r%   r&   rY   í  s    
zRun.__init__r2   c                 C  s    | j r| jr| j › | j› �S dS )rl   N)rg   r±   r3   r%   r%   r&   rp   ÷  s    zRun.urlz
int | Nonec                 C  s   | j S )zAlias for prompt_tokens.)r´   r3   r%   r%   r&   Úinput_tokensþ  s    zRun.input_tokensc                 C  s   | j S )zAlias for completion_tokens.)rµ   r3   r%   r%   r&   Úoutput_tokens  s    zRun.output_tokenszDecimal | Nonec                 C  s   | j S )zAlias for prompt_cost.)r¼   r3   r%   r%   r&   Ú
input_cost  s    zRun.input_costc                 C  s   | j S )zAlias for completion_cost.)r½   r3   r%   r%   r&   Úoutput_cost  s    zRun.output_costzdict[str, int] | Nonec                 C  s   | j S )zAlias for prompt_token_details.)r·   r3   r%   r%   r&   Úinput_token_details  s    zRun.input_token_detailsc                 C  s   | j S )zAlias for output_token_details.)r¸   r3   r%   r%   r&   Úoutput_token_details  s    zRun.output_token_detailszdict[str, Decimal] | Nonec                 C  s   | j S )zAlias for prompt_cost_details.)r¾   r3   r%   r%   r&   Úinput_cost_details  s    zRun.input_cost_detailsc                 C  s   | j S )z"Alias for completion_cost_details.)r¿   r3   r%   r%   r&   Úoutput_cost_details!  s    zRun.output_cost_details)N))r    r!   r"   r#   r¬   r$   r®   r¯   r°   r±   r²   r³   r´   rµ   r¶   r·   r¸   r¹   r»   r¼   r½   r¾   r¿   rÀ   r   rÃ   rÅ   r   rg   rY   ru   rp   rÊ   rË   rÌ   rÍ   rÎ   rÏ   rÐ   rÑ   r]   r%   r%   r[   r&   r«   ¥  sV   

r«   c                   @  s,   e Zd ZdZdZdZdZdZdZdZ	dZ
d	S )
ÚRunTypeEnumz5(Deprecated) Enum for run types. Use string directly.ÚtoolÚchainrƒ   Ú	retrieverÚ	embeddingÚpromptÚparserN)r    r!   r"   r#   rÓ   rÔ   rƒ   rÕ   rÖ   r×   rØ   r%   r%   r%   r&   rÒ   '  s   rÒ   c                   @  sÒ   e Zd ZU dZded< ded< ded< ded	< ded
< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< d ed!< ded"< d#ed$< d%S )&ÚRunLikeDictz&Run-like dictionary, for type-hinting.r   r†   rÒ   r™   r   r˜   r›   r:   r;   re   rš   rœ   ra   r�   rž   rC   r¢   r²   rŸ   r    rS   r•   Zinputs_s3_urlsZoutputs_s3_urlsrD   r¬   Zsession_namer¡   Zinput_attachmentsZoutput_attachmentsr   rÁ   rÃ   ÚAttachmentsrP   Nr   r%   r%   r%   r&   rÙ   3  s2   
rÙ   c                   @  s*   e Zd ZU dZdZded< dZded< dS )ÚRunWithAnnotationQueueInfoz&Run schema with annotation queue info.Nre   Úlast_reviewed_timeÚadded_at)r    r!   r"   r#   rÜ   r$   rÝ   r%   r%   r%   r&   rÛ   P  s   
rÛ   c                   @  sD   e Zd ZU dZded< eed�Zded< dZded	< dZ	d
ed< dS )ÚFeedbackSourceBasez‰Base class for feedback sources.

    This represents whether feedback is submitted from the API, model, human labeler,
        etc.
    r   ÚtyperK   r9   r<   NzOptional[Union[UUID, str]]Úuser_idra   Ú	user_name)
r    r!   r"   r#   r$   r   r|   r<   rà   rá   r%   r%   r%   r&   rÞ   Y  s   
rÞ   c                   @  s   e Zd ZU dZdZded< dS )ÚAPIFeedbackSourcezAPI feedback source.ÚapizLiteral['api']rß   N©r    r!   r"   r#   rß   r$   r%   r%   r%   r&   râ   j  s   
râ   c                   @  s   e Zd ZU dZdZded< dS )ÚModelFeedbackSourcezModel feedback source.ÚmodelzLiteral['model']rß   Nrä   r%   r%   r%   r&   rå   p  s   
rå   c                   @  s   e Zd ZdZdZdZdS )ÚFeedbackSourceTypezFeedback source type.rã   ræ   N)r    r!   r"   r#   ZAPIZMODELr%   r%   r%   r&   rç   v  s   rç   c                   @  sÄ   e Zd ZU dZded< dZded< dZded< ded	< ded
< ded< dZded< dZded< dZ	ded< dZ
ded< dZded< dZded< dZded< dZded< dZded< G dd„ dƒZdS )ÚFeedbackBasezFeedback schema.r   rD   Nre   rM   rf   rC   Zrun_idrÁ   r   ÚkeyÚ
SCORE_TYPEÚscoreÚ
VALUE_TYPEÚvaluera   ÚcommentzUnion[str, dict, None]Ú
correctionúOptional[FeedbackSourceBase]Úfeedback_sourcer¬   Úcomparative_experiment_idÚfeedback_group_idr›   rœ   c                   @  s   e Zd ZdZdZdS )zFeedbackBase.Configr=   TNr€   r%   r%   r%   r&   r@   £  s   r@   )r    r!   r"   r#   r$   rM   rf   rë   rí   rî   rï   rñ   r¬   rò   ró   rœ   r@   r%   r%   r%   r&   rè     s"   
rè   c                   @  s"   e Zd ZU dZded< ded< dS )ÚFeedbackCategoryz+Specific value and label pair for feedback.Úfloatrí   ra   ÚlabelNr   r%   r%   r%   r&   rô   ©  s   
rô   c                   @  s2   e Zd ZU dZded< ded< ded< ded< d	S )
ÚFeedbackConfigz:Represents _how_ a feedback value ought to be interpreted.z0Literal['continuous', 'categorical', 'freeform']rß   r¨   ÚminÚmaxz Optional[list[FeedbackCategory]]Ú
categoriesNr   r%   r%   r%   r&   r÷   ²  s   
r÷   c                   @  s2   e Zd ZU dZded< dZded< dZded< dS )	ÚFeedbackCreatez"Schema used for creating feedback.rÞ   rñ   NzOptional[FeedbackConfig]Úfeedback_configrÄ   r�   )r    r!   r"   r#   r$   rü   r�   r%   r%   r%   r&   rû   À  s   
rû   c                   @  s6   e Zd ZU dZded< ded< ded< dZded	< dS )
ÚFeedbackzSchema for getting feedback.r   rD   r   rM   rf   Nrð   rñ   )r    r!   r"   r#   r$   rñ   r%   r%   r%   r&   rý   Ê  s   
rý   c                      sÔ   e Zd ZU dZded< edd„ d�Zded< d	Zd
ed< d	Zded< d	Z	ded< d	Z
ded< ded< ded< ed	d�Zded< d$ddddœ‡ fdd„Zeddœdd„ƒZeddœdd „ƒZed!dœd"d#„ƒZ‡  ZS )%ÚTracerSessionzbTracerSession schema for the API.

    Sessions are also referred to as "Projects" in the UI.
    r   rD   c                   C  s   t  tj¡S rE   rF   r%   r%   r%   r&   rI   Þ  rJ   zTracerSession.<lambda>rK   r   r˜   Nre   rš   ra   rx   r†   r9   rœ   Ú	tenant_idrC   Úreference_dataset_idr7   rg   r	   ri   rÆ   c                   s:   t ƒ jf i |¤Ž || _| jjdu r6| jjtjd�| _dS )rÇ   N)Útzinfo)rX   rY   rg   r˜   r  Úreplacer   rH   )r-   rg   rj   r[   r%   r&   rY   ï  s    zTracerSession.__init__r2   c                 C  s$   | j r | j › d| j› d| j› �S dS )rl   rn   z/projects/p/N)rg   rÿ   rD   r3   r%   r%   r&   rp   ö  s    zTracerSession.urlr£   c                 C  s"   | j du sd| j vri S | j d S r¤   ©rœ   r3   r%   r%   r&   r<   ý  s    zTracerSession.metadatarz   c                 C  s"   | j du sd| j vrg S | j d S )zRetrieve the tags (if any).Nr•   r  r3   r%   r%   r&   r•     s    zTracerSession.tags)N)r    r!   r"   r#   r$   r   r˜   rš   rx   r†   rœ   r   rg   rY   ru   rp   r<   r•   r]   r%   r%   r[   r&   rþ   Ö  s"   
rþ   c                   @  s’   e Zd ZU dZded< ded< ded< ded< ded< ded	< d
ed< ded< ded< ded< ded< ded< ded< ded< ded< ded< dS )ÚTracerSessionResultzqA project, hydrated with additional information.

    Sessions are also referred to as "Projects" in the UI.
    r‹   Ú	run_countúOptional[timedelta]Úlatency_p50Úlatency_p99r¶   r´   rµ   re   Úlast_run_start_timer9   r°   Zsession_feedback_statsúOptional[list[dict[str, Any]]]Ú
run_facetsrº   r»   r¼   r½   Úfirst_token_p50Úfirst_token_p99r¨   Ú
error_rateNr   r%   r%   r%   r&   r    s$   
r  c                   @  s4   e Zd ZU dZded< ded< eddœdd„ƒZd	S )
ÚBaseMessageLikez7A protocol representing objects similar to BaseMessage.r   Úcontentzdict[Any, Any]Zadditional_kwargsr2   c                 C  s   dS )z,Type of the Message, used for serialization.Nr%   r3   r%   r%   r&   rß   =  s    zBaseMessageLike.typeN)r    r!   r"   r#   r$   ru   rß   r%   r%   r%   r&   r  4  s
   
r  c                   @  s*   e Zd ZU dZded< ded< ded< dS )ÚDatasetShareSchemaz*Represents the schema for a dataset share.r   r6   Zshare_tokenr   rp   Nr   r%   r%   r%   r&   r  B  s
   
r  c                   @  sb   e Zd ZU dZded< ded< dZded< ed	d
„ d�Zded< edd
„ d�Zded< ded< dS )ÚAnnotationQueuezRepresents an annotation queue.r   rD   r   r†   Nra   rx   c                   C  s   t  tj¡S rE   rF   r%   r%   r%   r&   rI   V  rJ   zAnnotationQueue.<lambda>rK   r   rM   c                   C  s   t  tj¡S rE   rF   r%   r%   r%   r&   rI   X  rJ   Ú
updated_atrÿ   )	r    r!   r"   r#   r$   rx   r   rM   r  r%   r%   r%   r&   r  M  s   
r  c                   @  s   e Zd ZU dZdZded< dS )ÚAnnotationQueueWithDetailsz,Represents an annotation queue with details.Nra   Úrubric_instructions)r    r!   r"   r#   r  r$   r%   r%   r%   r&   r  ^  s   
r  c                   @  sB   e Zd ZU dZded< ded< ded< ded< ded< d	ed
< dS )ÚBatchIngestConfigz"Configuration for batch ingestion.rQ   Zuse_multipart_endpointr)   Zscale_up_qsize_triggerZscale_up_nthreads_limitZscale_down_nempty_triggerZ
size_limitr‹   Zsize_limit_bytesNr   r%   r%   r%   r&   r  e  s   
r  c                   @  sB   e Zd ZU dZdZded< dZded< dZded	< dZd
ed< dS )ÚLangSmithInfoz'Information about the LangSmith server.rÂ   r   ÚversionNre   Úlicense_expiration_timezOptional[BatchIngestConfig]Úbatch_ingest_configr9   Úinstance_flags)	r    r!   r"   r#   r  r$   r  r  r  r%   r%   r%   r&   r  v  s
   
r  c                   @  s6   e Zd ZU dZded< ded< ded< dZded	< dS )
ÚLangSmithSettingsz"Settings for the LangSmith tenant.r   rD   Zdisplay_namer   rM   Nra   Útenant_handle)r    r!   r"   r#   r$   r  r%   r%   r%   r&   r  …  s
   
r  c                   @  s*   e Zd ZU dZded< ded< ded< dS )	ÚFeedbackIngestTokenz2Represents the schema for a feedback ingest token.r   rD   r   rp   r   Z
expires_atNr   r%   r%   r%   r&   r  ‘  s
   
r  c                   @  s*   e Zd ZU dZded< ded< ded< dS )	ÚRunEventzRun event schema.r   r†   zUnion[datetime, str]Útimer9   rj   Nr   r%   r%   r%   r&   r  œ  s
   
r  c                   @  s*   e Zd ZU dZded< ded< ded< dS )ÚTimeDeltaInputzTimedelta input schema.r)   ÚdaysÚhoursÚminutesNr   r%   r%   r%   r&   r!  §  s
   
r!  c                   @  s*   e Zd ZU dZded< ded< ded< dS )ÚDatasetDiffInfoz;Represents the difference information between two datasets.z
list[UUID]Zexamples_modifiedZexamples_addedZexamples_removedNr   r%   r%   r%   r&   r%  ²  s
   
r%  c                   @  sˆ   e Zd ZU dZded< dZded< dZded< ded< d	ed
< d	ed< ded< dZded< dZded< dZ	ded< e
ddœdd„ƒZdS )ÚComparativeExperimentz’Represents a comparative experiment.

    This information summarizes evaluation results comparing
    two or more models on a given dataset.
    r   rD   Nra   r†   rx   rÿ   r   rM   rf   r   r9   rœ   rŸ   Úexperiments_infor°   r£   r2   c                 C  s"   | j du sd| j vri S | j d S r¤   r  r3   r%   r%   r&   r<   Ù  s    zComparativeExperiment.metadata)r    r!   r"   r#   r$   r†   rx   rœ   r'  r°   ru   r<   r%   r%   r%   r&   r&  ½  s   
r&  c                   @  s:   e Zd ZU dZded< ded< ded< ded< ded	< d
S )ÚPromptCommitz$Represents a Prompt with a manifest.r   ÚownerÚrepoÚcommit_hashr£   Úmanifestz
list[dict]ZexamplesNr   r%   r%   r%   r&   r(  á  s   
r(  c                   @  s¨   e Zd ZU dZded< ded< ded< dZded	< dZded
< dZded< dZded< dZ	ded< dZ
ded< eed�Zded< dZded< dZded< dZded< dS )ÚListedPromptCommitz;Represents a listed prompt commit with associated metadata.r   rD   r   r)  r*  NrC   r²   Úrepo_idÚ	parent_idra   r+  re   rM   r  rK   r­   Úexample_run_idsr   r‹   Únum_downloadsÚ	num_viewsÚparent_commit_hash)r    r!   r"   r#   r$   r²   r.  r/  r+  rM   r  r   r}   r0  r1  r2  r3  r%   r%   r%   r&   r-  ð  s   
r-  c                   @  sâ   e Zd ZU dZded< dZded< dZded< ded< ded	< d
ed< d
ed< ded< ded< ded< dZded< dZded< ded< ded< ded< ded< ded< dZ	ded< dZ
ded< ded< dZded< dZded< dS ) ÚPromptz"Represents a Prompt with metadata.r   Zrepo_handleNra   rx   ÚreadmerD   rÿ   r   rM   r  rQ   Z	is_publicZis_archivedrz   r•   Úoriginal_repo_idÚupstream_repo_idr)  Z	full_namer)   Ú	num_likesr1  r2  rÄ   Úliked_by_auth_userÚlast_commit_hashZnum_commitsÚoriginal_repo_full_nameÚupstream_repo_full_name)r    r!   r"   r#   r$   rx   r5  r6  r7  r9  r:  r;  r<  r%   r%   r%   r&   r4    s0   
r4  c                   @  s"   e Zd ZU dZded< ded< dS )ÚListPromptsResponsez A list of prompts with metadata.zlist[Prompt]Zreposr)   r‰   Nr   r%   r%   r%   r&   r=  L  s   
r=  c                   @  s    e Zd ZdZdZdZdZdZdS )ÚPromptSortFieldz$Enum for sorting fields for prompts.r1  r2  r  r8  N)r    r!   r"   r#   r1  r2  r  r8  r%   r%   r%   r&   r>  U  s   r>  c                   @  s*   e Zd ZU dZded< ded< ded< dS )ÚInputTokenDetailsz~Breakdown of input token counts.

    Does *not* need to sum to full input token count. Does *not* need to have all keys.
    r)   ÚaudioÚcache_creationÚ
cache_readNr   r%   r%   r%   r&   r?  b  s
   
r?  c                   @  s"   e Zd ZU dZded< ded< dS )ÚOutputTokenDetailsz€Breakdown of output token counts.

    Does *not* need to sum to full output token count. Does *not* need to have all keys.
    r)   r@  Ú	reasoningNr   r%   r%   r%   r&   rC  w  s   
rC  c                   @  s*   e Zd ZU dZded< ded< ded< dS )ÚInputCostDetailszvBreakdown of input token costs.

    Does *not* need to sum to full input cost. Does *not* need to have all keys.
    rõ   r@  rA  rB  Nr   r%   r%   r%   r&   rE  ‡  s
   
rE  c                   @  s"   e Zd ZU dZded< ded< dS )ÚOutputCostDetailszxBreakdown of output token costs.

    Does *not* need to sum to full output cost. Does *not* need to have all keys.
    rõ   r@  rD  Nr   r%   r%   r%   r&   rF  œ  s   
rF  c                   @  sb   e Zd ZU dZded< ded< ded< ded< ded	< d
ed< d
ed< d
ed< ded< ded< dS )ÚUsageMetadataz�Usage metadata for a message, such as token counts.

    This is a standard representation of token usage that is consistent across models.
    r)   rÊ   rË   r¶   zNotRequired[InputTokenDetails]rÎ   zNotRequired[OutputTokenDetails]rÏ   zNotRequired[float]rÌ   rÍ   r»   zNotRequired[InputCostDetails]rÐ   zNotRequired[OutputCostDetails]rÑ   Nr   r%   r%   r%   r&   rG  ¬  s   
rG  c                   @  sb   e Zd ZU dZded< ded< ded< ded< ded	< d
ed< d
ed< d
ed< ded< ded< dS )ÚExtractedUsageMetadataz�Usage metadata dictionary extracted from a run.

    Should be the same as UsageMetadata, but does not require all
    keys to be present.
    r)   rÊ   rË   r¶   r?  rÎ   rC  rÏ   rõ   rÌ   rÍ   r»   rE  rÐ   rF  rÑ   Nr   r%   r%   r%   r&   rH  Î  s   
rH  c                   @  s"   e Zd ZU dZded< ded< dS )ÚUpsertExamplesResponsezCResponse object returned from the upsert_examples_multipart method.r)   Úcountrz   Zexample_idsNr   r%   r%   r%   r&   rI  ë  s   
rI  c                   @  s$   e Zd ZU dZeed�Zded< dS )ÚExampleWithRunszExample with runs.rK   z	list[Run]ÚrunsN)r    r!   r"   r#   r   r}   rL  r$   r%   r%   r%   r&   rK  ô  s   
rK  c                   @  s‚   e Zd ZU dZded< ded< ded< ded< ded< ded	< d
ed< ded< ded< ded< ded< ded< ded< ded< dS )ÚExperimentRunStatsz!Run statistics for an experiment.r‹   r  r  r  r  r¶   r´   rµ   re   r	  r
  r  rº   r»   r¼   r½   r  r  r¨   r  Nr   r%   r%   r%   r&   rM  ü  s    
rM  c                   @  s*   e Zd ZU dZded< ded< ded< dS )	ÚExperimentResultsz´Results container for experiment data with stats and examples.

    Breaking change in v0.4.32:
        The 'stats' field has been split into 'feedback_stats' and 'run_stats'.
    r|   r°   rM  Z	run_statszIterator[ExampleWithRuns]Zexamples_with_runsNr   r%   r%   r%   r&   rN    s   
rN  )lr#   Ú
__future__r   Úcollections.abcr   r   r   r   Údecimalr   Úenumr   Útypingr	   r
   r   r   r   r   Úuuidr   Ztyping_extensionsr   r   Zpydantic.v1r   r   r   r   r   r   ÚImportErrorZpydanticÚpathlibr   r   rê   r|   r   rì   r   Útupler*   rÚ   r'   r5   rA   Z_AttachmentLikerB   ZExampleUploadWithAttachmentsr^   r_   rb   rv   rw   r~   ZExampleUpdateWithAttachmentsr�   r…   ZDatasetTransformationTyperˆ   rŠ   r”   r–   r—   r«   rÒ   rÙ   rÛ   rÞ   râ   rå   rç   rè   rô   r÷   rû   rý   rþ   r  r  r  r  r  r  r  Zupdate_forward_refsr  r  r  r!  r%  r&  r(  r-  r4  r=  r>  r?  rC  rE  rF  rG  rH  rI  rK  rM  rN  r%   r%   r%   r&   Ú<module>   s²    $&	&ÿ*ÿ	0X 		*	
6($+1	"	!