
    9i                    |   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mZ ddlmZ dd	lmZ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$ eeeedf   Z%ee&e'df   Z( G d de      Z)e&e'ee*e'e+f   e)e*e'e#f   f   f   Z,	 e G d de             Z- G d de      Z. G d de      Z/ee)e/e*e'e+f   e*e'e#f   f   Z0 G d de      Z1e1Z2 G d de1      Z3 G d de      Z4 G d de.      Z5 G d de.      Z6 G d  d!e      Z7 G d" d#e      Z8e8Z9 G d$ d%e'e      Z: G d& d'e      Z;e$d(   Z< G d) d*ed+,      Z= G d- d.e;      Z> G d/ d0e      Z?d1 Z@ G d2 d3e      ZA G d4 d5eA      ZB G d6 d7e'e      ZC G d8 d9ed+,      ZD G d: d;eA      ZE G d< d=e      ZF G d> d?eF      ZG G d@ dAeF      ZH G dB dCe      ZI G dD dEe      ZJ G dF dGed+,      ZK G dH dIed+,      ZL G dJ dKeJ      ZM G dL dMeJ      ZN G dN dOe      ZO G dP dQeO      ZPe G dR dSe             ZQ G dT dUed+,      ZR G dV dWe      ZS G dX dYeS      ZT G dZ d[ed+,      ZU G d\ d]e      ZVe5j                           G d^ d_e      ZX G d` dae      ZY G db dced+,      ZZ G dd deed+,      Z[ G df dge      Z\ G dh die      Z] G dj dke      Z^ G dl dme      Z_ G dn doe      Z` G dp dqe      Za G dr dse'e      Zb G dt dued+,      Zc G dv dwed+,      Zd G dx dyed+,      Ze G dz d{ed+,      Zf G d| d}e      Zg G d~ ded+,      Zh G d de      Zi G d de5      Zj G d de      Zk G d de      Zl G d de      Zm G d de      Zn G d de      Zo G d de      Zp G d deo      Zqy# e $ r dd
