
    Ngs                        d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZmZmZmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ  G d	 d
          ZdS )zThe Async LangSmith Client.    )annotationsN)
AnyAsyncIteratorDictListMappingOptionalSequenceTupleUnioncast)client)schemas)utils)_beta_decoratorc                     e Zd ZdZdZ	 	 	 	 	 dddZddZd Zd Ze	d             Z
e	dd            ZddZ	 dddZddd d!dd'Zddd(dd1Zdd4Zdd6Zddddddddddddddddd7ddNZddOddQZddSZddTZddVZ	 	 dddWZdddXddYZdd\Z	 	 ddd^Zdd_ZddaZ	 	 	 ddddZddfZdddgddiZ	 	 	 dddqZ 	 ddddddrdd{Z!dddd|ddZ"ddZ#dddddddZ$e%j&        dddd            Z'e%j&        dddd            Z(dS )AsyncClientz4Async Client for interacting with the LangSmith API.)_retry_config_client_web_urlNapi_urlOptional[str]api_key
timeout_msWOptional[Union[int, Tuple[Optional[int], Optional[int], Optional[int], Optional[int]]]]retry_configOptional[Mapping[str, Any]]web_urlc                   t          j        d           |pddi| _        ddi}t          j        |          }t          j        |          }|r||t          j        <   t          j        ||           t          |t                    r
|dz  dddf}n1t          |t                    rt          d |D                       }nd	}t          j        |||
          | _        || _        dS )zInitialize the async client.zClass AsyncClient is in beta.max_retries   zContent-Typezapplication/json  Nc                     g | ]}||dz  nd S )Nr"    ).0ts     R/var/www/html/ai-engine/env/lib/python3.11/site-packages/langsmith/async_client.py
<listcomp>z(AsyncClient.__init__.<locals>.<listcomp>=   s$    VVVa!-a$hhTVVV    
   )base_urlheaderstimeout)ls_beta
_warn_oncer   ls_utilsget_api_keyget_api_url	ls_client	X_API_KEY_validate_api_key_if_hosted
isinstanceinttuplehttpxr   r   r   )selfr   r   r   r   r   _headerstimeout_s           r'   __init__zAsyncClient.__init__"   s    	:;;;)?mQ-?.
 &w//&w// 	4,3HY()-gw???j#&& 	-7$->dD,QHH
E** 	VV:VVVWWHHH(h
 
 
  r)   returnc                
   K   | S )zEnter the async client.r$   r:   s    r'   
__aenter__zAsyncClient.__aenter__E   s      r)   c                >   K   |                                   d{V  dS )zExit the async client.N)aclose)r:   exc_typeexc_valexc_tbs       r'   	__aexit__zAsyncClient.__aexit__I   s,      kkmmr)   c                H   K   | j                                          d{V  dS )zClose the async client.N)r   rC   r@   s    r'   rC   zAsyncClient.acloseM   s2      l!!###########r)   c                4    t          | j        j                  S N)strr   r+   r@   s    r'   _api_urlzAsyncClient._api_urlQ   s    4<()))r)   rK   c                @    t          j        | j        | j                  S )zThe web host url.)r0   get_host_urlr   rL   r@   s    r'   	_host_urlzAsyncClient._host_urlU   s     $T]DMBBBr)   methodendpointkwargsr   httpx.Responsec                  K   t          t          | j                            dd                    }t	          |          D ]}	  | j        j        ||fi | d{V }t          j        |           |c S # t          j
        $ rT}||dz
  k    r$t          j        dt          |                     t          j        d|z             d{V  Y d}~d}~wt          j        $ rT}||dz
  k    r$t          j        dt          |                     t          j        d|z             d{V  Y d}~d}~ww xY wt          j        d          )	z(Make an async HTTP request with retries.r    r!   N   zHTTP error:    zRequest error: z0Unexpected error connecting to the LangSmith API)r   r7   r   getranger   requestr0   raise_for_status_with_textr9   HTTPStatusErrorLangSmithAPIErrorreprasynciosleepRequestErrorLangSmithConnectionError)r:   rP   rQ   rR   r    attemptresponsees           r'   _arequest_with_retriesz"AsyncClient._arequest_with_retriesZ   s      3 2 6 6}a H HII[)) 	0 	0G0!5!5fh!Q!Q&!Q!QQQQQQQ3H===( 0 0 0kAo--"45MDGG5M5MNNNmAwJ//////////////% 0 0 0kAo--";<WdSTgg<W<WXXXmAwJ//////////////0 (>
 
 	
