
    ;i"                       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	J
r
JrJrJr  SSKJrJrJrJrJr  SSKrSSKJr  SSKJr  SSKJr  SS	KJr  \\R>                  \ 4   r! " S
 S5      r"SS jr#g)zThe Async LangSmith Client.    )annotationsN)AsyncGeneratorAsyncIteratorMappingSequence)AnyLiteralOptionalUnioncast)client)schemas)utils)_beta_decoratorc                  <   \ rS rSrSrSr     S`         SaS jjrSbS jrS rS r	\
S	 5       r\
ScS
 j5       r        SdS jr Se     SfS jjrSSSS.         SgS jjrSSS.             ShS jjr      SiS jrSjS jrSSSSSSSSSSSSSSSSS.                                   SkS jjrSS.     SlS jjrSmS jrSnS jr      SoS jr  Sp     SqS jjrSSS.     SrS jjr      SsS jr  Sp     StS  jjrSuS! jr    SvS" jr   Sw           SxS# jjrSyS$ jrSSS%.       SzS& jjr    Sw             S{S' jjr! SeSSSSS(.             S|S) jjjr"SSSS*.           S}S+ jjr#    S~S, jr$SSSSS-.           SS. jjr%SS/ jr&SSSSS0.         SS1 jjr'SSS2.       SS3 jjr(    SS4 jr)SS5.       SS6 jjr*SS7 jr+      SS8 jr,      SS9 jr-      SS: jr.\/R`                  S;S<.       SS= jj5       r1\/R`                        SS> j5       r2\/R`                  SS?.           SS@ jj5       r3SSA jr4SSB jr5      SSC jr6 S       SSE jjr7      SSF jr8SSG jr9SSH jr:SSI jr;SSJ jr<SKSDSSL\=R|                  R~                  SMSSN.               SSO jjr@SSP jrASSSSLSQ.           SSR jjrBSSS.       SST jjrCSSSSSSU.             SSV jjrDSSW jrESLSX.     SSY jjrFSSDSLSZ.         SS[ jjrGSLSX.     SS\ jjrHSS;SSSSS].               SS^ jjrIS_rJg)AsyncClient   z4Async Client for interacting with the LangSmith API.)_retry_config_client_web_url	_settingsNc                   U=(       d    SS0U l         SS0n[        R                  " U5      n[        R                  " U5      nU(       a  X&[        R
                  '   [        R                  " X5        [        U[        5      (       a
  US-  SSS4nO;[        U[        5      (       a$  [        U Vs/ s H  ob  US-  OSPM     sn5      nOSn[        R                  " XUS9U l        XPl        SU l        gs  snf )	zInitialize the async client.max_retries   zContent-Typeapplication/jsoni  N
   )base_urlheaderstimeout)r   ls_utilsget_api_keyget_api_url	ls_client	X_API_KEY_validate_api_key_if_hosted
isinstanceinttuplehttpxr   r   r   r   )	selfapi_urlapi_key
timeout_msretry_configweb_url_headerstimeout_ts	            f/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/langsmith/async_client.py__init__AsyncClient.__init__#   s     *?mQ-?.
 &&w/&&w/,3Y(()--g?j#&&-7$->dD,QH
E**:V:a-a$hTA:VWHH((
  AE Ws   /C4c                   #    U $ 7f)zEnter the async client. r*   s    r3   
__aenter__AsyncClient.__aenter__F   s
     s   c                @   #    U R                  5       I Sh  vN   g N7f)zExit the async client.N)aclose)r*   exc_typeexc_valexc_tbs       r3   	__aexit__AsyncClient.__aexit__J   s     kkms   c                T   #    U R                   R                  5       I Sh  vN   g N7f)zClose the async client.N)r   r<   r8   s    r3   r<   AsyncClient.acloseN   s     ll!!###s   (&(c                @    [        U R                  R                  5      $ N)strr   r   r8   s    r3   _api_urlAsyncClient._api_urlR   s    4<<(())    c                X    [         R                  " U R                  U R                  5      $ )zThe web host url.)r    get_host_urlr   rG   r8   s    r3   	_host_urlAsyncClient._host_urlV   s     $$T]]DMMBBrI   c                v  #    [        [        U R                  R                  SS5      5      nSU;   a2  US   nUR	                  5        VVs0 s H  u  pgUc  M
  Xg_M     nnnXS'   [        U5       HA  n	 U R                  R                  " X40 UD6I Sh  vN n
[        R                  " U
5        U
s  $    [        R                  " S5      es  snnf  N<! [        R                   Gad  nW
R                  S:X  a(  [        R                  " SU SU S[        U5       35      eU
R                  S	:X  a  [        R                  " S
U U 35      eU
R                  S:X  a%  [        R                   " SU S[        U5       35      eU
R                  S:X  a%  [        R"                  " SU S[        U5       35      eU
R                  S:X  a%  [        R$                  " SU S[        U5       35      eU
R                  S:X  a%  [        R&                  " SU S[        U5       35      e[        R(                  " SU SU S[        U5       35      eSnAf[        R*                   aX  nXS-
  :X  a"  [        R,                  " S[        U5       35      e[.        R0                  " SU	-  5      I Sh  vN     SnAGMA  SnAff = f7f)z(Make an async HTTP request with retries.r   r   paramsNi  zServer error caused failure to  z in LangSmith API. i  z(Client took too long to send request to i  zRate limit exceeded for z. i  zAuthentication failed for i  zResource not found for i  zConflict for z
Failed to    zRequest error:    z0Unexpected error connecting to the LangSmith API)r   r'   r   getitemsranger   requestr    raise_for_status_with_textr)   HTTPStatusErrorstatus_codeLangSmithAPIErrorreprLangSmithRequestTimeoutLangSmithRateLimitErrorLangSmithAuthErrorLangSmithNotFoundErrorLangSmithConflictErrorLangSmithErrorRequestErrorLangSmithConnectionErrorasynciosleep)r*   methodendpointkwargsr   rO   kvfiltered_paramsattemptresponsees               r3   _arequest_with_retries"AsyncClient._arequest_with_retries[   s     3 2 2 6 6}a HI vH%F06P!tqtOP.8[)G&0!%!5!5f!Q&!QQ33H=	 *P ((>
 	
W Q
 R (( ''3."449&H: &++/7)5 
 ))S0"::B6(8*U  ))S0"::28*BtAwiH  ))S0"554XJba	J  ))S0"991(2d1gYG  ))S0"99'zDG9=  #11$VHAhZ7J4PQ7)T  %% 0Ao-";;odSTgY<WXXmmAwJ////0sn   A	J9	CCJ94 CCC0!J9CJ6(EIJ6AJ1$J'%J1*J91J66J9c               >  #    U=(       d    0 nUR                  SS5      nUR                  SS5      US'    X2S'   U R                  SXS9I Sh  vN nUR                  5       nU(       d  gU H  nU7v   M
     [        U5      US   :  a  gU[        U5      -  nMe   NM7f)zGet a paginated list of items.offsetr   limitd   GETrO   N)rS   ro   jsonlen)r*   pathrO   rr   rm   rT   items          r3   _aget_paginated_list AsyncClient._aget_paginated_list   s      2Ha( **Wc2w%8!888TTHMMOE
 5zF7O+c%j F Ts   ABBABPOSTruns)bodyrequest_methoddata_keyc                #    U(       a  UR                  5       O0 n U R                  UU[        R                  " U5      S9I Sh  vN nUR	                  5       nU(       d  gUR                  U5      (       d  gXt    H  nU7v   M
     UR                  S5      n	U	(       d  gU	R                  S5      (       d  gU	S   US'   M   N}7f)z%Get a cursor paginated list of items.contentNcursorsnextcursor)copyro   r#   _dumps_jsonrw   rS   )
r*   ry   r   r   r   params_rm   response_bodyrunr   s
             r3   _aget_cursor_paginated_list'AsyncClient._aget_cursor_paginated_list   s      "&$))+2!88!--g6 9  H
 %MMOM  $$X..$.	 /#''	2G;;v&& 'GH% s   ACCA>C)project_namerevision_idc                 #    UUR                  S5      =(       d    [        R                  " 5       UUU=(       d    [        R                  " 5       US.UEnU R                  SS[        R                  " U5      S9I Sh  vN   g N7f)zCreate a run.id)namer   inputsrun_typesession_namer   r}   /runsr   N)rS   uuiduuid4r    get_tracer_projectro   r#   r   )r*   r   r   r   r   r   rh   
run_creates           r3   
create_runAsyncClient.create_run   s}      **T"2djjl (IH,G,G,I&
 

 ))GY%:%::%F * 
 	
 	
s   A;B=B>Bc                   #    0 UES[         R                  " U5      0EnU R                  SS[         R                  " U5       3[         R                  " U5      S9I Sh  vN   g N7f)zUpdate a run.r   PATCH/runs/r   N)r#   _as_uuidro   r   )r*   run_idrh   datas       r3   
update_runAsyncClient.update_run   sg      <&;$	 2 26 :;))Y''/01))$/ * 
 	
 	
s   AA&A$A&c                   #    U R                  SS[        R                  " U5       35      I Sh  vN n[        R                  " S0 UR                  5       D6$  N(7f)zRead a run.ru   r   Nr7   )ro   r#   r   
ls_schemasRunrw   )r*   r   rm   s      r3   read_runAsyncClient.read_run   sR     44Y''/01
 
 ~~000	
   -AA)A)
project_idr   r   trace_idreference_example_idqueryfiltertrace_filtertree_filteris_rootparent_run_id
start_timeerrorrun_idsselectrs   c              $  #    / n[        U[        R                  [        45      (       a  UR	                  U5        O&[        U[
        5      (       a  UR                  U5        Ub}  [        U[        5      (       a  U/n[        R                  " U Vs/ s H  nU R                  US9PM     sn6 I Sh  vN nUR                  U Vs/ s H  nUR                  PM     sn5        U(       a!  SU;   a  [        R                  " S[        5        U(       a  UOSUU(       a  U/OSUUUU	U
UU(       a  UR                  5       OSUUUUS.UEnU(       a3  U Vs/ s H"  n[        [        R                   " U5      5      PM$     snUS'   UR#                  5        VVs0 s H  u  nnUc  M  UU_M     nnnSnU R%                  SUS	9  Sh  vN n[&        R(                  " S0 UD67v   US
-  nUc  M,  UU:  d  M4    gs  snf  GNHs  snf s  snf s  snnf  NI
 g7f)a  List runs from the LangSmith API.

Parameters
----------
project_id : UUID or None, default=None
    The ID(s) of the project to filter by.
project_name : str or None, default=None
    The name(s) of the project to filter by.
run_type : str or None, default=None
    The type of the runs to filter by.
trace_id : UUID or None, default=None
    The ID of the trace to filter by.
reference_example_id : UUID or None, default=None
    The ID of the reference example to filter by.
query : str or None, default=None
    The query string to filter by.
filter : str or None, default=None
    The filter string to filter by.
trace_filter : str or None, default=None
    Filter to apply to the ROOT run in the trace tree. This is meant to
    be used in conjunction with the regular `filter` parameter to let you
    filter runs by attributes of the root run within a trace.
tree_filter : str or None, default=None
    Filter to apply to OTHER runs in the trace tree, including
    sibling and child runs. This is meant to be used in conjunction with
    the regular `filter` parameter to let you filter runs by attributes
    of any run within a trace.
is_root : bool or None, default=None
    Whether to filter by root runs.
parent_run_id : UUID or None, default=None
    The ID of the parent run to filter by.
start_time : datetime or None, default=None
    The start time to filter by.
error : bool or None, default=None
    Whether to filter by error status.
run_ids : List[str or UUID] or None, default=None
    The IDs of the runs to filter by.
limit : int or None, default=None
    The maximum number of runs to return.
**kwargs : Any
    Additional keyword arguments.

Yields:
------
Run
    The runs.

Examples:
--------
List all runs in a project:

.. code-block:: python

    project_runs = client.list_runs(project_name="<your_project>")

List LLM and Chat runs in the last 24 hours:

.. code-block:: python

    todays_llm_runs = client.list_runs(
        project_name="<your_project>",
        start_time=datetime.now() - timedelta(days=1),
        run_type="llm",
    )

List root traces in a project:

.. code-block:: python

    root_runs = client.list_runs(project_name="<your_project>", is_root=1)

List runs without errors:

.. code-block:: python

    correct_runs = client.list_runs(project_name="<your_project>", error=False)

List runs and only return their inputs/outputs (to speed up the query):

.. code-block:: python

    input_output_runs = client.list_runs(
        project_name="<your_project>", select=["inputs", "outputs"]
    )

List runs by run ID:

.. code-block:: python

    run_ids = [
        "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
        "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
    ]
    selected_runs = client.list_runs(id=run_ids)

List all "chain" type runs that took more than 10 seconds and had
`total_tokens` greater than 5000:

.. code-block:: python

    chain_runs = client.list_runs(
        project_name="<your_project>",
        filter='and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
    )

List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1:

.. code-block:: python

    good_extractor_runs = client.list_runs(
        project_name="<your_project>",
        filter='eq(name, "extractor")',
        trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
    )

List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0:

.. code-block:: python

    complex_runs = client.list_runs(
        project_name="<your_project>",
        filter='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
    )

List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds:

.. code-block:: python

    tagged_runs = client.list_runs(
        project_name="<your_project>",
        filter='and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
    )
Nr   child_run_idszOThe child_run_ids field is deprecated and will be removed in following versions)sessionr   reference_exampler   r   r   r   r   
parent_runr   r   r   tracer   r   r   z/runs/query)r   rQ   r7   )r&   r   UUIDrF   appendlistextendrd   gatherread_projectr   warningswarnDeprecationWarning	isoformatr#   r   rT   r   r   r   )r*   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   rh   project_idsr   projectsproject
body_queryid_ri   rj   r   ixr   s                                r3   	list_runsAsyncClient.list_runs   s    x j499c"233z*
D))z*#,,, ,~$^^COP<4$###6<P H (C(w

(CDo/MMa" '2{t *>%&D(&'4>*..0D!&
" #&

& 8C%8CI&&s+,%Jy! ",!1!1!3E!3Aq1!3E99-d9S 	#..'3''!GB R5[O Q  D8% F	Ss   BHG4*H1G92HG<A7H)H;H
H"H)H>HHH H*H2H<HHH)share_idc               z  #    [         R                  " US5      n[        U5      [        U=(       d    [        R                  " 5       5      S.nU R                  SSU S3[         R                  " U5      S9I Sh  vN n[        R                  " U5        UR                  5       S   nU R                   S	U S
3$  N?7f)aG  Get a share link for a run asynchronously.

Args:
    run_id (ID_TYPE): The ID of the run to share.
    share_id (Optional[ID_TYPE], optional): Custom share ID.
        If not provided, a random UUID will be generated.

Returns:
    str: The URL of the shared run.

Raises:
    httpx.HTTPStatusError: If the API request fails.
r   )r   share_tokenPUTr   /sharer   Nr   /public//r)r#   r   rF   r   r   ro   r   r    rW   rw   rL   )r*   r   r   run_id_r   rm   r   s          r3   	share_runAsyncClient.share_run  s       $$VX6'lx74::<8
 44WIV$))$/ 5 
 

 	++H5mmom4..!+b99
s   A7B;9B9:A B;c                r   #    U R                  [        R                  " US5      5      I Sh  vN nUSL$  N7f)z)Get share state for a run asynchronously.r   N)read_run_shared_linkr#   r   )r*   r   links      r3   run_is_sharedAsyncClient.run_is_shared  s6     ..y/A/A&(/STT4 Us   *75	7c                   #    U R                  SS[        R                  " US5       S35      I Sh  vN n[        R                  " U5        UR                  5       nUb  SU;  a  gU R                   SUS    S3$  NI7f)	a  Retrieve the shared link for a specific run asynchronously.

Args:
    run_id (ID_TYPE): The ID of the run.

Returns:
    Optional[str]: The shared link for the run, or None if the link is not
    available.

Raises:
    httpx.HTTPStatusError: If the API request fails.
ru   r   r   r   Nr   r   r   )ro   r#   r   r    rW   rw   rL   )r*   r   rm   results       r3   r    AsyncClient.read_run_shared_link  s      44Y''9:&A
 
 	++H5>]&8..!&*?)@CC
s   /A=A;A
A=c                   #    SU0UEnU R                  SS[        R                  " U5      S9I Sh  vN n[        R                  " S0 UR                  5       D6$  N(7f)zCreate a project.r   r}   	/sessionsr   Nr7   )ro   r#   r   r   TracerSessionrw   )r*   r   rh   r   rm   s        r3   create_projectAsyncClient.create_project  sc      //44K)>)>t)D 5 
 
 '':(--/::
   /AA)Ac                  #    U(       a2  U R                  SS[        R                  " U5       35      I Sh  vN nO.U(       a  U R                  SSSU0S9I Sh  vN nO[        S5      eUR	                  5       n[        U[        5      (       a:  U(       d  [        R                  " SU S	35      e[        R                  " S0 US
   D6$ [        R                  " S0 UD6$  N N7f)zRead a project.ru   
/sessions/Nr   r   rv   2Either project_name or project_id must be providedzProject 
 not foundr   r7   )ro   r#   r   
ValueErrorrw   r&   r   r    r_   r   r   )r*   r   r   rm   r   s        r3   r   AsyncClient.read_project  s      !88I$6$6z$B#CD H !88{FL+A 9  H QRR}}dD!!55|nJ7  ++6d1g66''/$//#"   4C#C"C#C!BC#!C#)r   r   c                 #    Uc  Uc  [        S5      eUc,  U R                  US9I Sh  vN n[        UR                  5      nU(       d  [        S5      eU R	                  SS[
        R                  " U5       35      I Sh  vN   g N] N7f)zDelete a project from LangSmith.

Parameters
----------
project_name : str or None, default=None
    The name of the project to delete.
project_id : str or None, default=None
    The ID of the project to delete.
Nr   r   zProject not foundDELETEr   )r   r   rF   r   ro   r#   r   )r*   r   r   r   s       r3   delete_projectAsyncClient.delete_project%  s      ,"6QRR --<-HHGWZZJ011))++J789
 	
 	
	 I	
s"   'BBABB	B	Bc                   #    SU0UEnU R                  SS[        R                  " U5      S9I Sh  vN n[        R                  " S0 UR                  5       D6$  N(7f)zCreate a dataset.r   r}   	/datasetsr   Nr7   )ro   r#   r   r   Datasetrw   )r*   dataset_namerh   r   rm   s        r3   create_datasetAsyncClient.create_dataset=  sc      //44K)>)>t)D 5 
 
 !!4HMMO44
r   c                  #    U(       a2  U R                  SS[        R                  " U5       35      I Sh  vN nO.U(       a  U R                  SSSU0S9I Sh  vN nO[        S5      eUR	                  5       n[        U[        5      (       a:  U(       d  [        R                  " SU S	35      e[        R                  " S0 US
   D6$ [        R                  " S0 UD6$  N N7f)zRead a dataset.ru   
/datasets/Nr   r   rv   z2Either dataset_name or dataset_id must be providedzDataset r   r   r7   )ro   r#   r   r   rw   r&   r   r    r_   r   r   )r*   r   
dataset_idrm   r   s        r3   read_datasetAsyncClient.read_datasetI  s      !88I$6$6z$B#CD H !88{FL+A 9  H QRR}}dD!!55|nJ7  %%0Q00!!)D))#r   c                r   #    U R                  SS[        R                  " U5       35      I Sh  vN   g N7f)zDelete a dataset.r   r   N)ro   r#   r   )r*   r   s     r3   delete_datasetAsyncClient.delete_datasetc  s6     ))++J789
 	
 	
s   -757c               z   #    U R                  SUS9  Sh  vN n[        R                  " S0 UD67v   M$   N
 g7f)zList datasets.r   rv   Nr7   )r{   r   r   )r*   rh   datasets      r3   list_datasetsAsyncClient.list_datasetsj  s=     
 "66{66R 	0'$$/w//	0Rs   ;979;9;c                D  #    Uc  Uc  [        S5      eUc#  U R                  US9I Sh  vN nUR                  nUU[        U5      S.UEnU R	                  SS[
        R                  " U5      S9I Sh  vN n[        R                  " S0 UR                  5       D6$  Nr N*7f)	zCreate an example.Nz2Either dataset_id or dataset_name must be providedr   )r   outputsr   r}   	/examplesr   r7   )
r   r   r   rF   ro   r#   r   r   Examplerw   )	r*   r   r	  r   r   rh   r  r   rm   s	            r3   create_exampleAsyncClient.create_exampler  s      ,"6QRR --<-HHG J j/
 	
 44K)>)>t)D 5 
 
 !!4HMMO44 I