l!mZmZmZmZmZmZ Y dw xY w)zSchemas for the LangSmith API.    )annotations)Iterator)datetime	timedeltatimezone)Decimal)Enum)	AnnotatedAny
NamedTupleOptionalProtocolUnionruntime_checkable)UUID)NotRequired	TypedDict)	BaseModelFieldPrivateAttr
StrictBoolStrictFloat	StrictInt)Path)LiteralNc                  &    e Zd ZU dZded<   ded<   y)
Attachmenta  Annotated type that will be stored as an attachment if used.

    Examples:
        ```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__     [/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/langsmith/schemas.pyr   r   1   s      N
r)   r   c                  ,    e Zd ZdZdddZdd	dZd
dZy)BinaryIOLikez$Protocol for binary IO-like objects.c                     y)zRead function.Nr(   )selfsizes     r*   readzBinaryIOLike.readQ       r)   c                     y)zSeek function.Nr(   )r.   offsetwhences      r*   seekzBinaryIOLike.seekU   r1   r)   c                     y)zGet value function.Nr(   r.   s    r*   getvaluezBinaryIOLike.getvalueY   r1   r)   N))r/   intreturnbytes)r   )r3   r:   r4   r:   r;   r:   )r;   r<   )r#   r$   r%   r&   r0   r5   r8   r(   r)   r*   r,   r,   M   s    .r)   r,   c                      e Zd ZU dZded<    ed      Zded<    ed      Zded<    ed      Zded	<    G d
 d      Z	y)ExampleBasezExample base model.r   
dataset_idNdefaultOptional[dict[str, Any]]inputsoutputsmetadatac                      e Zd ZdZdZdZy)ExampleBase.Config#Configuration class for the schema.TN)r#   r$   r%   r&   frozenarbitrary_types_allowedr(   r)   r*   ConfigrG   f   s    1"&r)   rK   )
r#   r$   r%   r&   r'   r   rC   rD   rE   rK   r(   r)   r*   r>   r>   ^   sE    ',T':F$:(-d(;G%;).t)<H&<' 'r)   r>   c                  "    e Zd ZU ded<   ded<   y)_AttachmentDictr   r   r    r!   N)r#   r$   r%   r'   r(   r)   r*   rM   rM   m   s    N
r)   rM   c                       e Zd ZU dZded<    ed       Zded<    ed	      Zd
ed<    ed	      Zd
ed<    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<   dZded<    fdZ xZS )ExampleCreatez Example upload with attachments.Optional[UUID]idc                 H    t        j                  t        j                        S Nr   nowr   utcr(   r)   r*   <lambda>zExampleCreate.<lambda>{       hll9S r)   default_factoryr   
created_atNr@   rB   rC   rD   rE   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                $    t        |   di | yzInitialize from dict.Nr(   super__init__r.   r!   	__class__s     r*   rh   zExampleCreate.__init__        4 r)   )r#   r$   r%   r&   r'   r   r[   rC   rD   rE   r]   r^   r`   rb   rc   rh   __classcell__rj   s   @r*   rO   rO   w   s    * 1STJT',T':F$:(-d(;G%;).t)<H&<-1E*18<K5<#t#6: 3:$(M>(! !r)   rO   c                      e Zd ZU dZded<   y)ExampleUpsertWithAttachmentsz Example create with attachments.r   r?   Nr"   r(   r)   r*   ro   ro      s    *r)   ro   c                  0    e Zd ZU dZded<   ded<   ded<   y)	AttachmentInfozInfo for an attachment.r   presigned_urlr,   readerOptional[str]r   Nr"   r(   r)   r*   rq   rq      s    !r)   rq   c                  "    e Zd ZU dZded<    ed       Zded<    e ed      	      Zded
<    ed	      Z	ded<   dZ
ded<    ed	      Zded<   	  ed	      Zded<    ed	      Zded<   	 	 d	 	 	 	 	 	 	 d fdZedd       Zd Z xZS )ExamplezExample model.r   rQ   c                 L    t        j                  dt        j                        S )Nr   )tz)r   fromtimestampr   rV   r(   r)   r*   rW   zExample.<lambda>   s     6 6qX\\ J r)   rY   r   r[   z$00000000-0000-0000-0000-000000000000r@   r?   NOptional[datetime]modified_atrP   rc   z#Optional[dict[str, AttachmentInfo]]r^   rt   	_host_url
_tenant_idc                @    t        |   di | || _        || _        y)Initialize a Dataset object.Nr(   )rg   rh   r|   r}   )r.   r|   r}   kwargsrj   s       r*   rh   zExample.__init__   s#     	"6""$r)   c                    | j                   r^d| j                   d| j                   }| j                  r&| j                    dt	        | j                         | S | j                    | S y)URL of this run within the app.
/datasets/z/e//o/N)r|   r?   rQ   r}   r   )r.   paths     r*   urlzExample.url   sh     >>0DGG9=D..)S-A,B4&IInn%dV,,r)   c                n    | j                    d| j                   d| j                   d| j                   dS )5Return a string representation of the RunBase object.(id=z, dataset_id=z, link=''))rj   rQ   r?   r   r7   s    r*   __repr__zExample.__repr__   s8    ..!dggYmDOO;LHUYU]U]T^^`aar)   )NN)r|   rt   r}   rP   r   r   r;   Noner;   rt   )r#   r$   r%   r&   r'   r   r[   r   r?   r{   rc   r^   r   r|   r}   rh   propertyr   r   rl   rm   s   @r*   rv   rv      s    H JJ  T*P%QRJR&+D&9K#9$(M>(7<T7JK4J.*48I}8!,T!:J: $(%)	% 	% #	% 		%
 
	%  br)   rv   c                      e Zd ZU dZded<   y)ExampleSearchzExample returned via search.r   rQ   Nr"   r(   r)   r*   r   r      s
    &Hr)   r   c                  N    e Zd ZU dZ eed      Zded<    eed      Z	ded<   y	)
AttachmentsOperationsz%Operations to perform on attachments.z,Mapping of old attachment names to new names)rZ   descriptionzdict[str, str]renamez List of attachment names to keep	list[str]retainN)
r#   r$   r%   r&   r   dictr   r'   listr   r(   r)   r*   r   r      s5    /"*XFN  *LFI r)   r   c                       e Zd ZU dZded<   dZded<    ed      Zded	<    ed      Zded
<    ed      Z	ded<   dZ
ded<   dZded<   dZded<    G d d      Z fdZ xZS )ExampleUpdatez Example update with attachments.r   rQ   NrP   r?   r@   rB   rC   rD   rE   r\   r]   zOptional[Attachments]r^   zOptional[AttachmentsOperations]attachments_operationsc                      e Zd ZdZdZy)ExampleUpdate.ConfigrH   TNr#   r$   r%   r&   rI   r(   r)   r*   rK   r      
    1r)   rK   c                $    t        |   di | yre   rf   ri   s     r*   rh   zExampleUpdate.__init__   rk   r)   )r#   r$   r%   r&   r'   r?   r   rC   rD   rE   r]   r^   r   rK   rh   rl   rm   s   @r*   r   r      s{    *H!%J%',T':F$:(-d(;G%;).t)<H&<-1E*1)-K&->B;B 
