
    =Kivo                    p   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKJrJrJrJrJr  SSKJrJr  SSKJrJrJrJrJrJrJ r J!r!  SSK"J#r$  SSK%r%SSK&r&SSK'J(r(  SS	K)J*r*  SS
K+J,r-  \R\                  " \/5      r0 " S S\15      r2 " S S\25      r3 " S S\25      r4 " S S\25      r5 " S S\25      r6 " S S\25      r7 " S S\25      r8 " S S\25      r9 " S S\25      r: " S S\25      r; " S S \<5      r= " S! S"\=5      r>SZS[S# jjr?S\S$ jr@S]S% jrA    S^S& jrBS_S' jrC\R                  " S(S)9S`S* j5       rESaS+ jrFSbS, jrGScS- jrHSdS. jrISeS/ jrJSfS0 jrKSgS1 jrL\R                  " S(S)9ShS2 j5       rMSiS3 jrNSjS4 jrOSkS5 jrP\!S6S7.       SlS8 jj5       rQ\! SZS6S7.       SmS9 jjj5       rQ\R                  " S:S)9 SZS6S7.       SnS; jjj5       rQ\R                  " S(S)9SoSpS< jj5       rR " S= S>\R                  5      rT " S? S@\R                  5      rU " SA SB\*5      rV\R                  " 5       rX\R                        SqSC j5       rZSrSD jr[SSSE.       SsSF jjr\\R                    St       SuSG jj5       r]\R                    St       SvSH jj5       r^SwSI jr_\" SJ5      r` Sx         SySK jjraSzSL jrbS{SM jrcS|SN jrd\(" SO5      re " SP SQ\5      rfS}SR jrgS~SS jrhSST jriSSU jrj\R                  " SVS)9SSW j5       rkSSSX jjrlSSY jrmg)zGeneric utility functions.    )annotationsN)	GeneratorIterableIteratorMappingSequence)FutureThreadPoolExecutor)AnyCallableLiteralOptionalTypeVarUnioncastoverload)parse)	ParamSpec)Retry)schemasc                      \ rS rSrSrSrg)LangSmithError*   z=An error occurred while communicating with the LangSmith API. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       Q/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langsmith/utils.pyr   r   *   s    Gr"   r   c                      \ rS rSrSrSrg)LangSmithAPIError.   z9Internal server error while communicating with LangSmith.r   Nr   r   r"   r#   r%   r%   .   s    Cr"   r%   c                      \ rS rSrSrSrg)LangSmithRequestTimeout2   z*Client took too long to send request body.r   Nr   r   r"   r#   r(   r(   2   s    4r"   r(   c                      \ rS rSrSrSrg)LangSmithUserError6   zAUser error caused an exception when communicating with LangSmith.r   Nr   r   r"   r#   r+   r+   6   s    Kr"   r+   c                      \ rS rSrSrSrg)LangSmithRateLimitError:   z7You have exceeded the rate limit for the LangSmith API.r   Nr   r   r"   r#   r.   r.   :   s    Ar"   r.   c                      \ rS rSrSrSrg)LangSmithAuthError>   z-Couldn't authenticate with the LangSmith API.r   Nr   r   r"   r#   r1   r1   >   s    7r"   r1   c                      \ rS rSrSrSrg)LangSmithNotFoundErrorB   z%Couldn't find the requested resource.r   Nr   r   r"   r#   r4   r4   B   s    /r"   r4   c                      \ rS rSrSrSrg)LangSmithConflictErrorF   zThe resource already exists.r   Nr   r   r"   r#   r7   r7   F       &r"   r7   c                      \ rS rSrSrSrg)LangSmithConnectionErrorJ   z&Couldn't connect to the LangSmith API.r   Nr   r   r"   r#   r;   r;   J       0r"   r;   c                  @   ^  \ rS rSrSr        SU 4S jjrSrU =r$ )LangSmithExceptionGroupN   z%Port of ExceptionGroup for Py < 3.11.c               2   > [         TU ]  " U0 UD6  Xl        g)zInitialize.N)super__init__
exceptions)selfrD   argskwargs	__class__s       r#   rC    LangSmithExceptionGroup.__init__Q   s     	$)&)$r"   )rD   )rF   r   rD   zSequence[Exception]rG   r   returnNone)r   r   r   r   r    rC   r!   __classcell__rH   s   @r#   r?   r?   N   s0    /%%&9%EH%	% %r"   r?   c                      \ rS rSrSrSrg)LangSmithWarning\   zBase class for warnings.r   Nr   r   r"   r#   rO   rO   \   s    "r"   rO   c                      \ rS rSrSrSrg)LangSmithMissingAPIKeyWarning`   zWarning for missing API key.r   Nr   r   r"   r#   rR   rR   `   r9   r"   rR   c                    SSK Js  Jn  SSKJnJn  U =(       d    U" 5       nUS   b  US   $ U" 5       (       a  gUR                  b  UR                  $ [        S[        SSS	9S	9nUS
:H  $ )z"Return True if tracing is enabled.r   N)get_current_run_treeget_tracing_contextenabledT
TRACING_V2TRACING defaulttrue)langsmith._internal._context	_internal_contextlangsmith.run_helpersrU   rV   _GLOBAL_TRACING_ENABLEDget_env_var)ctxr`   rU   rV   tc
var_results         r#   tracing_is_enabledrg   d   st     43O		%#%B
 
)} )}''3///\;yRT3UVJr"   c                     [        SSS9S:H  $ )z"Return True if testing is enabled.TEST_TRACKINGrZ   r[   falserc   r   r"   r#   test_tracking_is_disabledrl   |   s    3w>>r"   c                    ^  SU 4S jjnU$ )z7Validate specified keyword args are mutually exclusive.c                N   >^  [         R                  " T 5      SUU 4S jj5       nU$ )Nc                 ^  >^ T Vs/ s H  n[        U4S jU 5       5      PM     nn[        U5       VVs/ s H  u  pEUS:w  d  M  UPM     nnnU(       aA  U Vs/ s H  nSR                  TU   5      PM     nn[        SSR                  U5       35      eT	" U 0 TD6$ s  snf s  snnf s  snf )z3Validate exactly one arg in each group is not None.c              3  P   >#    U  H  nTR                  U5      c  M  Sv   M     g 7f)N   )get).0argrG   s     r#   	<genexpr>?xor_args.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>   s     J#fjjoAAs   &	&rq   z, zFExactly one argument in each of the following groups must be defined: )sum	enumeratejoin
ValueError)
rF   rG   	arg_groupcountsicountinvalid_groupsinvalid_group_names
arg_groupsfuncs
    `      r#   wrapper,xor_args.<locals>.decorator.<locals>.wrapper   s    
 ",!+I JJJ!+   1:&0AP0AHAUaZa0ANPIW&XAtyyA'?#&X 		"5679 
 ((( Q&Xs   BB$B$B*)rF   r   rG   r   rJ   r   )	functoolswraps)r   r   r   s   ` r#   	decoratorxor_args.<locals>.decorator   s%    			) 
	)  r"   )r   r   rJ   r   r   )r   r   s   ` r#   xor_argsr      s    ( r"   c                T    U R                  5         g! [        R                   a0  n[        R                  " [        U5      U R                  5      UeSnAf[
        R                   a>  n[
        R                  " [        U5       SU R                   3U R                  U S9UeSnAff = f)z&Raise an error with the response text.Nz: )requestresponse)raise_for_statusrequests	HTTPErrorstrtexthttpxHTTPStatusErrorr   )r   es     r#   raise_for_status_with_textr      s    	!!# ?  Q7Q>   ##1vhb($$
 		s     B'+AB')9B""B'c                \    [        U [        R                  5      (       a  U R                  $ U $ )zGet the value of a string enum.)