s"   'B BA	B 3B4)B B c                   #    U R                  SS[        R                  " U5       35      I Sh  vN n[        R                  " S0 UR                  5       D6$  N(7f)zRead an example.ru   z
/examples/Nr7   )ro   r#   r   r   r  rw   )r*   
example_idrm   s      r3   read_exampleAsyncClient.read_example  sS     44Z	 2 2: >?@
 
 !!4HMMO44
r   )r   r   c              :  #    UR                  5       nU(       a  [        R                  " U5      US'   O-U(       a&  U R                  US9I Sh  vN nUR                  US'   U R                  SUS9  Sh  vN n[        R                  " S0 UD67v   M$   NG N!
 g7f)zList examples.r  r  Nr
  rv   r7   )r   r#   r   r   r   r{   r   r  )r*   r   r   rh   rO   r  examples          r3   list_examplesAsyncClient.list_examples  s       ) 2 2: >F9 --<-HHG '

F9!66{66R 	0'$$/w//	 I	0Rs6   ABB#B1B5B6B9BBBc                   #    [         R                  " USS9UUUUS.UEnU R                  SS[         R                  " U5      S9I Sh  vN n[        R
                  " S0 UR                  5       D6$  N(7f)	a  Create feedback for a run.

Args:
    run_id (Optional[ls_client.ID_TYPE]): The ID of the run to provide feedback for.
        Can be None for project-level feedback.
    key (str): The name of the metric or aspect this feedback is about.
    score (Optional[float]): The score to rate this run on the metric or aspect.
    value (Optional[Any]): The display value or non-numeric value for this feedback.
    comment (Optional[str]): A comment about this feedback.
    **kwargs: Additional keyword arguments to include in the feedback data.

Returns:
    ls_schemas.Feedback: The created feedback object.

Raises:
    httpx.HTTPStatusError: If the API request fails.
T)accept_null)r   keyscorevaluecommentr}   	/feedbackr   Nr7   )r#   _ensure_uuidro   r   r   Feedbackrw   )	r*   r   r  r  r  r  rh   r   rm   s	            r3   create_feedbackAsyncClient.create_feedback  s     6  ,,VF
 
 44K)>)>t)D 5 
 
 ""5X]]_55