! !r)   r   c                      e Zd ZdZdZdZdZy)DataTypezEnum for dataset data types.kvllmchatN)r#   r$   r%   r&   r   r   r   r(   r)   r*   r   r      s    &	B
CDr)   r   c                  L    e Zd ZU dZded<   dZded<   dZded<    G d	 d
      Zy)DatasetBasezDataset base model.r   nameNrt   r   zOptional[DataType]	data_typec                      e Zd ZdZdZy)DatasetBase.ConfigrH   TNr   r(   r)   r*   rK   r      r   r)   rK   )r#   r$   r%   r&   r'   r   r   rK   r(   r)   r*   r   r      s)    
I!%K%$(I!( r)   r   )remove_system_messagesconvert_to_openai_messageconvert_to_openai_toolremove_extra_fieldsextract_tools_from_runc                  &    e Zd ZU dZded<   ded<   y)DatasetTransformationz#Schema for dataset transformations.r   r   z%Union[DatasetTransformationType, str]transformation_typeNr"   r(   r)   r*   r   r     s    -
O>>r)   r   F)totalc                  8    e Zd ZU dZded<   ded<    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<   dZded<   dZded<   dZded<    ed      Zded<    ed      Zded<    ed      Zded<   	 	 	 d	 	 	 	 	 	 	 	 	 d fdZedd       Z xZS )DatasetzDataset ORM model.r   rQ   r   r[   Nr@   rz   r{   Optional[int]example_countsession_countlast_session_start_timerB   inputs_schemaoutputs_schemaz%Optional[list[DatasetTransformation]]transformationsrE   rt   r|   rP   r}   _public_pathc                    d|v r|j                  d      |d<   d|v r|j                  d      |d<   t        |   di | || _        || _        || _        y)r   inputs_schema_definitionr   outputs_schema_definitionr   Nr(   )poprg   rh   r|   r}   r   )r.   r|   r}   r   r   rj   s        r*   rh   zDataset.__init__%  sd     &/&,jj1K&LF?#&&0'-zz2M'NF#$"6""$(r)   c                   | j                   r~| j                  r| j                    | j                   S | j                  r1| j                    dt        | j                         d| j                   S | j                    d| j                   S y)r   r   r   N)r|   r   r}   r   rQ   r7   s    r*   r   zDataset.url8  s}     >>  ..)$*;*;)<==..)S-A,B*TWWIVVnn%Zy99r)   )NNN)
r|   rt   r}   rP   r   rt   r   r   r;   r   r   )r#   r$   r%   r&   r'   r   r{   r   r   r   r   r   r   rE   r   r|   r}   r   rh   r   r   rl   rm   s   @r*   r   r     s    H&+D&9K#9#'M='#'M='26/6.2M+2/3N,3=AO:A)-H&-*48I}8!,T!:J:"-d";L-; $(%)&*	) ) #) $	)
 ) 
)&  r)   r   c                  *    e Zd ZU dZdZded<   ded<   y)DatasetVersionz%Class representing a dataset version.Nra   tagsr   as_of)r#   r$   r%   r&   r   r'   r(   r)   r*   r   r   D  s    / $D
$Or)   r   c                 
    di iS )NrE   r(   r(   r)   r*   _default_extrar   K  s    r)   c                  l   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      Zded<   	 d	Z	ded<   	 d	Z