s&   /A55D9A
CD9%A
D44D9pathparamsOptional[Dict[str, Any]]AsyncIterator[Dict[str, Any]]c               T  K   |pi }|                     dd          }|                     dd          |d<   	 ||d<   |                     d||           d{V }|                                }|sdS |D ]}|W V  t          |          |d         k     rdS |t          |          z  }s)	zGet a paginated list of items.offsetr   limitd   TGETrg   N)rW   re   jsonlen)r:   rf   rg   rk   rc   itemsitems          r'   _aget_paginated_listz AsyncClient._aget_paginated_lists   s       2Ha(( **Wc22w
	!%F8!88V8TTTTTTTTHMMOOE   




5zzF7O++c%jj F
	!r)   POSTruns)bodyrequest_methoddata_keyrw   Optional[dict]rx   ry   AsyncIterator[dict]c                K   |r|                                 ni }	 |                     ||t          j        |                     d{V }|                                }|sdS |                    |          sdS ||         D ]}|W V  |                    d          }	|	sdS |	                    d          sdS |	d         |d<   )z%Get a cursor paginated list of items.TcontentNcursorsnextcursor)copyre   r3   _dumps_jsonrp   rW   )
r:   rf   rw   rx   ry   params_rc   response_bodyrunr   s
             r'   _aget_cursor_paginated_listz'AsyncClient._aget_cursor_paginated_list   s      "&-$))+++2	0!88!-g66 9        H
 %MMOOM   $$X.. $X.  					#''	22G ;;v&&  'GH%	0r)   )project_namerevision_idnameinputsDict[str, Any]run_typer   r   Optional[ls_client.ID_TYPE]Nonec                  K   ||                     d          pt          j                    |||pt          j                    |d|}|                     ddt          j        |                     d{V  dS )zCreate a run.id)r   r   r   r   session_namer   ru   z/runsr}   N)rW   uuiduuid4r0   get_tracer_projectre   r3   r   )r:   r   r   r   r   r   rR   
run_creates           r'   
create_runzAsyncClient.create_run   s       **T""2djll (IH,G,I,I&
 
 

 ))GY%::%F%F * 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r)   run_idls_client.ID_TYPEc                   K   i |dt          j        |          i}|                     ddt          j        |           t          j        |                     d{V  dS )zUpdate a run.r   PATCH/runs/r}   N)r3   _as_uuidre   r   )r:   r   rR   datas       r'   
update_runzAsyncClient.update_run   s       <&;$	 26 : :;;))1Y'//11)$// * 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r)   ls_schemas.Runc                   K   |                      ddt          j        |                      d{V }t          j        di |                                S )zRead a run.rn   r   Nr$   )re   r3   r   
ls_schemasRunrp   )r:   r   rc   s      r'   read_runzAsyncClient.read_run   sr      441Y'//11
 
 
 
 
 
 
 
 ~00000r)   )
project_idr   r   trace_idreference_example_idqueryfiltertrace_filtertree_filteris_rootparent_run_id
start_timeerrorrun_idsselectrl   r   ?Optional[Union[ls_client.ID_TYPE, Sequence[ls_client.ID_TYPE]]]#Optional[Union[str, Sequence[str]]]r   r   r   r   r   r   r   Optional[bool]r   r   Optional[datetime.datetime]r   r   %Optional[Sequence[ls_client.ID_TYPE]]r   Optional[Sequence[str]]rl   Optional[int]AsyncIterator[ls_schemas.Run]c                 K   g }t          |t          j        t          f          r|                    |           n*t          |t
                    r|                    |           |Wt          |t                    r|g}t          j         fd|D               d{V }|                    d |D                        |r|nd||r|gnd||||	|