s   AA3A1	)A3)r  
correctionr  metadatac               L  #    [         R                  " XR                  SS9u  pxXpR                  :w  a  [        SU 35      eU R	                  SS[         R
                  " U5       3[         R                  " UUUUUS.5      S9I Sh  vN n	[        R                  " U	5        g N7f)	a  Create feedback from a presigned token or URL.

Args:
    token_or_url (Union[str, uuid.UUID]): The token or URL from which to create
         feedback.
    score (Union[float, int, bool, None], optional): The score of the feedback.
        Defaults to None.
    value (Union[float, int, bool, str, dict, None], optional): The value of the
        feedback. Defaults to None.
    correction (Union[dict, None], optional): The correction of the feedback.
        Defaults to None.
    comment (Union[str, None], optional): The comment of the feedback. Defaults
        to None.
    metadata (Optional[dict], optional): Additional metadata for the feedback.
        Defaults to None.

Raises:
    ValueError: If the source API URL is invalid.

Returns:
    None: This method does not return anything.
rQ   )	num_partszInvalid source API URL. r}   z/feedback/tokens/)r  r  r!  r  r"  r   N)	r#   _parse_token_or_urlrG   r   ro   r   r   r    rW   )
r*   token_or_urlr  r  r!  r  r"  source_api_url
token_uuidrm   s
             r3   create_feedback_from_token&AsyncClient.create_feedback_from_token  s     @ &/%B%B--1&
" ]]*77GHII44	 2 2: >?@))""",& (	 5 
 
 	++H5
s   BB$B"B$)
expirationfeedback_configfeedback_idc                 #    UUUU=(       d    [        [        R                  " 5       5      S.nUc  [        R                  " SSSS9US'   O[        U[        R                  5      (       a  UR                  5       US'   Ox[        U[        R                  5      (       aA  [        R                  " UR                  UR                  S-  UR                  S-  S	-  S9US'   O[        S
[        U5       S35      eU R                  SS[        R                  " U5      S9I Sh  vN n[        R                   " S0 UR#                  5       D6$  N(7f)a  Create a pre-signed URL to send feedback data to.

This is useful for giving browser-based clients a way to upload
feedback data directly to LangSmith without accessing the
API key.

Args:
    run_id:
    feedback_key:
    expiration: The expiration time of the pre-signed URL.
        Either a datetime or a timedelta offset from now.
        Default to 3 hours.
    feedback_config: FeedbackConfig or None.
        If creating a feedback_key for the first time,
        this defines how the metric should be interpreted,
        such as a continuous score (w/ optional bounds),
        or distribution over categorical values.
    feedback_id: The ID of the feedback to create. If not provided, a new
        feedback will be created.

Returns:
    The pre-signed URL for uploading feedback data.
)r   feedback_keyr,  r   Nr   r   )dayshoursminutes
expires_in
expires_ati  <   zInvalid expiration type: z3. Expected datetime.datetime or datetime.timedelta.r}   z/feedback/tokensr   r7   )rF   r   r   r   TimeDeltaInputr&   datetimer   	timedeltar0  secondsr   typero   r#   r   FeedbackIngestTokenrw   )r*   r   r/  r+  r,  r-  r   rm   s           r3   create_presigned_feedback_token+AsyncClient.create_presigned_feedback_token  sB    B (.2TZZ\!2	 
 !+!:!:"D
 