ded<   	 d	Zded<   	  ee      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      Zded<   	 ed$d       Zed%d       Zed&d        Zd! Z G d" d#      Zy	)'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   rQ   r   r   r   
start_timerun_typeNrz   end_timerY   Optional[dict]extrart   error
serializedOptional[list[dict]]eventsr   rC   rD   rP   reference_example_idparent_run_idra   r   z-Union[Attachments, dict[str, AttachmentInfo]]r^   c                `    | j                   i | _         | j                   j                  di       S zRetrieve the metadata (if any).rE   )r   
setdefaultr7   s    r*   rE   zRunBase.metadata  s,     ::DJzz$$Z44r)   c                8    | j                   j                  d      S )z"Retrieve the revision ID (if any).revision_id)rE   getr7   s    r*   r   zRunBase.revision_id  s     }}  //r)   c                j    | j                   y| j                   | j                  z
  j                         S )zLatency in seconds.N)r   r   total_secondsr7   s    r*   latencyzRunBase.latency  s-     == />>@@r)   c                n    | j                    d| j                   d| j                   d| j                   dS )r   r   z, name='z', run_type='r   )rj   rQ   r   r   r7   s    r*   r   zRunBase.__repr__  s3    ..!dggYhtyykt}}o]_``r)   c                      e Zd ZdZdZy)RunBase.ConfigrH   TN)r#   r$   r%   r&   rJ   r(   r)   r*   rK   r     s    1"&r)   rK   r;   dict[str, Any])r;   rP   )r;   Optional[float])r#   r$   r%   r&   r'   r   r   r   r   r   r   r   r   rC   rD   r   r   r   r^   r   rE   r   r   r   rK   r(   r)   r*   r   r   O  s+    	H(
I* M" $(H '-!.AE>A=E=;!%J%F#'F ' .FD.""G^"/+/./@$(M>(@ $D
$6AFBK> 
 5 5 0 0 A Aa' 'r)   r   c                  P    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"#      Zd$ed%<   	 dZd&ed'<   	  ed#      Zded(<   d3d4 fd)Zed5d*       Zed6d+       Z ed6d,       Z!ed7d-       Z"ed7d.       Z#ed8d/       Z$ed8d0       Z%ed9d1       Z&ed9d2       Z' xZ(S ):Runz$Run schema when loading from the DB.NrP   
session_idOptional[list[UUID]]child_run_idszOptional[list[Run]]
child_runsrB   feedback_statsrt   app_pathmanifest_idstatusr   prompt_tokenscompletion_tokenstotal_tokenszOptional[dict[str, int]]prompt_token_detailscompletion_token_detailsrz   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 r@   r   dotted_orderOptional[bool]
in_datasetr|   c                \   |j                  d      sd|j                  d      i|}|j                  dd      xs i }t        |   di |d|i || _        | j
                  j                         s;| j                  s.| j                  j                          | j                   | _        yyy)Initialize a Run object.r   rQ   rC   Nr(   )r   r   rg   rh   r|   r   stripr   r   	isoformatrQ   )r.   r|   r   rC   rj   s       r*   rh   zRun.__init__  s    zz*% &**T"2=f=FHd+1r161&1"  &&(1C1C#'??#<#<#>"?y ID 2D(r)   c                h    | j                   r&| j                  r| j                    | j                   S y)r   N)r|   r   r7   s    r*   r   zRun.url  s,     >>dmmnn%dmm_55r)   c                    | j                   S )zAlias for prompt_tokens.)r   r7   s    r*   input_tokenszRun.input_tokens  s     !!!r)   c                    | j                   S )zAlias for completion_tokens.)r   r7   s    r*   output_tokenszRun.output_tokens  s     %%%r)   c                    | j                   S )zAlias for prompt_cost.)r   r7   s    r*   
input_costzRun.input_cost  s     r)   c                    | j                   S )zAlias for completion_cost.)r   r7   s    r*   output_costzRun.output_cost  s     ###r)   c                    | j                   S )zAlias for prompt_token_details.)r   r7   s    r*   input_token_detailszRun.input_token_details  s     (((r)   c                    | j                   S )zAlias for output_token_details.)r   r7   s    r*   output_token_detailszRun.output_token_details  s     ,,,r)   c                    | j                   S )zAlias for prompt_cost_details.)r   r7   s    r*   input_cost_detailszRun.input_cost_details   s     '''r)   c                    | j                   S )z"Alias for completion_cost_details.)r   r7   s    r*   output_cost_detailszRun.output_cost_details%  s     +++r)   rS   r|   rt   r   r   r;   r   r   )r;   z
int | None)r;   zDecimal | None)r;   zdict[str, int] | None)r;   zdict[str, Decimal] | None))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   r|   rh   r   r   r  r
  r  r  r  r  r  r  rl   rm   s   @r*   r   r     s   .!%J%-*.M'.4&*J#*M/3N,3&"Hm"7"&K&: FM .#'M='/'+}+/"&L-&15929 :>6= ,0(/-$(J!(M%)K")G)-O&-C8<5< =A9@ ,0N(/!NCb)L#)
 "&J%+*48I}8J   " " & &     $ $ ) ) - - ( ( , ,r)   r   c                  ,    e Zd ZdZdZdZdZdZdZdZ	dZ
y	)
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(    ?DE
CIIFFr)   r  c                     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$<   y%)&RunLikeDictz&Run-like dictionary, for type-hinting.r   r   r  r   r   r   r   rC   rD   rz   r   r   rt   r   r   rP   r   r   r   r   ra   r   inputs_s3_urlsoutputs_s3_urlsrQ   r   session_namer   input_attachmentsoutput_attachmentsr   r   r   Attachmentsr^   Nr"   r(   r)   r*   r!  r!  7  s    0
I  !!  
""##((%%&&Nr)   r!  c                  0    e Zd ZU dZdZded<   	 dZded<   y)RunWithAnnotationQueueInfoz&Run schema with annotation queue info.Nrz   last_reviewed_timeadded_at)r#   r$   r%   r&   r*  r'   r+  r(   r)   r*   r)  r)  T  s"    0-1*1.#'H '3r)   r)  c                  Z    e Zd ZU dZded<   	  ee      Zded<   	 dZded	<   	 dZ	d
ed<   y)FeedbackSourceBasezBase class for feedback sources.

    This represents whether feedback is submitted from the API, model, human labeler,
        etc.
    r   typerY   rB   rE   NzOptional[Union[UUID, str]]user_idrt   	user_name)
r#   r$   r%   r&   r'   r   r   rE   r/  r0  r(   r)   r*   r-  r-  ]  s?     I*).t)DH&D6*.G'.:#I}#<r)   r-  c                       e Zd ZU dZdZded<   y)APIFeedbackSourcezAPI feedback source.apizLiteral['api']r.  Nr#   r$   r%   r&   r.  r'   r(   r)   r*   r2  r2  n  s     D. r)   r2  c                       e Zd ZU dZdZded<   y)ModelFeedbackSourcezModel feedback source.modelzLiteral['model']r.  Nr4  r(   r)   r*   r6  r6  t  s     $D
$r)   r6  c                      e Zd ZdZdZ	 dZy)FeedbackSourceTypezFeedback source type.r3  r7  N)r#   r$   r%   r&   APIMODELr(   r)   r*   r9  r9  z  s    
C2E"r)   r9  c                     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      Zy)FeedbackBasezFeedback schema.r   rQ   Nrz   r[   r{   rP   run_idr   r   key
SCORE_TYPEscore
VALUE_TYPEvaluert   commentzUnion[str, dict, None]
correctionOptional[FeedbackSourceBase]feedback_sourcer   comparative_experiment_idfeedback_group_idr   r   c                      e Zd ZdZdZy)FeedbackBase.ConfigrH   TNr   r(   r)   r*   rK   rK    r   r)   rK   )r#   r$   r%   r&   r'   r[   r{   rA  rC  rD  rE  rG  r   rH  rI  r   rK   r(   r)   r*   r=  r=    s    H(%)J"),&*K#*2<>	HAE:+E:Q!G]!2)-J&-!48O18%!%J%T04~4X(,~,1 !E> ' r)   r=  c                  (    e Zd ZU dZded<   	 ded<   y)FeedbackCategoryz+Specific value and label pair for feedback.floatrC  rt   labelNr"   r(   r)   r*   rM  rM    s    5LCNr)   rM  c                  @    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   y	)
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*   rQ  rQ    s,    D
::	4	400@r)   rQ  c                  <    e Zd ZU dZded<   	 dZded<   	 dZded<   y)	FeedbackCreatez"Schema used for creating feedback.r-  rG  NzOptional[FeedbackConfig]feedback_configr   r   )r#   r$   r%   r&   r'   rW  r   r(   r)   r*   rV  rV    s&    ,''%04O-4% E> r)   rV  c                  B    e Zd ZU dZded<   ded<   	 ded<   	 dZded	<   y)
FeedbackzSchema for getting feedback.r   rQ   r   r[   r{   NrF  rG  )r#   r$   r%   r&   r'   rG  r(   r)   r*   rY  rY    s*    &H,248O182r)   rY  c                       e Zd ZU dZded<   	  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<   	 ded<   	 ded<   	  ed      Zded<   dd fdZedd       Zedd       Zedd       Z xZS )TracerSessionzbTracerSession schema for the API.

    Sessions are also referred to as "Projects" in the UI.
    r   rQ   c                 H    t        j                  t        j                        S rS   rT   r(   r)   r*   rW   zTracerSession.<lambda>  rX   r)   rY   r   r   Nrz   r   rt   r   r   rB   r   	tenant_idrP   reference_dataset_idr@   r|   c                    t        |   di | || _        | j                  j                  0| j                  j                  t        j                        | _        yy)r  N)tzinfor(   )rg   rh   r|   r   r`  replacer   rV   )r.   r|   r   rj   s      r*   rh   zTracerSession.__init__  sL    "6""??!!)"oo55X\\5JDO *r)   c                l    | j                   r(| j                    d| j                   d| j                   S y)r   r   /projects/p/N)r|   r]  rQ   r7   s    r*   r   zTracerSession.url  s3     >>nn%S(8TWWINNr)   c                X    | j                   d| j                   vri S | j                   d   S r   r   r7   s    r*   rE   zTracerSession.metadata  -     ::4::!=Izz*%%r)   c                X    | j                   d| j                   vrg S | j                   d   S )zRetrieve the tags (if any).r   re  r7   s    r*   r   zTracerSession.tags  s-     ::tzz!9Izz&!!r)   rS   r  r   r   )r;   r   )r#   r$   r%   r&   r'   r   r   r   r   r   r   r   r|   rh   r   r   rE   r   rl   rm   s   @r*   r[  r[    s    
 	H  1STJT+#'H ')!%K%)D-"&*E#*)O0((J*48I}8K   & & " "r)   r[  c                      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<   y)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   rz   last_run_start_timerB   r   session_feedback_statsOptional[list[dict[str, Any]]]