||r|	                                nd||||d|}|rd |D             |d<   d |
                                D             }d}                     d	|
          2 3 d{V }t          j        di |W V  |dz  }|	||k    r dS ,6 dS )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))',
            )
        Nc                <    g | ]}                     |           S )r   )read_project)r%   r   r:   s     r'   r(   z)AsyncClient.list_runs.<locals>.<listcomp>x  s*    PPP4$###66PPPr)   c                    g | ]	}|j         
S r$   )r   )r%   projects     r'   r(   z)AsyncClient.list_runs.<locals>.<listcomp>z  s    CCCw
CCCr)   )sessionr   reference_exampler   r   r   r   r   
parent_runr   r   r   tracer   c                P    g | ]#}t          t          j        |                    $S r$   rK   r3   r   r%   id_s     r'   r(   z)AsyncClient.list_runs.<locals>.<listcomp>  s8     % % %14I&s++,,% % %r)   r   c                    i | ]
\  }}|||S rJ   r$   )r%   kvs      r'   
<dictcomp>z)AsyncClient.list_runs.<locals>.<dictcomp>  s    EEEAq}1}}}r)   r   z/runs/query)rw   rU   r$   )r6   r   UUIDrK   appendlistextendr^   gather	isoformatrr   r   r   r   )r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   rR   project_idsprojects
body_queryrw   ixr   s   `                       r'   	list_runszAsyncClient.list_runs   s2     x j49c"233 	+z****
D)) 	+z***#,,, . ,~$^PPPP<PPP      H CC(CCCDDD '2;{{t *>H%&&D(&'4>H*..000D!&
 &
" #&

&  	% %8C% % %Jy! FE!1!1!3!3EEE99-d9SS 	 	 	 	 	 	 	#.''3''''''!GB R5[[	 TSSs   :E&)share_idr   c               r  K   t          j        |d          }t          |          t          |pt          j                              d}|                     dd| dt          j        |                     d{V }t          j        |           |	                                d         }| j
         d	| d
S )a  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)r3   r   rK   r   r   re   r   r0   rZ   rp   rO   )r:   r   r   run_id_r   rc   r   s          r'   	share_runzAsyncClient.share_run  s        $VX66'llx74:<<88
 
 44$W$$$)$// 5 
 
 
 
 
 
 
 

 	+H555mmoom4.99+9999r)   boolc                j   K   |                      t          j        |d                     d{V }|duS )z)Get share state for a run asynchronously.r   N)read_run_shared_linkr3   r   )r:   r   links      r'   run_is_sharedzAsyncClient.run_is_shared  sC      ..y/A&(/S/STTTTTTTT4r)   c                   K   |                      ddt          j        |d           d           d{V }t          j        |           |                                }|d|vrdS | j         d|d          dS )	aN  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.
        rn   r   r   r   Nr   r   r   )re   r3   r   r0   rZ   rp   rO   )r:   r   rc   results       r'   r   z AsyncClient.read_run_shared_link  s       44AY'99AAA
 
 
 
 
 
 
 
 	+H555>]&884.CC&*?CCCCr)   ls_schemas.TracerSessionc                   K   d|i|}|                      ddt          j        |                     d{V }t          j        di |                                S )zCreate a project.r   ru   	/sessionsr}   Nr$   )re   r3   r   r   TracerSessionrp   )r:   r   rR   r   rc   s        r'   create_projectzAsyncClient.create_project  s       //44K)>t)D)D 5 
 
 
 
 
 
 
 
 '::(--//:::r)   c                  K   |r2|                      ddt          j        |                      d{V }n2|r!|                      ddd|i           d{V }nt          d          |                                }t          |t                    r1|st          j        d| d	          t          j
        di |d
         S t          j
        di |S )zRead a project.rn   
/sessions/Nr   r   ro   2Either project_name or project_id must be providedzProject 
 not foundr   r$   )re   r3   r   
ValueErrorrp   r6   r   r0   LangSmithNotFoundErrorr   r   )r:   r   r   rc   r   s        r'   r   zAsyncClient.read_project  s?       		S!88DI$6z$B$BDD       HH  	S!88{FL+A 9        HH QRRR}}dD!! 	7 57|777   +66d1g666'//$///r)   )r   r   c                 K   ||t          d          |0|                     |           d{V }t          |j                  }|st          d          |                     ddt          j        |                      d{V  dS )a  Delete 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   rK   r   re   r3   r   )r:   r   r   r   s       r'   delete_projectzAsyncClient.delete_project  s       ,"6QRRR --<-HHHHHHHHGWZJ 	20111))9+J7799
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r)   dataset_namels_schemas.Datasetc                   K   d|i|}|                      ddt          j        |                     d{V }t          j        di |                                S )zCreate a dataset.r   ru   	/datasetsr}   Nr$   )re   r3   r   r   Datasetrp   )r:   r   rR   r   rc   s        r'   create_datasetzAsyncClient.create_dataset  s       //44K)>t)D)D 5 
 
 
 
 
 
 
 
 !44HMMOO444r)   
dataset_idc                  K   |r2|                      ddt          j        |                      d{V }n2|r!|                      ddd|i           d{V }nt          d          |                                }t          |t                    r1|st          j        d| d	          t          j
        di |d
         S t          j
        di |S )zRead a dataset.rn   
/datasets/Nr   r   ro   z2Either dataset_name or dataset_id must be providedzDataset r   r   r$   )re   r3   r   r   rp   r6   r   r0   r   r   r   )r:   r   r   rc   r   s        r'   read_datasetzAsyncClient.read_dataset  s?       		S!88DI$6z$B$BDD       HH  	S!88{FL+A 9        HH QRRR}}dD!! 	1 57|777   %00Q000!))D)))r)   c                l   K   |                      ddt          j        |                      d{V  dS )zDelete a dataset.r   r   N)re   r3   r   )r:   r   s     r'   delete_datasetzAsyncClient.delete_dataset9  s_      ))9+J7799
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r)   !AsyncIterator[ls_schemas.Dataset]c               r   K   |                      d|          2 3 d{V }t          j        di |W V  6 dS )zList datasets.r   ro   Nr$   )rt   r   r   )r:   rR   datasets      r'   list_datasetszAsyncClient.list_datasets@  sr      
 "66{66RR 	0 	0 	0 	0 	0 	0 	0'$//w/////// SRRs   6outputsls_schemas.Examplec                F  K   ||t          d          |#|                     |           d{V }|j        }||t          |          d|}|                     ddt          j        |                     d{V }t          j        di |	                                S )	zCreate an example.Nz2Either dataset_id or dataset_name must be providedr   )r   r  r   ru   	/examplesr}   r$   )
r   r   r   rK   re   r3   r   r   Examplerp   )	r:   r   r  r   r   rR   r  r   rc   s	            r'   create_examplezAsyncClient.create_exampleH  s       ,"6QRRR --<-HHHHHHHHG J j//
 
 	
 44K)>t)D)D 5 
 
 
 
 
 
 
 
 !44HMMOO444r)   
example_idc                   K   |                      ddt          j        |                      d{V }t          j        di |                                S )zRead an example.rn   z
/examples/Nr$   )re   r3   r   r   r
  rp   )r:   r  rc   s      r'   read_examplezAsyncClient.read_exampleb  ss      44@	 2: > >@@
 
 
 
 
 
 
 
 !44HMMOO444r)   )r   r   !AsyncIterator[ls_schemas.Example]c                K   |                                 }|rt          j        |          |d<   n(|r&|                     |           d{V }|j        |d<   |                     d|          2 3 d{V }t          j        di |W V  6 dS )zList examples.r  r  Nr	  ro   r$   )r   r3   r   r   r   rt   r   r
  )r:   r   r   rR   rg   r  examples          r'   list_exampleszAsyncClient.list_examplesi  s        	+ ) 2: > >F9 	+ --<-HHHHHHHHG '
F9!66{66RR 	0 	0 	0 	0 	0 	0 	0'$//w/////// SRRs   0BkeyscoreOptional[float]valueOptional[Any]commentls_schemas.Feedbackc                   K   t          j        |d          ||||d|}|                     ddt          j        |                     d{V }t	          j        di |                                S )	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   r  r  r  r  ru   	/feedbackr}   Nr$   )r3   _ensure_uuidre   r   r   Feedbackrp   )	r:   r   r  r  r  r  rR   r   rc   s	            r'   create_feedbackzAsyncClient.create_feedback{  s      6  ,VFFF
 
 
 44K)>t)D)D 5 
 
 
 
 
 
 
 
 "55X]]__555r)   )r  
correctionr  metadatatoken_or_urlUnion[str, uuid.UUID]Union[float, int, bool, None](Union[float, int, bool, str, dict, None]r   Union[dict, None]Union[str, None]r!  c               @  K   t          j        || j        d          \  }}|| j        k    rt          d|           |                     ddt          j        |           t          j        |||||d                     d{V }	t          j        |	           dS )	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.
        rU   )	num_partszInvalid source API URL. ru   z/feedback/tokens/)r  r  r   r  r!  r}   N)	r3   _parse_token_or_urlrL   r   re   r   r   r0   rZ   )
r:   r"  r  r  r   r  r!  source_api_url
token_uuidrc   s
             r'   create_feedback_from_tokenz&AsyncClient.create_feedback_from_token  s      @ &/%B$-1&
 &
 &
"
 T]**HHHIII44@	 2: > >@@)""",& ( 	 	 5 
 
 
 
 
 
 
 
 	+H55555r)   )
expirationfeedback_configfeedback_idfeedback_keyr.  0Optional[datetime.datetime | datetime.timedelta]r/  #Optional[ls_schemas.FeedbackConfig]r0  ls_schemas.FeedbackIngestTokenc               r  K   ||||pt          t          j                              d}|t          j        ddd          |d<   nt          |t          j                  r|                                |d<   nmt          |t          j                  r3t          j        |j	        |j
        dz  |j
        dz  d	z            |d<   n t          d
t          |           d          |                     ddt          j        |                     d{V }t          j        di |                                S )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   r1  r/  r   Nr   r!   )dayshoursminutes
expires_in
expires_ati  <   zInvalid expiration type: z3. Expected datetime.datetime or datetime.timedelta.ru   z/feedback/tokensr}   r$   )rK   r   r   r   TimeDeltaInputr6   datetimer   	timedeltar6  secondsr   typere   r3   r   FeedbackIngestTokenrp   )r:   r   r1  r.  r/  r0  rw   rc   s           r'   create_presigned_feedback_tokenz+AsyncClient.create_presigned_feedback_token  s     B (.2TZ\\!2!2	 
  
 !+!:" " "D
 
H$566 	!+!5!5!7!7D
H$677 
	!+!:_ (D0#+d2r9" " "D DD,<,< D D D  
 44)$// 5 
 
 
 
 
 
 
 

 -@@@@@r)   c                   K   |                      ddt          j        |                      d{V }t          j        di |                                S )zRead feedback.rn   z
/feedback/Nr$   )re   r3   r   r   r  rp   )r:   r0  rc   s      r'   read_feedbackzAsyncClient.read_feedback  su       44A	 2; ? ?AA
 
 
 
 
 
 
 
 "55X]]__555r)   )r   r1  feedback_source_typerl   rE  1Optional[Sequence[ls_schemas.FeedbackSourceType]]"AsyncIterator[ls_schemas.Feedback]c                 K   |rd |D             nd|t          |d          ndd|}|||d<   |||d<   d}|                     d|	          2 3 d{V }t          j        di |W V  |d
z  }|	||k    r dS ,6 dS )zList feedback.c                P    g | ]#}t          t          j        |                    $S r$   r   r   s     r'   r(   z-AsyncClient.list_feedback.<locals>.<listcomp>-  s+    AAA#Y',,--AAAr)   Nrm   )r   rl   r  sourcer   r  ro   rU   r$   )minrt   r   r  )	r:   r   r1  rE  rl   rR   rg   r   feedbacks	            r'   list_feedbackzAsyncClient.list_feedback!  s       FMVAAAAAARV(-(9S___s	
 

 
 #(F5M+3F8"77F7SS 	 	 	 	 	 	 	(%11111111!GB R5[[	 TSSs   A=latest)tagrO  c                  K   t          j        |d          }|                     dd| dt          j        d|i|                     d{V }t	          j        |           dS )a1  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   ru   r   z/indexrO  r}   N)r3   r   re   r   r0   rZ   )r:   r   rO  rR   resps        r'   index_datasetzAsyncClient.index_dataset=  s      2 '
LAA
00++++)5#*@*@AA 1 
 
 
 
 
 
 
 

 	+D11111r)   )r   dictr7   List[ls_schemas.ExampleSearch]c         	     n  K   t          j        |d          }||d|}|r||d<   |                     dd| dt          j        |                     d{V }t	          j        |           g }|                                d	         D ]*}	|                    t          j	        d
i |	d|i           +|S )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   rl   r   ru   r   z/searchr}   Nexamplesr$   )
r3   r   re   r   r0   rZ   rp   r   r   ExampleSearch)
r:   r   rl   r   r   rR   reqrQ  rV  exs
             r'   similar_exampleszAsyncClient.similar_examples^  s     H '
LAA

 
 

  	#"CM00,,,,)#.. 1 
 
 
 
 
 
 
 

 	+D111))++j) 	S 	SBOOJ4QQrQQjQQQRRRRr)   )NNNNN)
r   r   r   r   r   r   r   r   r   r   )r>   r   )r>   rK   )rP   rK   rQ   rK   rR   r   r>   rS   rJ   )rf   rK   rg   rh   r>   ri   )
rf   rK   rw   rz   rx   rK   ry   rK   r>   r{   )r   rK   r   r   r   rK   r   r   r   r   rR   r   r>   r   )r   r   rR   r   r>   r   )r   r   r>   r   )$r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rl   r   rR   r   r>   r   )r   r   r   r   r>   rK   )r   r   r>   r   )r   r   r>   r   )r   rK   rR   r   r>   r   )NN)r   r   r   r   r>   r   )r   r   r   r   r>   r   )r   rK   rR   r   r>   r   )r   r   r   r   r>   r   )r   r   r>   r   )rR   r   r>   r  )NNN)r   r   r  rh   r   r   r   r   rR   r   r>   r  )r  r   r>   r  )r   r   r   r   rR   r   r>   r  )r   r   r  rK   r  r  r  r  r  r   rR   r   r>   r  )r"  r#  r  r$  r  r%  r   r&  r  r'  r!  rz   r>   r   )r   r   r1  rK   r.  r2  r/  r3  r0  r   r>   r4  )r0  r   r>   r  )r   r   r1  r   rE  rF  rl   r   rR   r   r>   rG  )r   r   rO  rK   rR   r   r>   r   )r   rS  rl   r7   r   r   r   r   rR   r   r>   rT  ))__name__
__module____qualname____doc__	__slots__r=   rA   rG   rC   propertyrL   rO   re   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r-  rB  rD  rM  r.   	warn_betarR  rZ  r$   r)   r'   r   r      sb       >>8I "&!%
 48!%!  !  !  !  ! F     $ $ $ * * X* C C C XC
 
 
 
8 ,0! ! ! ! !2  $$0 0 0 0 0 0H '+37
 
 
 
 
 
0
 
 
 
1 1 1 1 <@"&04<@# $&*%)"&5926 $9=*.#)F F F F F FR UY: : : : : :<       
D D D D.
; 
; 
; 
; '+260 0 0 0 06 04QU
 
 
 
 
 
0
5 
5 
5 
5 '+26* * * * *4
 
 
 
0 0 0 0 -126&*5 5 5 5 545 5 5 5 37&*	0 0 0 0 0 0, "&#!%%6 %6 %6 %6 %6T 0436
 ;?(,$(#'36 36 36 36 36 36t HL?C37?A ?A ?A ?A ?A ?AB6 6 6 6 :>04RV#     8 
 	2 2 2 2 2 2@  !%U U U U U U U Ur)   r   )r^  
__future__r   r^   r=  r   typingr   r   r   r   r   r	   r
   r   r   r   r9   	langsmithr   r3   r   r   r   r0   langsmith._internalr   r.   r   r$   r)   r'   <module>rf     s?   ! ! " " " " " "                            ) ) ) ) ) ) + + + + + + ' ' ' ' ' ' : : : : : :W W W W W W W W W Wr)   