H$5$566!+!5!5!7D
H$6$677!+!:!:__ ((D0#++d2r9"D +D,<+= >D D 
 44))$/ 5 
 

 --@@@
s   DE
E )E
c                   #    U R                  SS[        R                  " U5       35      I Sh  vN n[        R                  " S0 UR                  5       D6$  N(7f)zRead feedback.ru   
/feedback/Nr7   )ro   r#   r   r   r  rw   r*   r-  rm   s      r3   read_feedbackAsyncClient.read_feedbackB  sU      44Z	 2 2; ?@A
 
 ""5X]]_55
r   )r   r/  feedback_source_typers   c              `  #    U(       a0  U Vs/ s H"  n[        [        R                  " U5      5      PM$     snOSUb  [        US5      OSS.UEnUb  X'S'   Ub  X7S'   SnU R	                  SUS9  Sh  vN n	[
        R                  " S
0 U	D67v   US	-  nUc  M,  X:  d  M3    gs  snf  N5
 g7f)zList feedback.Nrt   )r   rs   r  sourcer   r  rv   rQ   r7   )rF   r#   r   minr{   r   r  )
r*   r   r/  rC  rs   rh   r   rO   r   feedbacks
             r3   list_feedbackAsyncClient.list_feedbackK  s      FMA#Y'',-ARV(-(9S_s	

 
 #(5M+38"77F7S 	(%%111!GB R[ B	Ss?   B.)B%9B.0B,4B*5B,8 B.B.#B.*B,,B.c                   #    U R                  SS[        R                  " US5       35      I Sh  vN n[        R                  " U5        g N7f)zDelete a feedback by ID.

Args:
    feedback_id (Union[UUID, str]):
        The ID of the feedback to delete.

Returns:
    None
r   r?  r-  Nro   r#   r   r    rW   r@  s      r3   delete_feedbackAsyncClient.delete_feedbackg  sK      44
9#5#5k=#Q"RS
 
 	++H5
s   .AAA)	queue_idsr   name_containsrs   c          
    P  #    Ub9  [        U5       VVs/ s H   u  pV[        R                  " USU S35      PM"     snnOSUUUb  [        US5      OSS.nSnU R	                  SUS9  Sh  vN n	[
        R                  " S
0 U	D67v   US	-  nUc  M,  X:  d  M3    gs  snnf  N6
 g7f)a  List the annotation queues on the LangSmith API.

Args:
    queue_ids (Optional[List[Union[UUID, str]]]):
        The IDs of the queues to filter by.
    name (Optional[str]):
        The name of the queue to filter by.
    name_contains (Optional[str]):
        The substring that the queue name should contain.
    limit (Optional[int]):
        The maximum number of queues to return.

Yields:
    The annotation queues.
Nz
queue_ids[]rt   )idsr   rO  rs   r   /annotation-queuesrv   rQ   r7   )	enumerater#   r   rF  r{   r   AnnotationQueue)
r*   rN  r   rO  rs   ir   rO   r   rG  s
             r3   list_annotation_queues"AsyncClient.list_annotation_queuesx  s     : ( #,I"6"6 &&sj1,=>"6
 *(-(9S_s
 "77  8 
 	( ,,8x88!GB R[%	 
s?   B&'B,B&'B$+B",B$/ B&B&B&"B$$B&)descriptionqueue_idc          
     p  #    UUUb  [        U5      O[        [        R                  " 5       5      S.nU R                  SSUR	                  5        VVs0 s H  u  pVUc  M
  XV_M     snnS9I Sh  vN n[
        R                  " U5        [        R                  " S0 UR                  5       D6$ s  snnf  ND7f)a[  Create an annotation queue on the LangSmith API.

Args:
    name (str):
        The name of the annotation queue.
    description (Optional[str]):
        The description of the annotation queue.
    queue_id (Optional[Union[UUID, str]]):
        The ID of the annotation queue.

Returns:
    AnnotationQueue: The created annotation queue object.
N)r   rY  r   r}   rS  rw   r7   )
rF   r   r   ro   rT   r    rW   r   rU  rw   )r*   r   rY  rZ  r   ri   rj   rm   s           r3   create_annotation_queue#AsyncClient.create_annotation_queue  s     * &#+#7#h-S=N

 44 #'::<A<411$!$<A 5 
 

 	++H5)) 
mmo
 	
 B
s%   AB6	B. B.&	B6/B40AB6c                Z   #    U R                  U/S9R                  5       I Sh  vN $  N7f)zRead an annotation queue with the specified queue ID.

Args:
    queue_id (Union[UUID, str]): The ID of the annotation queue to read.

Returns:
    AnnotationQueue: The annotation queue object.
)rN  N)rW  	__anext__)r*   rZ  s     r3   read_annotation_queue!AsyncClient.read_annotation_queue  s,      00H:0FPPRRRRs   "+)+)rY  c                  #    U R                  SS[        R                  " US5       3UUS.S9I Sh  vN n[        R                  " U5        g N7f)a=  Update an annotation queue with the specified queue_id.

Args:
    queue_id (Union[UUID, str]): The ID of the annotation queue to update.
    name (str): The new name for the annotation queue.
    description (Optional[str]): The new description for the
        annotation queue. Defaults to None.

Returns:
    None
r   /annotation-queues/rZ  )r   rY  r\  NrK  )r*   rZ  r   rY  rm   s        r3   update_annotation_queue#AsyncClient.update_annotation_queue  s\      44!)"4"4Xz"J!KL* 5 
 
 	++H5
s   0AAAc                   #    U R                  SS[        R                  " US5       3SS0U R                  R                  ES9I Sh  vN n[
        R                  " U5        g N7f)zDelete an annotation queue with the specified queue ID.

Args:
    queue_id (Union[UUID, str]): The ID of the annotation queue to delete.

Returns:
    None
r   rd  rZ  Acceptr   )r   N)ro   r#   r   r   r   r    rW   )r*   rZ  rm   s      r3   delete_annotation_queue#AsyncClient.delete_annotation_queue  si      44!)"4"4Xz"J!KL1JT\\5I5IJ 5 
 

 	++H5
s   AA%A#A%c               ,  #    U R                  SS[        R                  " US5       S3[        U5       VVs/ s H)  u  p4[	        [        R                  " USU S35      5      PM+     snnS9I Sh  vN n[
        R                  " U5        gs  snnf  N!7f)	zAdd runs to an annotation queue with the specified queue ID.

Args:
    queue_id (Union[UUID, str]): The ID of the annotation queue.
    run_ids (List[Union[UUID, str]]): The IDs of the runs to be added to the annotation
        queue.

Returns:
    None
r}   rd  rZ  r   zrun_ids[rQ  r\  N)ro   r#   r   rT  rF   r    rW   )r*   rZ  r   rV  r   rm   s         r3   add_runs_to_annotation_queue(AsyncClient.add_runs_to_annotation_queue  s      44!)"4"4Xz"J!K5Q (00FA I&&shqcO<=0 5 
 
 	++H5
s   5B0B'	B0B1"Bc          
        #    U R                  SS[        R                  " US5       S[        R                  " US5       35      I Sh  vN n[        R                  " U5        g N7f)a  Delete a run from an annotation queue with the specified queue ID and run ID.

Args:
    queue_id (Union[UUID, str]): The ID of the annotation queue.
    run_id (Union[UUID, str]): The ID of the run to be added to the annotation
        queue.

Returns:
    None
r   rd  rZ  r   r   NrK  )r*   rZ  r   rm   s       r3    delete_run_from_annotation_queue,AsyncClient.delete_run_from_annotation_queue  sc      44!)"4"4Xz"J!K6R[RdRdekmuRvQwx
 
 	++H5	
   AA&A$	A&c                  #    S[         R                  " US5       S3nU R                  SU SU 35      I Sh  vN n[        R                  " U5        [
        R                  " S0 UR                  5       D6$  N>7f)a  Get a run from an annotation queue at the specified index.

Args:
    queue_id (Union[UUID, str]): The ID of the annotation queue.
    index (int): The index of the run to retrieve.

Returns:
    RunWithAnnotationQueueInfo: The run at the specified index.

Raises:
    LangSmithNotFoundError: If the run is not found at the given index.
    LangSmithError: For other API-related errors.
rd  rZ  z/runru   /Nr7   )r#   r   ro   r    rW   r   RunWithAnnotationQueueInforw   )r*   rZ  indexr   rm   s        r3   get_run_from_annotation_queue)AsyncClient.get_run_from_annotation_queue(  sr       )););Hj)Q(RRVW44Uxj%<QRR++H544Gx}}GG Ss   6A9A7?A9latest)tagc                  #    [         R                  " US5      nU R                  SSU S3[         R                  " SU0UE5      S9I Sh  vN n[        R
                  " U5        g N7f)a  Enable dataset indexing. Examples are indexed by their inputs.

This enables searching for similar examples by inputs with
``client.similar_examples()``.

Args:
    dataset_id (UUID): The ID of the dataset to index.
    tag (str, optional): The version of the dataset to index. If 'latest'
        then any updates to the dataset (additions, updates, deletions of
        examples) will be reflected in the index.

Returns:
    None

Raises:
    requests.HTTPError
r   r}   r   z/indexry  r   Nr#   r   ro   r   r    rW   )r*   r   ry  rh   resps        r3   index_datasetAsyncClient.index_dataset=  so     2 ''
LA
00F+))5#*@*@A 1 
 

 	++D1
s   AA(
A&A(c                  #    [         R                  " US5      nU R                  SSU S3[         R                  " 0 UE5      S9I Sh  vN n[        R
                  " U5        g N7f)zSync dataset index. This already happens automatically every 5 minutes, but you can call this to force a sync.

Args:
    dataset_id (UUID): The ID of the dataset to sync.

Returns:
    None

Raises:
    requests.HTTPError
r   r}   r   z/index/syncr   Nr{  )r*   r   rh   r|  s       r3   sync_indexed_dataset AsyncClient.sync_indexed_dataset^  si     $ ''
LA
00K0))*V*5 1 
 

 	++D1
rq  )r   c         	     |  #    [         R                  " US5      nUUS.UEnU(       a  XFS'   U R                  SSU S3[         R                  " U5      S9I Sh  vN n[        R
                  " U5        / nUR                  5       S	    H,  n	UR                  [        R                  " S
0 U	DSU0D65        M.     U$  Na7f)a  Retrieve the dataset examples whose inputs best match the current inputs.

**Note**: Must have few-shot indexing enabled for the dataset. See
``client.index_dataset()``.

Args:
    inputs (dict): The inputs to use as a search query. Must match the dataset
        input schema. Must be JSON serializable.
    limit (int): The maximum number of examples to return.
    dataset_id (str or UUID): The ID of the dataset to search over.
    filter (str, optional): A filter string to apply to the search results. Uses
        the same syntax as the `filter` parameter in `list_runs()`. Only a subset
        of operations are supported. Defaults to None.
    kwargs (Any): Additional keyword args to pass as part of request body.

Returns:
    List of ExampleSearch objects.

Example:
    .. code-block:: python

        from langsmith import Client

        client = Client()
        await client.similar_examples(
            {"question": "When would i use the runnable generator"},
            limit=3,
            dataset_id="...",
        )

    .. code-block:: pycon

        [
            ExampleSearch(
                inputs={'question': 'How do I cache a Chat model? What caches can I use?'},
                outputs={'answer': 'You can use LangChain\'s caching layer for Chat Models. This can save you money by reducing the number of API calls you make to the LLM provider, if you\'re often requesting the same completion multiple times, and speed up your application.\n\n```python\n\nfrom langchain.cache import InMemoryCache\nlangchain.llm_cache = InMemoryCache()\n\n# The first time, it is not yet in cache, so it should take longer\nllm.predict(\'Tell me a joke\')\n\n```\n\nYou can also use SQLite Cache which uses a SQLite database:\n\n```python\n  rm .langchain.db\n\nfrom langchain.cache import SQLiteCache\nlangchain.llm_cache = SQLiteCache(database_path=".langchain.db")\n\n# The first time, it is not yet in cache, so it should take longer\nllm.predict(\'Tell me a joke\') \n```\n'},
                metadata=None,
                id=UUID('b2ddd1c4-dff6-49ae-8544-f48e39053398'),
                dataset_id=UUID('01b6ce0f-bfb6-4f48-bbb8-f19272135d40')
            ),
            ExampleSearch(
                inputs={'question': "What's a runnable lambda?"},
                outputs={'answer': "A runnable lambda is an object that implements LangChain's `Runnable` interface and runs a callbale (i.e., a function). Note the function must accept a single argument."},
                metadata=None,
                id=UUID('f94104a7-2434-4ba7-8293-6a283f4860b4'),
                dataset_id=UUID('01b6ce0f-bfb6-4f48-bbb8-f19272135d40')
            ),
            ExampleSearch(
                inputs={'question': 'Show me how to use RecursiveURLLoader'},
                outputs={'answer': 'The RecursiveURLLoader comes from the langchain.document_loaders.recursive_url_loader module. Here\'s an example of how to use it:\n\n```python\nfrom langchain.document_loaders.recursive_url_loader import RecursiveUrlLoader\n\n# Create an instance of RecursiveUrlLoader with the URL you want to load\nloader = RecursiveUrlLoader(url="https://example.com")\n\n# Load all child links from the URL page\nchild_links = loader.load()\n\n# Print the child links\nfor link in child_links:\n    print(link)\n```\n\nMake sure to replace "https://example.com" with the actual URL you want to load. The load() method returns a list of child links found on the URL page. You can iterate over this list to access each child link.'},
                metadata=None,
                id=UUID('0308ea70-a803-4181-a37d-39e95f138f8c'),
                dataset_id=UUID('01b6ce0f-bfb6-4f48-bbb8-f19272135d40')
            ),
        ]