run_facetsr   r   r   r   first_token_p50first_token_p99r   
error_rateNr"   r(   r)   r*   ri  ri    s    
 ,$$?$$6=  D$$H++8,,)441..-!!M""G&&C((G((>)r)   ri  c                  <    e Zd ZU dZded<   	 ded<   	 edd       Zy)	BaseMessageLikez7A protocol representing objects similar to BaseMessage.r   contentzdict[Any, Any]additional_kwargsc                     y)z,Type of the Message, used for serialization.Nr(   r7   s    r*   r.  zBaseMessageLike.typeA  s    r)   Nr;   r   )r#   r$   r%   r&   r'   r   r.  r(   r)   r*   rv  rv  8  s(    AL%%%C; ;r)   rv  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)DatasetShareSchemaz*Represents the schema for a dataset share.r   r?   share_tokenr   r   Nr"   r(   r)   r*   r|  r|  F  s    4 ,	H(r)   r|  c                      e Zd ZU dZded<   	 ded<   	 dZded<   	  ed	 
      Zded<   	  ed 
      Zded<   	 ded<   y)AnnotationQueuezRepresents an annotation queue.r   rQ   r   r   Nrt   r   c                 H    t        j                  t        j                        S rS   rT   r(   r)   r*   rW   zAnnotationQueue.<lambda>Z  rX   r)   rY   r   r[   c                 H    t        j                  t        j                        S rS   rT   r(   r)   r*   rW   zAnnotationQueue.<lambda>\  rX   r)   