isinstanceenumEnumvalue)enus    r#   get_enum_valuer      s"    #tyy!!yyJr"   rq   )maxsizec                .    [         R                  X5        g)z4Log a message at the specified level, but only once.N)_LOGGERlog)levelmessages     r#   log_oncer      s     KKr"   c                    U (       d  [        S5      eSU ;   a;  SU ;  a  [        SU  S35      eU S   S   R                  SS5      R                  5       $ S	U ;  a  [        S
U  S35      eU S	   $ )NMessage is empty.lcid*Unexpected format for serialized message: z Message does not have an id.MessagerZ   type&Unexpected format for stored message: z Message does not have a type.)rz   replacelowerr   s    r#   _get_message_typer      s    ,--ww<WI/0  t}R ((B7==?? 8	01  vr"   c                    U (       d  [        S5      eSU ;   a  SU ;  a  [        SU  S35      eU S   $ SU ;  a  [        SU  S35      eU S   $ )	Nr   r   rG   r   z Message does not have kwargs.datar   z Message does not have data.)rz   r   s    r#   _get_message_fieldsr      sy    ,--w7"<WI01  x   8	./  vr"   c                6    [        U 5      n[        U 5      nXS.$ )z&Extract message from a message object.r   r   )r   r   )r   message_typemessage_datas      r#   _convert_messager      s    $W-L&w/L 77r"   c                    SU ;   a  U S    Vs/ s H  n[        U5      PM     sn$ SU ;   a  [        U S   5      /$ [        SU  S35      es  snf )zExtract messages from the given inputs dictionary.