r   )r   rs   r   r}   r   z/searchr   Nexamplesr7   )
r#   r   ro   r   r    rW   rw   r   r   ExampleSearch)
r*   r   rs   r   r   rh   reqr|  r  exs
             r3   similar_examplesAsyncClient.similar_examplesx  s     H ''
LA

 

 "M00G,))#. 1 
 

 	++D1))+j)BOOJ44QrQjQR *
s   AB<B:A"B<c                   #    U R                   cY  U R                  SS5      I Sh  vN n[        R                  " U5        [        R
                  " S0 UR                  5       D6U l         U R                   $  NO7f)zbGet the settings for the current tenant.

Returns:
    dict: The settings for the current tenant.
Nru   z	/settingsr7   )r   ro   r    rW   r   LangSmithSettingsrw   )r*   rm   s     r3   _get_settingsAsyncClient._get_settings  s_      >>!!88LLH//9'99LHMMOLDN~~	 Ms   #A7A5AA7c                t   #    U R                  5       I Sh  vN nUS:H  =(       d    UR                  U:H  $  N7f)zCheck if the current workspace has the same handle as owner.

Args:
    owner (str): The owner to check against.

Returns:
    bool: True if the current tenant is the owner, False otherwise.
N-)r  tenant_handle)r*   ownersettingss      r3   _current_tenant_is_owner$AsyncClient._current_tenant_is_owner  s7      ++--|>x55>> .s   86 8c                   #    U R                  5       I S h  vN n[        R                  " SU SUR                   SU 35      $  N-7f)NzCannot z% for another tenant.
Current tenant: z,
Requested tenant: )r  r    LangSmithUserErrorr  )r*   actionr  r  s       r3   _owner_conflict_error!AsyncClient._owner_conflict_error  sW      ++--**fX '556 7!!&)
 	
 .s   AA.Ar   c                   #    U R                  SSU S3X#S.S9I Sh  vN nUR                  5       S   nU(       a  US   S	   $ S$  N(7f)
ag  Get the latest commit hash for a prompt.

Args:
    prompt_owner_and_name (str): The owner and name of the prompt.
    limit (int, default=1): The maximum number of commits to fetch. Defaults to 1.
    offset (int, default=0): The number of commits to skip. Defaults to 0.

Returns:
    Optional[str]: The latest commit hash, or None if no commits are found.
ru   	/commits/rs  )rs   rr   rv   Ncommitsr   commit_hash)ro   rw   )r*   prompt_owner_and_namers   rr   rm   r  s         r3   _get_latest_commit_hash#AsyncClient._get_latest_commit_hash  se      44-.a0"5 5 
 

 --/),,3wqz-(==
s   AA)Ac                   #    [         R                  " U5      u  p4nU R                  SSU SU 3SU0S9I Sh  vN nUR                  5         UR	                  5       $  N$7f)aR  Like or unlike a prompt.

Args:
    prompt_identifier (str): The identifier of the prompt.
    like (bool): True to like the prompt, False to unlike it.