updated_atr]  )	r#   r$   r%   r&   r'   r   r   r[   r  r(   r)   r*   r  r  Q  sP    )H8
I+!%K%: 1STJT> 1STJTCODr)   r  c                       e Zd ZU dZdZded<   y)AnnotationQueueWithDetailsz,Represents an annotation queue with details.Nrt   rubric_instructions)r#   r$   r%   r&   r  r'   r(   r)   r*   r  r  b  s    6)--;r)   r  c                  X    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
<   y)BatchIngestConfigz"Configuration for batch ingestion.r_   use_multipart_endpointr:   scale_up_qsize_triggerscale_up_nthreads_limitscale_down_nempty_trigger
size_limitr   size_limit_bytesNr"   r(   r)   r*   r  r  i  s:    ,  D<  7""AO/##8r)   r  c                  P    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<   y)LangSmithInfoz'Information about the LangSmith server.r   r   versionNrz   license_expiration_timezOptional[BatchIngestConfig]batch_ingest_configrB   instance_flags)	r#   r$   r%   r&   r  r'   r  r  r  r(   r)   r*   r  r  z  s;    1GS.26/6+7;4;/3N,3r)   r  c                  D    e Zd ZU dZded<   	 ded<   	 ded<   	 dZded	<   y)
LangSmithSettingsz"Settings for the LangSmith tenant.r   rQ   display_namer   r[   Nrt   tenant_handle)r#   r$   r%   r&   r'   r  r(   r)   r*   r  r    s)    ,G)*#'M='r)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)	FeedbackIngestTokenz2Represents the schema for a feedback ingest token.r   rQ   r   r   r   
expires_atNr"   r(   r)   r*   r  r    s    <H.	H3+r)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)	RunEventzRun event schema.r   r   zUnion[datetime, str]timerB   r   Nr"   r(   r)   r*   r  r    s    
I
$$,r)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)TimeDeltaInputzTimedelta input schema.r:   dayshoursminutesNr"   r(   r)   r*   r  r    s    !
IJLr)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)DatasetDiffInfoz;Represents the difference information between two datasets.z
list[UUID]examples_modifiedexamples_addedexamples_removedNr"   r(   r)   r*   r  r    s     E!!=:  <r)   r  c                      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       Zy)ComparativeExperimentzRepresents a comparative experiment.

    This information summarizes evaluation results comparing
    two or more models on a given dataset.
    r   rQ   Nrt   r   r   r]  r   r[   r{   r^  rB   r   r   experiments_infor   c                X    | j                   d| j                   vri S | j                   d   S r   re  r7   s    r*   rE   zComparativeExperiment.metadata  rf  r)   r   )r#   r$   r%   r&   r'   r   r   r   r  r   r   rE   r(   r)   r*   r  r    s     	H?D-:!%K%@OGDJJ&*E#*?-1*1\/3N,3P& &r)   r  c                  L    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   	 ded	<   y
)PromptCommitz$Represents a Prompt with a manifest.r   ownerrepocommit_hashr   manifestz
list[dict]examplesNr"   r(   r)   r*   r  r    s0    .J0
I!(%r)   r  c                      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      Zded<   	 dZded<   	 dZded<   	 dZded<   y)ListedPromptCommitz;Represents a listed prompt commit with associated metadata.r   rQ   r   r  r  NrP   r   repo_id	parent_idrt   r  rz   r[   r  rY   r   example_run_idsr   r   num_downloads	num_viewsparent_commit_hash)r#   r$   r%   r&   r'   r   r  r  r  r[   r  r   r   r  r  r  r  r(   r)   r*   r  r    s    EH6J)
I3"&K&O"G^"5 $I~$8!%K%*%)J")=%)J")B,1$,GO)GH#$M=$> I} :(,,1r)   r  c                  8   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<   y) Promptz"Represents a Prompt with metadata.r   repo_handleNrt   r   readmerQ   r]  r   r[   r  r_   	is_publicis_archivedr   r   original_repo_idupstream_repo_idr  	full_namer:   	num_likesr  r  r   liked_by_auth_userlast_commit_hashnum_commitsoriginal_repo_full_nameupstream_repo_full_name)r#   r$   r%   r&   r'   r   r  r  r  r  r  r  r  r(   r)   r*   r  r    s    ,!!%K%( FM #GN,*-O')
O.&*m*3&*m*30N<N"N)--@&*m*& -1]1:-1]1:r)   r  c                  (    e Zd ZU dZded<   	 ded<   y)ListPromptsResponsez A list of prompts with metadata.zlist[Prompt]reposr:   r   Nr"   r(   r)   r*   r  r  P  s    *J&r)   r  c                  &    e Zd ZdZdZ	 dZ	 dZ	 dZy)PromptSortFieldz$Enum for sorting fields for prompts.r  r  r  r  N)r#   r$   r%   r&   r  r  r  r  r(   r)   r*   r  r  Y  s%    .#MIJIr)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)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  f  s(    
 J Or)   r  c                  (    e Zd ZU dZded<   	 ded<   y)OutputTokenDetailszBreakdown 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  r  {  s    
 JNr)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)InputCostDetailszvBreakdown of input token costs.

    Does *not* need to sum to full input cost. Does *not* need to have all keys.
    rN  r  r  r  Nr"   r(   r)   r*   r  r    s)    
 L% r)   r  c                  (    e Zd ZU dZded<   	 ded<   y)OutputCostDetailszxBreakdown of output token costs.

    Does *not* need to sum to full output cost. Does *not* need to have all keys.
    rN  r  r  Nr"   r(   r)   r*   r  r    s    
 L&r)   r  c                      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<   y)UsageMetadatazUsage 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  r    sk    
 JPA77 :9 #"'##(""'55/770r)   r  c                      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<   y)ExtractedUsageMetadatazUsage 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  r  r  rN  r  r  r   r  r  r  r  Nr"   r(   r)   r*   r  r    sc     33****,,+'('((/**0r)   r  c                  (    e Zd ZU dZded<   	 ded<   y)UpsertExamplesResponsezCResponse object returned from the upsert_examples_multipart method.r:   countr   example_idsNr"   r(   r)   r*   r  r    s    MJ45r)   r  c                  .    e Zd ZU dZ ee      Zded<   y)ExampleWithRunszExample with runs.rY   z	list[Run]runsN)r#   r$   r%   r&   r   r   r  r'   r(   r)   r*   r  r    s    D1D)1"r)   r  c                      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<   y)ExperimentRunStatsz!Run statistics for an experiment.r   rj  rk  rl  rm  r   r   r   rz   rn  rp  rq  r   r   r   r   rr  rs  r   rt  Nr"   r(   r)   r*   r  r     s    +,$$?$$6=  D$$H++8..-!!M""G&&C((G((>)r)   r  c                  4    e Zd ZU dZded<   	 ded<   	 ded<   y)	ExperimentResultszResults 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   r  	run_statszIterator[ExampleWithRuns]examples_with_runsNr"   r(   r)   r*   r  r  !  s!     1!!611r)   r  c                  v    e Zd ZU dZded<   ded<   ded<   dZded	<   ded