Args:
    inputs: The inputs dictionary.

Returns:
    A list of dictionaries representing the extracted messages.

Raises:
    ValueError: If no message(s) are found in the inputs dictionary.
messagesr   z-Could not find message(s) in run with inputs .)r   rz   )inputsr   s     r#   get_messages_from_inputsr      sd     V9?
9KL9Kg )9KLLF 	!2344
DVHAN
OO Ms   A
c                    SU ;  a  [        SU  S35      eU S   n[        U5      S:w  a  [        S[        U5       SU S35      eUS   nSU;  a  [        S	U S
35      e[        US   5      $ )zRetrieve the message generation from the given outputs.

Args:
    outputs: The outputs dictionary.

Returns:
    The message generation.

Raises:
    ValueError: If no generations are found or if multiple generations are present.
generations,No generations found in in run with output: r   rq   z3Chat examples expect exactly one generation. Found z generations: r   r   z"Unexpected format for generation: z%. Generation does not have a message.)rz   lenr   outputsr   first_generations      r#   #get_message_generation_from_outputsr      s     G#GyPQRSS-(K
;1+&'~k]!E
 	
 #1~((01A0B C3 3
 	
 ,Y788r"   c                    SU ;   a  U S   $ SU ;   a(  U S   n[        U5      S:X  a  US   $ [        SU  S35      e[        SU  S35      e)	zRetrieve the prompt from the given inputs.

Args:
    inputs: The inputs dictionary.

Returns:
    str: The prompt.

Raises:
    ValueError: If the prompt is not found or if multiple prompts are present.
promptpromptsrq   r   z$Multiple prompts in run with inputs z!. Please create example manually.z)Could not find prompt in run with inputs r   )r   rz   )r   r   s     r#   get_prompt_from_inputsr     st     6hF#w<11:26( ;/ /
 	
 @J
KKr"   c                    SU ;  a  [        SU  S35      eU S   n[        U5      S:w  a  [        SU 35      eUS   nSU;  a  [        SU 35      eUS   $ )	z(Get the LLM generation from the outputs.r   r   r   rq   zMultiple generations in run: r   r   zNo text in generation: )rz   r   r   s      r#   get_llm_generation_from_outputsr   .  s}    G#GyPQRSS-(K
;18FGG"1~%%23C2DEFFF##r"   c                 v    [         R                  " / SQ[         R                  [         R                  S9  SS/$ ! [         R                  [        4 ad     [         R                  " SS/[         R                  [         R                  S9  S/s $ ! [         R                  [        4 a    [        S5      ef = ff = f)z7Get the correct docker compose command for this system.)dockercompose	--version)stdoutstderrr   r   zdocker-composer   zNeither 'docker compose' nor 'docker-compose' commands are available. Please install the Docker server following the instructions for your operating system at https://docs.docker.com/engine/install/)
subprocess
check_callDEVNULLCalledProcessErrorFileNotFoundErrorrz   r   r"   r#   get_docker_compose_commandr   ;  s    .%%%%	

 )$$))+<= 	!!!;/!))!))
 %%%--/@A 	E 	s!   7: B86BB8&B44B8c                    U R                   SU R                  0S.nU R                  (       a-  [        U R                  5      S:  a  0 U R                  EUS   S'   U$ )z*Convert a LangChain message to an example.contentr   r   r   additional_kwargs)r   r   r   r   )r   	converteds     r#   convert_langchain_messager   V  s\     GOO,!I
   S)B)B%Ca%G1NG4M4M1N	&-.r"   c           
         [        [        [        U SS5      [        5      [        [        U SS5      [        5      [        U S5      =(       a    [        [        U S5      [        5      /5      $ )zCheck if the given object is similar to `BaseMessage`.

Args:
    obj: The object to check.

Returns:
    bool: True if the object is similar to `BaseMessage`, `False` otherwise.
r   Nr   r   )allr   getattrr   dicthasattr)objs    r#   is_base_message_liker   b  sZ     wsIt4c:ws$7>EC JZV0Dc%J	
 r"   c                2    U c  g[        [        U 5      5      $ )z2Check if the given environment variable is truish.F)	is_truishrc   )r   s    r#   is_env_var_truishr   t  s    }['((r"   )	LANGSMITH	LANGCHAIN)
namespacesc                   g Nr   namer\   r   s      r#   rc   rc   {  s     r"   c                   g r   r   r   s      r#   rc   rc     s     r"   d   c                   U Vs/ s H	  o3 SU  3PM     nnU H?  n [         R                  R                  U 5      nUc  M'  UR                  5       S:w  d  M=  Us  $    U$ s  snf )a  Retrieve an environment variable from a list of namespaces.

Args:
    name: The name of the environment variable.
    default: The default value to return if the environment variable is not found.
    namespaces: A tuple of namespaces to search for the environment variable.

        Defaults to `('LANGSMITH', 'LANGCHAINs')`.

Returns:
    The value of the environment variable if found, otherwise the default value.
_rZ   )osenvironrr   strip)r   r\   r   	namespacenamesr   s         r#   rc   rc     sb    & 5??Jy{!D6"JE?

t$"!4L  N @s   Ac                t    [         R                  R                  S[        S[        SU (       a  SOSS9S95      $ )z,Get the project name for a LangSmith tracer.HOSTED_LANGSERVE_PROJECT_NAMEPROJECTSESSIONr\   Nr[   )r   r   rr   rc   )return_default_values    r#   get_tracer_projectr     s=     ::>>
 	(  0D9$		
 r"   c                  >   ^  \ rS rSrSrSSU 4S jjjrSS jrSrU =r$ )	FilterPoolFullWarningi  zGFilter `urllib3` warnings logged when the connection pool isn't reused.c                0   > [         TU ]  U5        X l        g)zInitialize the `FilterPoolFullWarning` filter.

Args:
    name: The name of the filter. Defaults to `""`.
    host: The host to filter. Defaults to `""`.
N)rB   rC   _host)rE   r   hostrH   s      r#   rC   FilterPoolFullWarning.__init__  s     	
r"   c                N    UR                  5       nSU;  a  gU R                  U;  $ )zJurllib3.connectionpool:Connection pool is full, discarding connection: ...z.Connection pool is full, discarding connectionT)
getMessager   rE   recordmsgs      r#   filterFilterPoolFullWarning.filter  s*    !;3Fzz$$r"   )r   )rZ   rZ   )r   r   r  r   rJ   rK   rJ   bool)	r   r   r   r   r    rC   r  r!   rL   rM   s   @r#   r   r     s    Q % %r"   r   c                  "    \ rS rSrSrSS jrSrg)FilterLangSmithRetryi  z!Filter for retries from this lib.c                ,    UR                  5       nSU;  $ )z!Filter retries from this library.LangSmithRetry)r  r  s      r#   r  FilterLangSmithRetry.filter  s     !s**r"   r   Nr
  )r   r   r   r   r    r  r!   r   r"   r#   r  r    s
    ++r"   r  c                      \ rS rSrSrSrg)r  i  z&Wrapper to filter logs with this name.r   Nr   r   r"   r#   r  r    r=   r"   r  c              #    #    [            U H  nU R                  U5        M     SSS5         Sv   [            U H  n U R                  U5        M     SSS5        g! , (       d  f       N>= f! [         a    [        R                  S5         MU  f = f! , (       d  f       g= f! [            U H;  n U R                  U5        M  ! [         a    [        R                  S5         M9  f = f   SSS5        f ! , (       d  f       f = f= f7f)zTemporarily adds specified filters to a logger.

Parameters:
- logger: The logger to which the filters will be added.
- filters: A sequence of `logging.Filter` objects to be temporarily added
    to the logger.
NzFailed to remove filter)_FILTER_LOCK	addFilterremoveFilterBaseExceptionr   warning)loggerfiltersr  s      r#   filter_logsr    s      
FV$  
?!?''/ " \ 
 % ?OO$=>?	 \\!?''/$ ?OO$=>? " \\s   D
AD
B$ D
BA-B	D

A*&D
-BBBB
B!D
$D+C62CC6C($C6'C((C6-	D6
D DD
c                     U b  U $ [        SSS9$ )zGet the testing cache directory.

Args:
    cache: The cache path.

Returns:
    The cache path if provided, otherwise the value from the `LANGSMITH_TEST_CACHE`
    environment variable.
N
TEST_CACHEr[   rk   )caches    r#   get_cache_dirr    s     |T22r"   ignore_hostsallow_hostsc               2  ^ ^ U(       a  [        U 4S jU 5       5      (       a  gU(       aT   [        R                  " T R                  5      nUR
                  =(       d    Sm[        U U4S jU 5       5      nU(       d  g0 T l        T $ ! [         a     gf = f)zAFilter request headers based on `ignore_hosts` and `allow_hosts`.c              3  Z   >#    U  H   nTR                   R                  U5      v   M"     g 7fr   )url
startswith)rs   r  r   s     r#   ru   )filter_request_headers.<locals>.<genexpr>  s#     R\TGKK22488\s   (+NrZ   c              3     >#    U  HV  nUR                  S 5      (       a  TR                  R                  U5      OTU:H  =(       d    TR                  SU 35      v   MX     g7f))zhttp://zhttps://r   N)r%  r$  endswith)rs   r  r   request_hosts     r#   ru   r&    sa      	
 $ ??#:;; &&t,!T)N\-B-BQtf:-NO $s   AA!)anyurllib_parseurlparser$  	Exceptionhostnameheaders)r   r   r!  
parsed_urlhost_matchesr)  s   `    @r#   filter_request_headersr2    s     R\RRR	%..w{{;J "**0b 	
 $	
 	
 GON'  		s    B	 	
BBc           	   #    ^^#     SSK nSSKJn  UR	                  5         [
        R                  R                  U 5      u  pVUR                  UR                  S5      (       d  UR                  S5      (       a  SOSUS	/ S
QSS/UU4S jS9nUR                  U5         Sv   SSS5        g! [         a    [        S5      ef = f! , (       d  f       g= f7f)Use a cache for requests.r   NzNvcrpy is required to use caching. Install with:pip install -U "langsmith[vcr]")_patchz.yamlz.ymlyamljsonnew_episodes)urimethodpathbodyauthorizationz
Set-Cookiec                   > [        U TTS9$ )Nr  )r2  )r   r!  r   s    r#   <lambda>with_cache.<locals>.<lambda>P  s    .D,K/
r"   )
serializercassette_library_dirrecord_modematch_onfilter_headersbefore_record_request)vcrImportErrorlangsmith._internalr5  patch_urllib3r   r;  splitVCRr(  use_cassette)r;  r   r!  rG  rJ  	cache_dir
cache_filels_vcrs    ``     r#   
with_cacherQ  /  s     
 <!GGMM$/IWW ""7++z/B/B6/J/J & #2'6
  F  
		Z	( 
)	(9  
.
 	

8 
)	(s4   CB+ BCC"	C+CC
CCc              #  p   #    U b  [        XU5         Sv   SSS5        gSv   g! , (       d  f       g= f7f)r4  N)rQ  )r;  r   r!  s      r#   with_optional_cacherS  X  s/      K8 98 	 98s   6%6
36c                     [         R                  " [        R                  " 5       6 n U  Vs/ s H  nSU;  d  M  UPM     nnSR	                  U5      $ s  snf )Nz
langsmith/rZ   )	tracebackformat_exceptionsysexc_infory   )tb_lineslinefiltered_liness      r#   _format_excr\  f  sH    ))3<<>:H'/Lxt<t3KdxNL77>"" Ms
   
AATc                  ^^^ [        U 5      n[        USS 5      nUb	   U" T5      $ TT:  a  U $ [        U [        5      (       aD  U R                  5        VVs0 s H&  u  pg[        UTTTS-   5      [        UTTTS-   5      _M(     snn$ [        U [        5      (       a"  U  Vs/ s H  n[        UTTTS-   5      PM     sn$ [        U [        5      (       a  [        UUU4S jU  5       5      $ [        U [        5      (       a"  U  Vs1 s H  n[        UTTTS-   5      iM     sn$ U $ ! [         a     GN
f = fs  snnf s  snf s  snf )N__deepcopy__rq   c              3  F   >#    U  H  n[        UTTTS -   5      v   M     g7f)rq   N)_middle_copy)rs   item_depth	max_depthmemos     r#   ru   _middle_copy.<locals>.<genexpr>  s%     UQT\$i!DDQTs   !)
r   r   r  r   r   itemsra  listtupleset)	valre  rd  rc  clscopierkvrb  s	    ```     r#   ra  ra  p  sO    s)CS.$/F	$< 
#t
 			
 $ D)VaZ8,4FQJ;  $	
 	
 #tLOPCDT4FQJ?CPP#uUQTUUU#sLOPCDT4FQJ?CPPJ%  		

 Q Qs#   D% -D6"D<E%
D32D3c                    0 n [         R                  " X5      $ ! [         a4  n[        R	                  S[        U5      5        [        X5      s SnA$ SnAff = f)zDeep copy a value with a compromise for uncopyable objects.

Args:
    val: The value to be deep copied.

Returns:
    The deep copied value.
zFailed to deepcopy input: %sN)copydeepcopyr  r   debugreprra  )rk  re  r   s      r#   deepish_copyru    sM     D'}}S'' '
 	4d1g>C&&'s    
A)AAAc                Z    SSK Jn  UR                  U 5      nUR                  U5      nX4:  $ )zGCheck if the current version is greater or equal to the target version.r   )version)	packagingrw  r   )current_versiontarget_versionrw  currenttargets        r#   is_version_greater_or_equalr}    s*    !mmO,G]]>*Fr"   c                   U (       aA  U R                  S5      S:  d,  U R                  S5      (       d  U R                  S5      (       a  [        SU  35      eU R	                  SS5      nUS   n[        U5      S:  a  US   OSnSU;   a4  UR	                  SS5      u  pEU(       a  U(       d  [        SU  35      eXEU4$ U(       d  [        SU  35      eSX#4$ )a  Parse a string in the format of `owner/name:hash`, `name:hash`, `owner/name`, or `name`.