Returns:
    A dictionary with the key 'likes' and the count of likes as the value.

Raises:
    requests.exceptions.HTTPError: If the prompt is not found or
    another error occurs.
r}   z/likes/rs  liker\  N)r    parse_prompt_identifierro   raise_for_statusrw   )r*   prompt_identifierr  r  prompt_name_rm   s          r3   _like_or_unlike_prompt"AsyncClient._like_or_unlike_prompt  sn       !) @ @AR SA44geWAk]364. 5 
 
 	!!#}}	
s   6AA%Ac           	       #    [         R                  " U5      u  p#nU R                  U5      (       d  U R                   SU SU SUSS  3$ U R	                  5       I Sh  vN nU R                   SU SUSS  SUR
                   3$  N(7f)zGet a URL for a prompt.

Args:
    prompt_identifier (str): The identifier of the prompt.

Returns:
    str: The URL for the prompt.

z/hub/rs  :N   z	/prompts/z?organizationId=)r    r  r  rL   r  r   )r*   r  r  r  r  r  s         r3   _get_prompt_urlAsyncClient._get_prompt_url  s      +3*J*J+
'K ,,U33nn%U5';-qRa@QRR++--~~i}Ak"1o5Fx{{m-	
 .s   AB
B )B
c                V   #    U R                  U5      I Sh  vN nU(       a  S$ S$  N7f)zCheck if a prompt exists.

Args:
    prompt_identifier (str): The identifier of the prompt.

Returns:
    bool: True if the prompt exists, False otherwise.
NTF)
get_prompt)r*   r  prompts      r3   _prompt_existsAsyncClient._prompt_exists6  s+      '899t(5( :s   )')c                >   #    U R                  USS9I Sh  vN $  N7f)zLike a prompt.

Args:
    prompt_identifier (str): The identifier of the prompt.

Returns:
    Dict[str, int]: A dictionary with the key 'likes' and the count of likes as the value.

Tr  Nr  r*   r  s     r3   like_promptAsyncClient.like_promptB  s$      001B0NNNN   c                >   #    U R                  USS9I Sh  vN $  N7f)zUnlike a prompt.

Args:
    prompt_identifier (str): The identifier of the prompt.

Returns:
    Dict[str, int]: A dictionary with the key 'likes' and the count of likes as the value.

Fr  Nr  r  s     r3   unlike_promptAsyncClient.unlike_promptN  s$      001B0OOOOr  rt   Fdesc)rs   rr   	is_publicis_archived
sort_fieldsort_directionr   c          	     F  #    UUU(       a  SOUb  SOSU(       a  SOS[        U[        R                  5      (       a  UR                  OUUUU(       a  SOSS.nU R	                  SS[        U5      S9I Sh  vN n	[        R                  " S0 U	R                  5       D6$  N(7f)	a  List prompts with pagination.

Args:
    limit (int, default=100): The maximum number of prompts to return. Defaults to 100.
    offset (int, default=0): The number of prompts to skip. Defaults to 0.
    is_public (Optional[bool]): Filter prompts by if they are public.
    is_archived (Optional[bool]): Filter prompts by if they are archived.
    sort_field (PromptSortField): The field to sort by.
      Defaults to "updated_at".
    sort_direction (Literal["desc", "asc"], default="desc"): The order to sort by.
      Defaults to "desc".
    query (Optional[str]): Filter prompts by a search query.

Returns:
    ListPromptsResponse: A response object containing
    the list of prompts.
trueNfalse)rs   rr   r  r  r  r  r   match_prefixru   /repos/rv   r7   )r&   r   PromptSortFieldr  ro   _exclude_noneListPromptsResponserw   )
r*   rs   rr   r  r  r  r  r   rO   rm   s
             r3   list_promptsAsyncClient.list_promptsZ  s     : #I4It%06g j**D*DEE   ,&+F
" 449]6%: 5 
 
 --@@@
s   A4B!6B7)B!c                  #    [         R                  " U5      u  p#n U R                  SSU SU 35      I Sh  vN n[        R                  " S0 UR                  5       S   D6$  N+! [         R                   a     gf = f7f)a[  Get a specific prompt by its identifier.

Args:
    prompt_identifier (str): The identifier of the prompt.
        The identifier should be in the format "prompt_name" or "owner/prompt_name".

Returns:
    Optional[Prompt]: The prompt object.

Raises:
    requests.exceptions.HTTPError: If the prompt is not found or
        another error occurs.
ru   r  rs  Nrepor7   )r    r  ro   r   Promptrw   r_   r*   r  r  r  r  rm   s         r3   r  AsyncClient.get_prompt  s      !) @ @AR SA	!88q6 H $$?x}}v'>?? .. 		s8   B A& A$*A& #B $A& &A=:B <A==B rY  readmetagsr  c               *  #    U R                  5       I Sh  vN nU(       a'  UR                  (       d  [        R                  " S5      e[        R                  " U5      u  pxn	U R                  US9I Sh  vN (       d  U R                  SU5      I Sh  vN eUU=(       d    SU=(       d    SU=(       d    / US.n
U R                  SSU
S	9I Sh  vN nUR                  5         [        R                  " S0 UR                  5       S
   D6$  N N N{ NA7f)a  Create a new prompt.

Does not attach prompt object, just creates an empty prompt.

Args:
    prompt_identifier (str): The identifier of the prompt.
        The identifier should be in the formatof owner/name:hash, name:hash, owner/name, or name
    description (Optional[str]): A description of the prompt.
    readme (Optional[str]): A readme for the prompt.
    tags (Optional[Sequence[str]]): A list of tags for the prompt.
    is_public (bool): Whether the prompt should be public. Defaults to False.

Returns:
    Prompt: The created prompt object.

Raises:
    ValueError: If the current tenant is not the owner.
    HTTPError: If the server request fails.
NCannot create a public prompt without first
creating a LangChain Hub handle. You can add a handle by creating a public prompt at:
https://smith.langchain.com/prompts)r  zcreate a prompt )repo_handlerY  r  r  r  r}   r  r\  r  r7   )r  r  r    r  r  r  r  ro   r  r   r  rw   )r*   r  rY  r  r  r  r  r  r  r  rw   rm   s               r3   create_promptAsyncClient.create_prompt  s    8 ++--X33--6  !) @ @AR SA33%3@@@334EuMMN '&,"lJB"<
 44VYT4RR!!#  ;8==?6#:;;/ . AM SsF   DDAD4D5DD;DD<DDDDparent_commit_hashc               V  #    U R                  U5      I Sh  vN (       d  [        R                  " S5      e SSKJn  [        R                  " U5      nU" U5      n[        R                  " U5      n[        R                  " U5      u  pn
U SU	 3nUS:X  d  Uc  U R                  U5      I Sh  vN nX7S.nU R                  S	S
U 3US9I Sh  vN nUR                  5       S   S   nU R                  U SU 35      I Sh  vN $  N! [
         a    [        S5      ef = f Ns NU N#7f)a  Create a commit for an existing prompt.

Args:
    prompt_identifier (str): The identifier of the prompt.
    object (Any): The LangChain object to commit.
    parent_commit_hash (Optional[str]): The hash of the parent commit.
        Defaults to latest commit.

Returns:
    str: The url of the prompt commit.

Raises:
    HTTPError: If the server request fails.
    ValueError: If the prompt does not exist.
Nz0Prompt does not exist, you must create it first.r   )dumpszvThe client.create_commit function requires the langchain-corepackage to run.
Install with `pip install langchain-core`rs  rx  )parent_commitmanifestr}   r  r\  commitr  r  )r  r    r_   langchain_core.loadr  ImportErrorr#   prep_obj_for_pushrw   loadsr  r  ro   r  )r*   r  objectr  r  chain_to_pushjson_objectmanifest_dictr  r  r  r  request_dictrm   r  s                  r3   create_commitAsyncClient.create_commit  sX    , ))*;<<<11B 	1 "33F;M*

;/ ( @ @AR SA#(';- 8)-?-G'+'C'C%( " *<W44i 567l 5 
 
 mmoh/>))-B,C1[M*RSSSA =  	M 	"

 TsV   D)DD)D
 A1D)/D#0D)D%3D)D'D)
D  D)%D)'D))rY  r  r  r  r  c                 #    U R                  5       I Sh  vN nU(       a  UR                  (       d  [        S5      e0 nUb  X(S'   Ub  X8S'   Ub  XXS'   Ub  XhS'   Ub  XHS'   [        R                  " U5      u  pnU R                  SS	U	 S
U
 3US9I Sh  vN nUR                  5         UR                  5       $  N N&7f)a  Update a prompt's metadata.

To update the content of a prompt, use push_prompt or create_commit instead.