<   ded<   ded<   edd       ZddZy)InsightsReportzHAn Insights Report created by the Insights Agent over a tracing project.z
UUID | strrQ   r   r   r   Nz
str | Noner   
project_idhost_urlr]  c           	         | j                    dt        | j                         dt        | j                         dt        | j                         S )z1URL to view this Insights Report in LangSmith UI.r   rc  z?tab=4&clusterJobId=)r  r   r]  r  rQ   r7   s    r*   linkzInsightsReport.link:  sH     --C$7#8SEYDZZnorswszszo{n|}}r)   c                <    d| j                    d| j                   dS )Nz	<a href="z2", target="_blank" rel="noopener">InsightsReport('z')</a>)r  r   r7   s    r*   _repr_html_zInsightsReport._repr_html_?  s%    499+%XY]YbYbXccjkkr)   rz  )	r#   r$   r%   r&   r'   r   r   r  r  r(   r)   r*   r  r  /  sI    RN
IKE:M~ ~lr)   r  c                  0    e Zd ZU dZded<   ded<   ded<   y)	FeedbackFormulaWeightedVariablezBA feedback key and weight used when calculating feedback formulas.zLiteral['weighted_key']	part_typerN  weightz#Annotated[str, Field(min_length=1)]r?  Nr"   r(   r)   r*   r  r  C  s    L&&M	,,r)   r  c                  b    e Zd ZU dZdZded<   dZded<   ded<   ded	<    ed
dd      Zded<   y)FeedbackFormulaCreatez,Schema used for creating a feedback formula.NrP   r?   r   r   feedback_keyLiteral['sum', 'avg']aggregation_type.   2   	min_items	max_items%list[FeedbackFormulaWeightedVariable]formula_parts)	r#   r$   r%   r&   r?   r'   r   r   r  r(   r)   r*   r  r  K  s>    6!%J%!%J%++;@qB<M8 r)   r  c                  F    e Zd ZU dZded<   ded<    eddd	      Zd
ed<   y)FeedbackFormulaUpdatez,Schema used for updating a feedback formula.r   r  r  r  .r  r  r  r  r  N)r#   r$   r%   r&   r'   r   r  r(   r)   r*   r  r  W  s*    6++;@qB<M8 r)   r  c                  0    e Zd ZU dZded<   ded<   ded<   y)FeedbackFormulaz%Schema for getting feedback formulas.r   rQ   r   r[   r{   Nr"   r(   r)   r*   r  r  a  s    /Hr)   r  )rr&   
__future__r   collections.abcr   r   r   r   decimalr   enumr	   typingr
   r   r   r   r   r   r   uuidr   typing_extensionsr   r   pydantic.v1r   r   r   r   r   r   ImportErrorpydanticpathlibr   r   r@  r   r   rB  r   tupler<   r'  r,   r>   rM   _AttachmentLikerO   ExampleUploadWithAttachmentsro   rq   rv   r   r   r   ExampleUpdateWithAttachmentsr   r   DatasetTransformationTyper   r   r   r   r   r   r  r!  r)  r-  r2  r6  r9  r=  rM  rQ  rV  rY  r[  ri  rv  r|  r  r  r  r  update_forward_refsr  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*   <module>r     sz   $ " $ 2 2      4 $  %:y+t;<
4d?#
 * 3eCJ/U39=MMNNO 8   ') 'i 
 sEz!2E#t)4DD
!I !&  - = Y 'bk 'bTK I !I !,  - sD 
) 
 $ ?IU ?-k -`Y W'i W't,' ,D	#t 	)5 :4 4= ="!* !%, %# #'9 'TOy O@Ye @!\ !	3| 	33"I 3"l%*- %*P 
;h 
; 
;)% )Ei E"< <9	 9"	4I 	4    	(	 	(,) ,-y -Ye =i =!&I !&H 9  (2 (2V.;Y .;b') '
c4 
	 *%  y *	  1I 1D1Ye 1:6Y 6#g #* *B2	 2lY l(-i -	I 	I + E*    s   N" "N;:N;