Args:
    identifier: The prompt identifier to parse.

Returns:
    A tuple containing `(owner, name, hash)`.

Raises:
    ValueError: If the identifier doesn't match the expected formats.
/rq   zInvalid identifier format: :r   latest-)r~   r%  r(  rz   rK  r   )
identifierparts
owner_namecommitownerr   s         r#   parse_prompt_identifierr    s     C 1$  %%s##6zlCDDS!$EqJUaU1XXF
j &&sA.D::,GHHF""::,GHHJ&&r"   Pc                  l   ^  \ rS rSrSr        S	U 4S jjrSSS.         S
U 4S jjjrSrU =r$ )ContextThreadPoolExecutori  z?ThreadPoolExecutor that copies the context to the child thread.c           
        > [         TU ]  [        [        S[        4   [
        R                  " [        R                  " 5       R                  U/UQ70 UD65      5      $ )a  Submit a function to the executor.

Args:
    func (Callable[..., T]): The function to submit.
    *args (Any): The positional arguments to the function.
    **kwargs (Any): The keyword arguments to the function.

Returns:
    Future[T]: The future for the function.
.)
rB   submitr   r   r]  r   partialcontextvarscopy_contextrun)rE   r   rF   rG   rH   s       r#   r   ContextThreadPoolExecutor.submit  s\      w~a !!,,.22D;?CI
 	