Args:
    prompt_identifier (str): The identifier of the prompt to update.
    description (Optional[str]): New description for the prompt.
    readme (Optional[str]): New readme for the prompt.
    tags (Optional[Sequence[str]]): New list of tags for the prompt.
    is_public (Optional[bool]): New public status for the prompt.
    is_archived (Optional[bool]): New archived status for the prompt.

Returns:
    Dict[str, Any]: The updated prompt data as returned by the server.

Raises:
    ValueError: If the prompt_identifier is empty.
    HTTPError: If the server request fails.
Nr  rY  r  r  r  r  r   r  rs  r\  )r  r  r   r    r  ro   r  rw   )r*   r  rY  r  r  r  r  r  rw   r  r  r  rm   s                r3   update_promptAsyncClient.update_prompt  s     : ++--X336  <>""-#N  )""-L ( @ @AR SA44wugQ{m44 5 
 
 	!!#}}7 ..
s"   B?B;A?B?B=%B?=B?c                  #    [         R                  " U5      u  p#nU R                  U5      I Sh  vN (       d  U R                  SU5      I Sh  vN eU R	                  SSU SU 35      I Sh  vN nUR                  5         g NT N7 N7f)zDelete a prompt.

Args:
    prompt_identifier (str): The identifier of the prompt to delete.

Returns:
    bool: True if the prompt was successfully deleted, False otherwise.

Raises:
    ValueError: If the current tenant is not the owner of the prompt.
Nzdelete a promptr   r  rs  )r    r  r  r  ro   r  r  s         r3   delete_promptAsyncClient.delete_promptJ  s      !) @ @AR SA33E:::334EuMMN44wa}5
 
 	!!# ;M
s3   .BBBBB/B	0BB	Binclude_modelc          
        #    [         R                  " U5      u  p4nU R                  SSU SU SU U(       a  SOS 35      I Sh  vN n[        R                  " S0 X4S.UR                  5       ED6$  N,7f)	zPull a prompt object from the LangSmith API.

Args:
    prompt_identifier (str): The identifier of the prompt.

Returns:
    PromptCommit: The prompt object.

Raises:
    ValueError: If no commits are found for the prompt.
ru   r  rs  z?include_model=truer  Nr  r  r7   )r    r  ro   r   PromptCommitrw   )r*   r  r  r  r  r  rm   s          r3   pull_prompt_commitAsyncClient.pull_prompt_commit_  s     " +3*J*J+
'K 44E7!K=+,9(rBD
 
 && 
FhmmoF
 	

s   AA4A2-A4rs   rr   r  c                #    [         R                  " U5      u  pVnUb  [        SU5      OUUUS.nSn	 X8S'   U R                  SSU SU S3US	9I Sh  vN n
U
R	                  5       nUS
   nUS   nU(       d  gU H/  nUb  X:  a    g[
        R                  " S0 XVS.UED67v   U	S-  n	M1     U[        U5      -  nX=:  a  gM   Nq7f)a  List commits for a given prompt.

Args:
    prompt_identifier (str): The identifier of the prompt in the format 'owner/repo_name'.
    limit (Optional[int]): The maximum number of commits to return. If None, returns all commits. Defaults to None.
    offset (int, default=0): The number of commits to skip before starting to return results. Defaults to 0.
    include_model (bool, default=False): Whether to include the model information in the commit data. Defaults to False.

Yields:
    A ListedPromptCommit object for each commit.

Note:
    This method uses pagination to retrieve commits. It will make multiple API calls if necessary to retrieve all commits
    or up to the specified limit.
Nrt   r  r   rr   ru   r  rs  rv   r  totalr  rQ   r7   )r    r  rF  ro   rw   r   ListedPromptCommitrx   )r*   r  rs   rr   r  r  r  r  rO   rV  rm   valrT   r  its                  r3   list_prompt_commitsAsyncClient.list_prompt_commits~  s    . !) @ @AR SA ).(9Se_u*

 %8!88E7!K=2 9  H
 --/C	NELE$ 33  %AbA  Q  c%j F/ s   ACCA2Cc          	       #     SSK Jn  SSKJn  SSKJn  SSKJn  SSKJ	n  SSK
JnJn	   SS	KJn
  U R%                  XS9I Sh  vN nU
" 5          U" [&        R(                  " UR*                  5      5      nSSS5        [-        WU5      (       d+  [-        X5      (       a  [-        UR.                  U5      (       a  [-        X5      (       a  UO8[-        X5      (       a'  [-        UR.                  U5      (       a  UR.                  OSnUc  [0        R2                  " S5      eUR4                  c  0 Ul        UR4                  R7                  UR8                  UR:                  UR<                  S.5        U(       Gay  [-        X5      (       Gah  [-        UR.                  U5      (       GaL  [?        UR@                  5      S:X  Ga2  [-        URB                  U5      (       Gd  [-        URB                  U5      (       a  [-        URB                  RD                  U5      (       a  [G        XR.                  URB                  RD                  -  5      n[?        UR@                  5      S:X  aU  UR@                  S   nU	" UR.                  URH                  " S0 0 URB                  RJ                  ED6URB                  5      nU$ Un U$ [-        URB                  U5      (       a  UR.                  URB                  -  nU$  U$ ! [         a    [        S5      ef = f! [         a    [         R"                  S
 5       n
 GNf = f GN! , (       d  f       GN= f7f)a  Pull a prompt and return it as a LangChain PromptTemplate.

This method requires `langchain-core <https://pypi.org/project/langchain-core/>`__.

Args:
    prompt_identifier (str): The identifier of the prompt.
    include_model (Optional[bool], default=False): Whether to include the model information in the prompt data.

Returns:
    Any: The prompt object in the specified format.
r   )BaseLanguageModel)r  )BaseOutputParser)BasePromptTemplate)StructuredPrompt)RunnableBindingRunnableSequenceztThe client.pull_prompt function requires the langchain-corepackage to run.
Install with `pip install langchain-core`)suppress_langchain_beta_warningc               3     #    S v   g 7frE   r7   r7   rI   r3   r  @AsyncClient.pull_prompt.<locals>.suppress_langchain_beta_warning  s     s   r  Nz-Prompt object is not a valid prompt template.)lc_hub_ownerlc_hub_repolc_hub_commit_hashrR   r   rQ   r7   )&#langchain_core.language_models.baser  langchain_core.load.loadr  langchain_core.output_parsersr  langchain_core.promptsr  !langchain_core.prompts.structuredr  langchain_core.runnables.baser  r  r  langchain_core._apir  
contextlibcontextmanagerr  rw   r  r  r&   firstr    ra   r"  updater  r  r  rx   stepslastboundr   bindrh   )r*   r  r  r  r  r  r  r  r  r  r  prompt_objectr  prompt_templateseqrebound_llms                   r3   pull_promptAsyncClient.pull_prompt  s    	M6FAJW	K #55 6 
 
 -.4::m&<&<=>F / v122&336<<);<< f99  "&;;"6<<1CDD LL   &--C  ''/+-($$++$1$7$7#0#5#5*7*C*C 6446<<)9:: FLL!Q&z&++GW/X/X &++77J!!#4= = +\\FKK<M<M-MNsyy>Q&"%))A,K-#((B+Afkk.@.@+ABF  !F  FKK):;;+1<<&+++E  _  	M 	  	&& '	
 /.s]   M&K2 L ML2M'L56I<M2LM L/+M.L//M5
M?M)r  r  r  rY  r  r  c               n  #    U R                  U5      I Sh  vN (       a5  [        S XEXg4 5       5      (       a  U R                  UUUUUS9I Sh  vN   O U R                  UUb  UOSUUUS9I Sh  vN   Uc  U R	                  US9I Sh  vN $ U R                  UUUS9I Sh  vN nU$  N N\ N= N% N7f)a  Push a prompt to the LangSmith API.

Can be used to update prompt metadata or prompt content.

If the prompt does not exist, it will be created.
If the prompt exists, it will be updated.

Args:
    prompt_identifier (str): The identifier of the prompt.
    object (Optional[Any]): The LangChain object to push.
    parent_commit_hash (str): The parent commit hash.
      Defaults to "latest".
    is_public (Optional[bool]): Whether the prompt should be public.
        If None (default), the current visibility status is maintained for existing prompts.
        For new prompts, None defaults to private.
        Set to True to make public, or False to make private.
    description (Optional[str]): A description of the prompt.
      Defaults to an empty string.
    readme (Optional[str]): A readme for the prompt.
      Defaults to an empty string.
    tags (Optional[Sequence[str]]): A list of tags for the prompt.
      Defaults to an empty list.

Returns:
    str: The URL of the prompt.
Nc              3  (   #    U  H  oS Lv   M
     g 7frE   r7   ).0params     r3   	<genexpr>*AsyncClient.push_prompt.<locals>.<genexpr>C  s      /UeT!/Us   r  F)r  rY  r  r  )r  r  )r  anyr  r  r  r  )	r*   r  r  r  r  rY  r  r  urls	            r3   push_promptAsyncClient.push_prompt  s    L $$%6777 09/U   ((% +!' )    $$!'0'<)%' %    >--@Q-RRR &&1 ' 
 

 
; 8 S
sW   B5B+8B5B- B51B/2B5B1B5$B3%B5-B5/B51B53B5)r   r   r   r   )NNNNN)
r+   Optional[str]r,   r-  r-   zWOptional[Union[int, tuple[Optional[int], Optional[int], Optional[int], Optional[int]]]]r.   zOptional[Mapping[str, Any]]r/   r-  )returnr   )r.  rF   )rf   rF   rg   rF   rh   r   r.  zhttpx.ResponserE   )ry   rF   rO   Optional[dict[str, Any]]r.  zAsyncIterator[dict[str, Any]])
ry   rF   r   Optional[dict]r   rF   r   rF   r.  zAsyncIterator[dict])r   rF   r   dict[str, Any]r   rF   r   r-  r   Optional[ls_client.ID_TYPE]rh   r   r.  None)r   ls_client.ID_TYPErh   r   r.  r3  )r   r4  r.  zls_schemas.Run)$r   z?Optional[Union[ls_client.ID_TYPE, Sequence[ls_client.ID_TYPE]]]r   z#Optional[Union[str, Sequence[str]]]r   r-  r   r2  r   r2  r   r-  r   r-  r   r-  r   r-  r   Optional[bool]r   r2  r   zOptional[datetime.datetime]r   r5  r   %Optional[Sequence[ls_client.ID_TYPE]]r   Optional[Sequence[str]]rs   Optional[int]rh   r   r.  zAsyncIterator[ls_schemas.Run])r   r4  r   r2  r.  rF   )r   r4  r.  bool)r   r4  r.  r-  )r   rF   rh   r   r.  ls_schemas.TracerSession)NN)r   r-  r   r2  r.  r:  )r   r-  r   r-  r.  r3  )r   rF   rh   r   r.  ls_schemas.Dataset)r   r-  r   r2  r.  r;  )r   r4  r.  r3  )rh   r   r.  z!AsyncIterator[ls_schemas.Dataset])NNN)r   r1  r	  r/  r   r2  r   r-  rh   r   r.  ls_schemas.Example)r  r4  r.  r<  )r   r2  r   r-  rh   r   r.  z!AsyncIterator[ls_schemas.Example])r   r2  r  rF   r  zOptional[float]r  Optional[Any]r  r-  rh   r   r.  ls_schemas.Feedback)r&  zUnion[str, uuid.UUID]r  zUnion[float, int, bool, None]r  z(Union[float, int, bool, str, dict, None]r!  zUnion[dict, None]r  zUnion[str, None]r"  r0  r.  r3  )r   r4  r/  rF   r+  z0Optional[datetime.datetime | datetime.timedelta]r,  z#Optional[ls_schemas.FeedbackConfig]r-  r2  r.  zls_schemas.FeedbackIngestToken)r-  r4  r.  r>  )r   r6  r/  r7  rC  z1Optional[Sequence[ls_schemas.FeedbackSourceType]]rs   r8  rh   r   r.  z"AsyncIterator[ls_schemas.Feedback])r-  ID_TYPEr.  r3  )
rN  zOptional[list[ID_TYPE]]r   r-  rO  r-  rs   r8  r.  z)AsyncIterator[ls_schemas.AnnotationQueue])r   rF   rY  r-  rZ  zOptional[ID_TYPE]r.  ls_schemas.AnnotationQueue)rZ  r?  r.  r@  )rZ  r?  r   rF   rY  r-  r.  r3  )rZ  r?  r.  r3  )rZ  r?  r   zlist[ID_TYPE]r.  r3  )rZ  r?  r   r?  r.  r3  )rZ  r?  ru  r'   r.  z%ls_schemas.RunWithAnnotationQueueInfo)r   r4  ry  rF   rh   r   r.  r3  )r   r4  rh   r   r.  r3  )r   dictrs   r'   r   r4  r   r-  rh   r   r.  zlist[ls_schemas.ExampleSearch])r.  zls_schemas.LangSmithSettings)r  rF   r.  r9  )r  rF   r  rF   r.  zls_utils.LangSmithUserError)rQ   r   )r  rF   rs   r'   rr   r'   r.  r-  )r  rF   r  r9  r.  dict[str, int])r  rF   r.  rF   )r  rF   r.  r9  )r  rF   r.  rB  )rs   r'   rr   r'   r  r5  r  r5  r  zls_schemas.PromptSortFieldr  zLiteral['desc', 'asc']r   r-  r.  zls_schemas.ListPromptsResponse)r  rF   r.  zOptional[ls_schemas.Prompt])r  rF   rY  r-  r  r-  r  r7  r  r9  r.  zls_schemas.Prompt)r  rF   r  r   r  r-  r.  rF   )r  rF   rY  r-  r  r-  r  r7  r  r5  r  r5  r.  r1  )r  rF   r.  r3  )r  rF   r  r5  r.  zls_schemas.PromptCommit)
r  rF   rs   r8  rr   r'   r  r9  r.  z3AsyncGenerator[ls_schemas.ListedPromptCommit, None])r  rF   r  r5  r.  r   )r  rF   r  r=  r  rF   r  r5  rY  r-  r  r-  r  r7  r.  rF   )K__name__
__module____qualname____firstlineno____doc__	__slots__r4   r9   r@   r<   propertyrG   rL   ro   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r)  r<  rA  rH  rL  rW  r]  ra  re  ri  rl  ro  rv  ls_beta	warn_betar}  r  r  r  r  r  r  r  r  r  r  r  r   r  
updated_atr  r  r  r  r  r  r  r  r!  r+  __static_attributes__r7   rI   r3   r   r      s
   >EI "&!%
 48!%!F!F !F
	!F 2!F !FF$ * * C C:
:
 :
 	:

 
:
~ ,0!! )! 
'	!2  $$00 	0
 0 0 
0H '+37

 
 	
 $
 1
 
 

0
!
 
 
	
1 <@"&04<@# $&*%)"&5926 $9=*.#)L
L :L  L .L :L L L $L #L  L 3L  0!L" #L$ 7%L& ('L( )L* +L, 
'-L^ UY:':6Q:	:< 
D.
;
; 
; 
"	
; '+260#0 00 
"	06 04QU
,
AN
	
0
5
5 
5 
	
5 '+26*#* 0* 
	*4
00 
+0 -126&*55 *5 0	5
 $5 5 
545 37&*	0 00 $	0
 0 
+0, "&#!%%6+%6 %6 	%6
 %6 %6 %6 
%6T 0436
 ;?(,$(#'36+36 -36
 836 &36 "36 !36 
36t HL?C37?A!?A ?A
 E?A =?A 1?A 
(?AB6,6	6 :>04RV# 7 .	
 P   
,86( .2"'+#+ ++ 	+
 %+ + 
3+b &*&*!
 !
 #	!

 $!
 
$!
FSS	#S MQ66*-6<I6	606 66-:6	6.66,36	6&HH+.H	.H* 
 	2 &2 	2
 2 
2 2@ 2 &2 	2
 
2 22  !%UU
 U &U U U 
(U Un
?

"%
	$
 IJ>%(>14>BE>	>*!$,0	.
.
)
O
P $(&+1;1K1K1V1V17#0A 0A 	0A
 "0A $0A /0A /0A 0A 
(0Ad6 &* $(,3<3< #	3<
 3< &3< 3< 
3<t -16T6T 6T
 *6T 
6Tx &* $(,$(&*88 #	8
 8 &8 "8 $8 
8t$2 ).	

 &	

 
!
F  $#66 	6
 6 6 
=6r JOd!$d8Fd	dT !%"*$(%) $(,CC 	C
  C "C #C C &C 
C CrI   r   c                b    U R                  5        VVs0 s H  u  pUc  M
  X_M     snn$ s  snnf )z&Exclude None values from a dictionary.)rT   )dri   rj   s      r3   r  r  b  s(    WWY8YTQ!DADY888s   	++)rO  rA  r.  rA  )$rG  
__future__r   rd   r  r7  rw   r   r   collections.abcr   r   r   r   typingr   r	   r
   r   r   r)   	langsmithr   r#   r   r   r   r    langsmith._internalr   rJ  r   rF   r?  r   r  r7   rI   r3   <module>rU     sb    ! "       L L   ) + ' :
		3
A AH:9rI   