r"   Nrq   timeout	chunksizec                  >^^ [        [        US   5      5       Vs/ s H  n[        R                  " 5       PM     snmSUU4S jjn[        TU ]  " U/UQ7UUS.6$ s  snf )aA  Return an iterator equivalent to stdlib map.

Each function will receive its own copy of the context from the parent thread.

Args:
    fn: A callable that will take as many arguments as there are
        passed iterables.
    timeout: The maximum number of seconds to wait. If None, then there
        is no limit on the wait time.
    chunksize: The size of the chunks the iterable will be broken into
        before being passed to a child process. This argument is only
        used by ProcessPoolExecutor; it is ignored by
        ThreadPoolExecutor.

Returns:
    An iterator equivalent to: map(func, *iterables) but the calls may
    be evaluated out-of-order.

Raises:
    TimeoutError: If the entire result iterator could not be generated
        before the given timeout.
    Exception: If fn(*args) raises for any values.
r   c                 F   > TR                  5       R                  " T/U Q76 $ r   )popr  )rF   contextsfns    r#   _wrapped_fn2ContextThreadPoolExecutor.map.<locals>._wrapped_fn  s    <<>%%b0400r"   r  )rF   r   rJ   r]  )ranger   r  r  rB   map)	rE   r  r  r  	iterablesr   r  r  rH   s	    `     @r#   r  ContextThreadPoolExecutor.map  sm    < 9>c)A,>O8PQ8P1K,,.8PQ	1 	1 w{

 	
 	
 Rs   Ar   )r   zCallable[P, T]rF   zP.argsrG   zP.kwargsrJ   z	Future[T])
r  zCallable[..., T]r  zIterable[Any]r  zOptional[float]r  intrJ   zIterator[T])	r   r   r   r   r    r  r  r!   rL   rM   s   @r#   r  r    ss    I

 
 	

 

: $((
(
 "(
 !	(

 (
 
(
 (
r"   r  c                    U =(       d    [        [        [        SSS95      nUR                  5       (       d  [	        S5      eUR                  5       R                  S5      R                  S5      R                  S5      $ )zBGet the LangSmith API URL from the environment or the given value.ENDPOINTzhttps://api.smith.langchain.comr[   z!LangSmith API URL cannot be empty"'r  )r   r   rc   r   r+   rstrip)api_url_api_urls     r#   get_api_urlr    sm     $5	
H >> !DEE>>!!#&,,S188==r"   c                    U b  U O	[        SSS9nUb  UR                  5       (       d  gUR                  5       R                  S5      R                  S5      $ )z8Get the API key from the environment or the given value.NAPI_KEYr[   r  r  rc   r   )api_keyapi_key_s     r#   get_api_keyr  '  sN    !-w;yRV3WHx~~//>>!!#&,,S11r"   c                    U b  U O	[        SSS9nUb  UR                  5       (       d  gUR                  5       R                  S5      R                  S5      $ )zGet workspace ID.NWORKSPACE_IDr[   r  r  r  )workspace_idworkspace_id_s     r#   get_workspace_idr  /  s\     # 	6 
 M$7$7$9$9 &&s+11#66r"   c                2    [         R                  " U 5      R                  R                  S5      S   n[        R
                  " U5      nUS:H  =(       d)    UR                  S5      =(       d    UR                  S5      $ ! [        R                   a     gf = f)zCheck if the URL is localhost.

Parameters
----------
url : str
    The URL to check.

Returns:
-------
bool
    True if the URL is localhost, False otherwise.
r  r   z	127.0.0.1z0.0.0.0z::F)r+  urlsplitnetlocrK  socketgethostbynamer%  gaierror)r$  r  ips      r#   _is_localhostr  ;  sz    &&s+2288=a@!!&)[ SBMM)$<Sd@SS?? s   A<A? ?BB   c                V   U (       a  U $ [         R                  " U5      n[        U5      (       a  SnU$ [        UR                  5      R                  S5      (       aM  [        UR                  5      R                  SS5      S   n[         R                  " UR                  US95      nU$ [        UR                  5      R                  S5      (       aM  [        UR                  5      R                  SS5      S   n[         R                  " UR                  US95      nU$ [        UR                  5      R                  S5      (       a  SnU$ [        UR                  5      R                  S	5      (       a  S
nU$ [        UR                  5      R                  S5      (       a  SnU$ SnU$ )z1Get the host URL based on the web URL or API URL.zhttp://localhostz/apirq   r   )r;  z/api/v1zeu.zhttps://eu.smith.langchain.comzdev.zhttps://dev.smith.langchain.comzbeta.z https://beta.smith.langchain.comzhttps://smith.langchain.com)r+  r,  r  r   r;  r(  rsplit
urlunparse_replacer  r%  )web_urlr  r0  linknew_paths        r#   get_host_urlr  P  s    &&w/JW! K 
Z__		&	&v	.	.z'..vq9!<&&z':':':'IJ K 
Z__		&	&y	1	1z'..y!<Q?&&z':':':'IJ K 
Z		*	*5	1	1/ K 
Z		*	*6	2	20
 K	 
Z		*	*7	3	31 K -Kr"   c                   US:  d  [        U 5      (       d  [        U 5      $ [        U S5      (       a  U R                  $ [	        U [
        R                  5      (       a  [        U R                  US-   5      $ [        U S5      (       a[  [        U S5      (       a1  [        U R                  S5      (       a  U R                  R                  $ [        U R                  US-   5      $ [        U 5      $ )Nr  r   rq   __call__rH   )callabler   r   r   r   r   r  _get_function_namer   rH   r  )r  depths     r#   r  r  i  s    qy2wr:{{"i''((!"''51955r:2{##j(I(I<<(((!"++uqy99r7Nr"   c                    [        U [        5      (       a  U R                  5       S:H  =(       d    U S:H  $ [        U 5      $ )zCheck if the value is truish.

Args:
    val (Any): The value to check.

Returns:
    bool: True if the value is truish, False otherwise.
r]   1)r   r   r   r  )rk  s    r#   r   r   {  s5     #syy{f$2s
29r"   r   )rd   zOptional[dict]rJ   zUnion[bool, Literal['local']]r
  )r   ztuple[str, ...]rJ   r   )r   z(Union[requests.Response, httpx.Response]rJ   rK   )r   zUnion[enum.Enum, str]rJ   r   )r   r  r   r   rJ   rK   )r   Mapping[str, Any]rJ   r   )r   r  rJ   r  )r   r  rJ   dict[str, Any])r   r  rJ   zlist[dict[str, Any]])r   r  rJ   r  )r   r  rJ   r   )r   r  rJ   r   )rJ   z	list[str])r   zls_schemas.BaseMessageLikerJ   r   )r   objectrJ   r  )r   Optional[str]rJ   r  )r   r   r\   r   r   ri  rJ   r   )r   r   r\   rK   r   ri  rJ   r  )r   r   r\   r  r   ri  rJ   r  )T)rJ   r  )r  zlogging.Loggerr  zSequence[logging.Filter]rJ   Generator[None, None, None])r  r  rJ   r  )r   r   r   Optional[Sequence[str]]r!  r  rJ   r   )NN)r;  zUnion[str, pathlib.Path]r   r  r!  r  rJ   r  )r;  z"Optional[Union[str, pathlib.Path]]r   r  r!  r  rJ   r  )rJ   r   )   r   )
rk  r]  re  zdict[int, Any]rd  r  rc  r  rJ   r]  )rk  r]  rJ   r]  )ry  r   rz  r   rJ   r  )r  r   rJ   ztuple[str, str, str])r  r  rJ   r   )r  r  rJ   r  )r  r  rJ   r  )r$  r   rJ   r  )r  r  r  r   )r   )r  r   r  r  rJ   r   )rk  r   rJ   r  )nr    
__future__r   
contextlibr  rq  r   r   loggingr   pathlibr  r   rW  	threadingrU  collections.abcr   r   r   r   r   concurrent.futuresr	   r
   typingr   r   r   r   r   r   r   r   urllibr   r+  r   r   typing_extensionsr   urllib3.utilr   	langsmithr   
ls_schemas	getLoggerr   r   r-  r   r%   r(   r+   r.   r1   r4   r7   r;   r?   UserWarningrO   rR   rg   rl   r   r   r   	lru_cacher   r   r   r   r   r   r   r   r   r   r   r   rc   r   Filterr   r  r  RLockr  contextmanagerr  r  r2  rQ  rS  r\  r]  ra  ru  r}  r  r  r  r  r  r  r  r  r  r   r   r"   r#   <module>r     su     "       	    
   L L 9	 	 	 )   '  +


H
%HY HD D5n 5L LBn B8 80^ 0'^ '1~ 1%n %#{ #'$4 ' 0?
46	  Q    
&&8P&9:L2
$ Q  4	$) 

 3	
 	
 	 
 
  3	
 	
  
 S! " 3	
 	
  "4 Q  &%GNN %*+7>> +1U 1   ??%=? ? ?23$ -1+/	!! *! )	!
 	!H  -1+/%
"%)% )% !	% %P  -1+/

,
)
 )
 !	
 
# CL EF	
 -0>A<'* 'F cND
 2 D
N>2	7* Q  0$r"   