o
    Zh&                    @  s   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZ ddl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 eejef Z G d
d dZ!dddZ"dS )zThe Async LangSmith Client.    )annotationsN)AsyncGeneratorAsyncIteratorMappingSequence)AnyLiteralOptionalUnioncast)client)schemas)utils)_beta_decoratorc                   @  st  e Zd ZdZdZ					d#d$ddZd%ddZdd Zdd Ze	dd Z
e	d&ddZd'dd Z	d(d)d%d&Zdd'd(d)d*d/d0Zddd1d+d:d;Zd,d>d?Zd-dAdBZdddddddddddddddddCd.dZd[Zdd\d/d^d_Zd0dadbZd1dcddZd2dfdgZ		d3d4dhdiZdddjd5dkdlZd6dodpZ		d3d7drdsZd8dtduZd9dwdxZ			d:d;d{d|Zd<d~dZdddd=ddZ			d:d>ddZ 	d(dddddd?ddZ!ddddd@ddZ"dAddZ#ddddddBddZ$dCddZ%ddddddDddZ&ddddEddZ'dFddZ(dddGddZ)dHddZ*dIddĄZ+dJddƄZ,dKdd˄Z-e.j/dd͜dLddЄZ0e.j/dMdd҄Z1e.j/ddӜdNddׄZ2dOddڄZ3dPdd݄Z4dQddZ5	dRdSddZ6dTddZ7dUddZ8dVddZ9dWddZ:dWddZ;dddde<j=j>ddddXd dZ?dYddZ@ddddddZd	d
ZAddd[ddZBddddddd\ddZCd]ddZDddd^ddZEddddd_ddZFddd`ddZGddddddd dad!d"ZHdS (b  AsyncClientz4Async Client for interacting with the LangSmith API.)_retry_config_client_web_url	_settingsN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                 C  s   |pddi| _ ddi}t|}t|}|r||tj< t|| t|tr0|d dddf}nt|t	r?t	dd |D }nd	}t
j|||d
| _|| _d| _dS )zInitialize the async client.max_retries   zContent-Typeapplication/json  Nc                 S  s    g | ]}|d ur|d nd qS )Nr     ).0tr!   r!   M/var/www/html/lang_env/lib/python3.10/site-packages/langsmith/async_client.py
<listcomp><   s     z(AsyncClient.__init__.<locals>.<listcomp>
   )base_urlheaderstimeout)r   ls_utilsZget_api_keyZget_api_url	ls_clientZ	X_API_KEYZ_validate_api_key_if_hosted
isinstanceinttuplehttpxr   r   r   r   )selfr   r   r   r   r   _headersZtimeout_r!   r!   r$   __init__"   s$   





zAsyncClient.__init__returnc                   s   | S )zEnter the async client.r!   r0   r!   r!   r$   
__aenter__E   s   zAsyncClient.__aenter__c                   s   |   I dH  dS )zExit the async client.N)aclose)r0   exc_typeexc_valexc_tbr!   r!   r$   	__aexit__I   s   zAsyncClient.__aexit__c                   s   | j  I dH  dS )zClose the async client.N)r   r6   r4   r!   r!   r$   r6   M   s   zAsyncClient.aclosec                 C  s   t | jjS N)strr   r'   r4   r!   r!   r$   _api_urlQ   s   zAsyncClient._api_urlr<   c                 C  s   t | j| jS )zThe web host url.)r*   Zget_host_urlr   r=   r4   r!   r!   r$   	_host_urlU   s   zAsyncClient._host_urlmethodendpointkwargsr   httpx.Responsec           
        s  t t| jdd}d|v r |d }dd | D }||d< t|D ]}z| jj||fi |I dH }t	| |W   S  t
jy }	 z||jdkr\td| d	| d
t|	 |jdkrktd| | |jdkr}td| dt|	 |jdkrtd| dt|	 |jdkrtd| dt|	 |jdkrtd| dt|	 td| d	| d
t|	 d}	~	w t
jy }	 z ||d krtdt|	 td| I dH  W Y d}	~	q$d}	~	ww td)z(Make an async HTTP request with retries.r   r   paramsc                 S     i | ]\}}|d ur||qS r;   r!   r"   kvr!   r!   r$   
<dictcomp>g       z6AsyncClient._arequest_with_retries.<locals>.<dictcomp>Ni  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/   ZHTTPStatusErrorstatus_codeZLangSmithAPIErrorreprZLangSmithRequestTimeoutZLangSmithRateLimitErrorZLangSmithAuthErrorLangSmithNotFoundErrorZLangSmithConflictErrorLangSmithErrorRequestErrorZLangSmithConnectionErrorasynciosleep)
r0   r?   r@   rA   r   rC   Zfiltered_paramsattemptresponseer!   r!   r$   _arequest_with_retriesZ   sj   







 z"AsyncClient._arequest_with_retriespathrC   Optional[dict[str, Any]]AsyncIterator[dict[str, Any]]c                 C s   |pi }| dd}| dd|d< 	 ||d< | jd||dI dH }| }|s+dS |D ]}|V  q-t||d k r=dS |t|7 }q)	zGet a paginated list of items.offsetr   limitd   TGETrC   N)rM   r\   jsonlen)r0   r]   rC   r`   rZ   rN   itemr!   r!   r$   _aget_paginated_list   s    z AsyncClient._aget_paginated_listPOSTruns)bodyrequest_methoddata_keyrk   Optional[dict]rl   rm   AsyncIterator[dict]c          
      C s   |r|  ni }	 | j||t|dI dH }| }|s dS ||s'dS || D ]}|V  q+|d}	|	s:dS |	dsAdS |	d |d< q
)z%Get a cursor paginated list of items.TcontentNcursorsnextcursor)copyr\   r+   _dumps_jsonre   rM   )
r0   r]   rk   rl   rm   Zparams_rZ   Zresponse_bodyrunrr   r!   r!   r$   _aget_cursor_paginated_list   s,   	


z'AsyncClient._aget_cursor_paginated_list)project_namerevision_idnameinputsdict[str, Any]run_typery   rz   Optional[ls_client.ID_TYPE]Nonec                  sN   || dp
t |||pt |d|}| jddt|dI dH  dS )zCreate a run.id)r{   r   r|   r~   Zsession_namerz   ri   /runsrp   N)rM   uuiduuid4r*   Zget_tracer_projectr\   r+   rv   )r0   r{   r|   r~   ry   rz   rA   Z
run_creater!   r!   r$   
create_run   s   
	zAsyncClient.create_runrun_idls_client.ID_TYPEc                   sD   i |dt |i}| jddt | t |dI dH  dS )zUpdate a run.r   PATCH/runs/rp   N)r+   _as_uuidr\   rv   )r0   r   rA   datar!   r!   r$   
update_run   s   zAsyncClient.update_runls_schemas.Runc                   4   |  ddt| I dH }tjdi | S )zRead a run.rc   r   Nr!   )r\   r+   r   
ls_schemasRunre   )r0   r   rZ   r!   r!   r$   read_run   s   
zAsyncClient.read_run)
project_idry   r~   trace_idreference_example_idqueryfiltertrace_filtertree_filteris_rootparent_run_id
start_timeerrorrun_idsselectra   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]]ra   Optional[int]AsyncIterator[ls_schemas.Run]c                 sB  g }t |tjtfr|| n
t |tr|| |dur@t |tr'|g}tj fdd|D  I dH }|dd |D  |rD|nd||rK|gnd||||	|
||rX|	 nd||||d|}|rmdd |D |d< dd	 |
 D }d
} jd|d2 z3 dH W }tjdi |V  |d7 }|dur||kr dS q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                   s   g | ]} j |d qS )ry   )read_project)r"   r{   r4   r!   r$   r%     s    z)AsyncClient.list_runs.<locals>.<listcomp>c                 S  s   g | ]}|j qS r!   )r   )r"   projectr!   r!   r$   r%     s    )sessionr~   Zreference_exampler   r   r   r   r   Z
parent_runr   r   r   tracer   c                 S     g | ]	}t t|qS r!   r<   r+   r   r"   id_r!   r!   r$   r%     s    r   c                 S  rD   r;   r!   rE   r!   r!   r$   rH     rI   z)AsyncClient.list_runs.<locals>.<dictcomp>r   z/runs/query)rk   rK   r!   )r,   r   UUIDr<   appendlistextendrW   Zgather	isoformatrN   rx   r   r   )r0   r   ry   r~   r   r   r   r   r   r   r   r   r   r   r   r   ra   rA   Zproject_idsZprojectsZ
body_queryrk   ixrw   r!   r4   r$   	list_runs   sX    





zAsyncClient.list_runs)share_idr   c                  st   t |d}t|t|pt d}| jdd| dt |dI dH }t| |	 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   /sharerp   Nr   /public//r)r+   r   r<   r   r   r\   rv   r*   rQ   re   r>   )r0   r   r   Zrun_id_r   rZ   r   r!   r!   r$   	share_run  s   

zAsyncClient.share_runboolc                   s"   |  t|dI dH }|duS )z)Get share state for a run asynchronously.r   N)read_run_shared_linkr+   r   )r0   r   linkr!   r!   r$   run_is_shared  s   zAsyncClient.run_is_sharedc                   s`   |  ddt|d dI dH }t| | }|du s#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.
        rc   r   r   r   Nr   r   r   )r\   r+   r   r*   rQ   re   r>   )r0   r   rZ   resultr!   r!   r$   r     s   

z AsyncClient.read_run_shared_linkls_schemas.TracerSessionc                   >   d|i|}| j ddt|dI dH }tjdi | S )zCreate a project.r{   ri   	/sessionsrp   Nr!   )r\   r+   rv   r   TracerSessionre   )r0   ry   rA   r   rZ   r!   r!   r$   create_project     zAsyncClient.create_projectc                      |r|  ddt| I dH }n|r#| j ddd|idI dH }ntd| }t|trE|s;td| d	t	j
di |d
 S t	j
di |S )zRead a project.rc   
/sessions/Nr   r{   rd   2Either project_name or project_id must be providedzProject 
 not foundr   r!   )r\   r+   r   
ValueErrorre   r,   r   r*   rT   r   r   )r0   ry   r   rZ   r   r!   r!   r$   r     $   


zAsyncClient.read_project)ry   r   c                  sl   |du r|du rt d|du r| j|dI dH }t|j}|s%t d| ddt| I dH  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   r<   r   r\   r+   r   )r0   ry   r   r   r!   r!   r$   delete_project  s   
zAsyncClient.delete_projectdataset_namels_schemas.Datasetc                   r   )zCreate a dataset.r{   ri   	/datasetsrp   Nr!   )r\   r+   rv   r   Datasetre   )r0   r   rA   r   rZ   r!   r!   r$   create_dataset6  r   zAsyncClient.create_dataset
dataset_idc                   r   )zRead a dataset.rc   
/datasets/Nr   r{   rd   z2Either dataset_name or dataset_id must be providedzDataset r   r   r!   )r\   r+   r   r   re   r,   r   r*   rT   r   r   )r0   r   r   rZ   r   r!   r!   r$   read_datasetB  r   zAsyncClient.read_datasetc                   s$   |  ddt| I dH  dS )zDelete a dataset.r   r   N)r\   r+   r   )r0   r   r!   r!   r$   delete_dataset\  s
   zAsyncClient.delete_dataset!AsyncIterator[ls_schemas.Dataset]c                 K s6   | j d|d2 z3 dH W }tjdi |V  q6 dS )zList datasets.r   rd   Nr!   )rh   r   r   )r0   rA   datasetr!   r!   r$   list_datasetsc  s   zAsyncClient.list_datasetsoutputsls_schemas.Examplec           	        s~   |du r|du rt d|du r| j|dI dH }|j}||t|d|}| jddt|dI dH }tjdi |	 S )	zCreate an example.Nz2Either dataset_id or dataset_name must be providedr   )r|   r   r   ri   	/examplesrp   r!   )
r   r   r   r<   r\   r+   rv   r   Examplere   )	r0   r|   r   r   r   rA   r   r   rZ   r!   r!   r$   create_examplek  s    	zAsyncClient.create_example
example_idc                   r   )zRead an example.rc   z
/examples/Nr!   )r\   r+   r   r   r   re   )r0   r   rZ   r!   r!   r$   read_example  s
   
zAsyncClient.read_example)r   r   !AsyncIterator[ls_schemas.Example]c                K sr   |  }|rt||d< n|r| j|dI dH }|j|d< | jd|d2 z3 dH W }tjdi |V  q&6 dS )zList examples.r   r   Nr   rd   r!   )ru   r+   r   r   r   rh   r   r   )r0   r   r   rA   rC   r   exampler!   r!   r$   list_examples  s   
zAsyncClient.list_exampleskeyscoreOptional[float]valueOptional[Any]commentls_schemas.Feedbackc           	        sP   t j|dd||||d|}| jddt |dI dH }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)Zaccept_null)r   r   r   r   r   ri   	/feedbackrp   Nr!   )r+   Z_ensure_uuidr\   rv   r   Feedbackre   )	r0   r   r   r   r   r   rA   r   rZ   r!   r!   r$   create_feedback  s   zAsyncClient.create_feedback)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          
        sr   t j|| jdd\}}|| jkrtd| | jddt | t |||||ddI dH }	t|	 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.
        rK   )Z	num_partszInvalid source API URL. ri   z/feedback/tokens/)r   r   r   r   r   rp   N)	r+   Z_parse_token_or_urlr=   r   r\   r   rv   r*   rQ   )
r0   r   r   r   r   r   r   Zsource_api_urlZ
token_uuidrZ   r!   r!   r$   create_feedback_from_token  s&    

z&AsyncClient.create_feedback_from_token)
expirationfeedback_configfeedback_idfeedback_keyr   0Optional[datetime.datetime | datetime.timedelta]r   #Optional[ls_schemas.FeedbackConfig]r   ls_schemas.FeedbackIngestTokenc                  s   ||||pt t d}|du rtjdddd|d< n1t|tjr*| |d< n$t|tjrDtj|j	|j
d |j
d d	 d|d< n
td
t| d| jddt|dI dH }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   r   r   r   Nr   r   )dayshoursminutesZ
expires_inZ
expires_ati  <   zInvalid expiration type: z3. Expected datetime.datetime or datetime.timedelta.ri   z/feedback/tokensrp   r!   )r<   r   r   r   ZTimeDeltaInputr,   datetimer   	timedeltar  secondsr   typer\   r+   rv   ZFeedbackIngestTokenre   )r0   r   r   r   r   r   rk   rZ   r!   r!   r$   create_presigned_feedback_token  s:   !z+AsyncClient.create_presigned_feedback_tokenc                   r   )zRead feedback.rc   
/feedback/Nr!   )r\   r+   r   r   r   re   r0   r   rZ   r!   r!   r$   read_feedback;  s
   
zAsyncClient.read_feedback)r   r   feedback_source_typera   r  1Optional[Sequence[ls_schemas.FeedbackSourceType]]"AsyncIterator[ls_schemas.Feedback]c          	      K s   |r
dd |D nd|durt |dndd|}|dur"||d< |dur*||d< d}| jd	|d
2 z3 dH W }tjdi |V  |d7 }|durQ||krQ dS q36 dS )zList feedback.c                 S  r   r!   r   r   r!   r!   r$   r%   P  s    z-AsyncClient.list_feedback.<locals>.<listcomp>Nrb   )rw   ra   r   sourcer   r   rd   rK   r!   )minrh   r   r   )	r0   r   r   r  ra   rA   rC   r   feedbackr!   r!   r$   list_feedbackD  s$   zAsyncClient.list_feedbackID_TYPEc                   s0   |  ddt|d I dH }t| dS )zDelete a feedback by ID.

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

        Returns:
            None
        r   r  r   Nr\   r+   r   r*   rQ   r  r!   r!   r$   delete_feedback`  s
   

zAsyncClient.delete_feedback)	queue_idsr{   name_containsra   r  Optional[list[ID_TYPE]]r  )AsyncIterator[ls_schemas.AnnotationQueue]c                C s   |durdd t |D nd|||durt|dndd}d}| jd|d2 z3 dH W }tjd
i |V  |d	7 }|durE||krE dS q'6 dS )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.
        Nc                 S  s$   g | ]\}}t |d | dqS )z
queue_ids[])r+   r   r"   ir   r!   r!   r$   r%     s    z6AsyncClient.list_annotation_queues.<locals>.<listcomp>rb   )Zidsr{   r  ra   r   /annotation-queuesrd   rK   r!   )	enumerater  rh   r   AnnotationQueue)r0   r  r{   r  ra   rC   r   r  r!   r!   r$   list_annotation_queuesq  s(   z"AsyncClient.list_annotation_queues)descriptionqueue_idr#  r$  Optional[ID_TYPE]ls_schemas.AnnotationQueuec                  sh   |||durt |nt t d}| jdddd | D dI dH }t| tjdi |	 S )	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{   r#  r   ri   r  c                 S  rD   r;   r!   rE   r!   r!   r$   rH     rI   z7AsyncClient.create_annotation_queue.<locals>.<dictcomp>re   r!   )
r<   r   r   r\   rN   r*   rQ   r   r!  re   )r0   r{   r#  r$  rk   rZ   r!   r!   r$   create_annotation_queue  s   
z#AsyncClient.create_annotation_queuec                   s   | j |gd I dH S )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.
        )r  N)r"  	__anext__)r0   r$  r!   r!   r$   read_annotation_queue  s   z!AsyncClient.read_annotation_queue)r#  c                  s:   | j ddt|d ||ddI dH }t| dS )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/r$  )r{   r#  r'  Nr  )r0   r$  r{   r#  rZ   r!   r!   r$   update_annotation_queue  s   z#AsyncClient.update_annotation_queuec                   s@   | j ddt|d ddi| jjdI dH }t| dS )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   r+  r$  Acceptr   )r(   N)r\   r+   r   r   r(   r*   rQ   )r0   r$  rZ   r!   r!   r$   delete_annotation_queue  s   	z#AsyncClient.delete_annotation_queuelist[ID_TYPE]c                  sD   | j ddt|d ddd t|D dI dH }t| dS )	a7  Add 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
        ri   r+  r$  r   c              	   S  s(   g | ]\}}t t|d | dqS )zrun_ids[r  r   r  r!   r!   r$   r%     s    z<AsyncClient.add_runs_to_annotation_queue.<locals>.<listcomp>r'  N)r\   r+   r   r   r*   rQ   )r0   r$  r   rZ   r!   r!   r$   add_runs_to_annotation_queue  s   z(AsyncClient.add_runs_to_annotation_queuec             
     s>   |  ddt|d dt|d I dH }t| dS )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   r+  r$  r   r   Nr  )r0   r$  r   rZ   r!   r!   r$    delete_run_from_annotation_queue  s   
z,AsyncClient.delete_run_from_annotation_queueindexr-   %ls_schemas.RunWithAnnotationQueueInfoc                  sP   dt |d d}| d| d| I dH }t| tjdi | S )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.
        r+  r$  z/runrc   /Nr!   )r+   r   r\   r*   rQ   r   ZRunWithAnnotationQueueInfore   )r0   r$  r2  r'   rZ   r!   r!   r$   get_run_from_annotation_queue!  s
   
z)AsyncClient.get_run_from_annotation_queuelatest)tagr7  c                  sH   t |d}| jdd| dt d|i|dI dH }t| 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   ri   r   z/indexr7  rp   Nr+   r   r\   rv   r*   rQ   )r0   r   r7  rA   respr!   r!   r$   index_dataset6  s   
zAsyncClient.index_datasetc                  sD   t |d}| jdd| dt i |dI dH }t| dS )a  Sync 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   ri   r   z/index/syncrp   Nr8  )r0   r   rA   r9  r!   r!   r$   sync_indexed_datasetW  s   
z AsyncClient.sync_indexed_dataset)r   dictlist[ls_schemas.ExampleSearch]c         
        s   t |d}||d|}|r||d< | jdd| dt |dI dH }t| g }| d	 D ]}	|tj	d
i |	d|i q3|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|   ra   r   ri   r   z/searchrp   Nexamplesr!   )
r+   r   r\   rv   r*   rQ   re   r   r   ZExampleSearch)
r0   r|   ra   r   r   rA   reqr9  r>  exr!   r!   r$   similar_examplesq  s&   D

 zAsyncClient.similar_examplesls_schemas.LangSmithSettingsc                   sD   | j du r| ddI dH }t| tjdi | | _ | j S )zzGet the settings for the current tenant.

        Returns:
            dict: The settings for the current tenant.
        Nrc   z	/settingsr!   )r   r\   r*   rQ   r   ZLangSmithSettingsre   )r0   rZ   r!   r!   r$   _get_settings  s   

zAsyncClient._get_settingsownerc                   s"   |   I dH }|dkp|j|kS )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-)rC  tenant_handle)r0   rD  settingsr!   r!   r$   _current_tenant_is_owner  s   	z$AsyncClient._current_tenant_is_owneractionls_utils.LangSmithUserErrorc                   s.   |   I d H }td| d|j d| S )NzCannot z% for another tenant.
Current tenant: z,
Requested tenant: )rC  r*   LangSmithUserErrorrF  )r0   rI  rD  rG  r!   r!   r$   _owner_conflict_error  s   z!AsyncClient._owner_conflict_errorrK   r   prompt_owner_and_namer`   c                   sF   | j dd| d||ddI dH }| d }|r!|d d	 S dS )
a  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.
        rc   	/commits/r4  )ra   r`   rd   Ncommitsr   commit_hash)r\   re   )r0   rM  ra   r`   rZ   rO  r!   r!   r$   _get_latest_commit_hash  s   
z#AsyncClient._get_latest_commit_hashprompt_identifierlikedict[str, int]c                   sH   t |\}}}| jdd| d| d|idI dH }|  | S )a  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.
        ri   z/likes/r4  rS  r'  N)r*   parse_prompt_identifierr\   raise_for_statusre   )r0   rR  rS  rD  prompt_name_rZ   r!   r!   r$   _like_or_unlike_prompt  s   z"AsyncClient._like_or_unlike_promptc              	     st   t |\}}}| |s | j d| d| d|dd  S |  I dH }| j d| d|dd  d|j S )zGet a URL for a prompt.

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

        Returns:
            str: The URL for the prompt.

        z/hub/r4  :N   z	/prompts/z?organizationId=)r*   rU  rH  r>   rC  r   )r0   rR  rD  rW  rP  rG  r!   r!   r$   _get_prompt_url  s   


$zAsyncClient._get_prompt_urlc                   s   |  |I dH }|rdS dS )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)r0   rR  promptr!   r!   r$   _prompt_exists/  s   	zAsyncClient._prompt_existsc                      | j |ddI dH S )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rS  NrY  r0   rR  r!   r!   r$   like_prompt;     
zAsyncClient.like_promptc                   r`  )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.

        Fra  Nrb  rc  r!   r!   r$   unlike_promptG  re  zAsyncClient.unlike_promptrb   FZdesc)ra   r`   	is_publicis_archived
sort_fieldsort_directionr   rg  rh  ri  ls_schemas.PromptSortFieldrj  Literal['desc', 'asc']ls_schemas.ListPromptsResponsec          
   	     s|   |||rdn|durdnd|rdndt |tjr|jn||||r#dndd}| jddt|dI dH }	tjdi |	 S )	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)ra   r`   rg  rh  ri  rj  r   Zmatch_prefixrc   /repos/rd   r!   )r,   r   PromptSortFieldr   r\   _exclude_noneZListPromptsResponsere   )
r0   ra   r`   rg  rh  ri  rj  r   rC   rZ   r!   r!   r$   list_promptsS  s    



zAsyncClient.list_promptsOptional[ls_schemas.Prompt]c                   sb   t |\}}}z| dd| d| I dH }tjdi | d W S  t jy0   Y dS w )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.
        rc   rp  r4  Nrepor!   )r*   rU  r\   r   Promptre   rT   r0   rR  rD  rW  rX  rZ   r!   r!   r$   r]    s   
zAsyncClient.get_promptr#  readmetagsrg  ry  rz  ls_schemas.Promptc                  s   |   I dH }|r|jstdt|\}}}	| j|dI dH s,| d|I dH ||p0d|p3d|p6g |d}
| jdd|
d	I dH }|  t	j
di | d
 S )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)rD  zcreate a prompt )Zrepo_handler#  ry  rz  rg  ri   rp  r'  ru  r!   )rC  rF  r*   rK  rU  rH  rL  r\   rV  r   rv  re   )r0   rR  r#  ry  rz  rg  rG  rD  rW  rX  re   rZ   r!   r!   r$   create_prompt  s$   
zAsyncClient.create_promptparent_commit_hashobjectr  c                  s   |  |I dH stdzddlm} W n ty!   tdw ||}t|}t|\}}}	| d| }
|dksB|du rJ| 	|
I dH }||d}| j
d	d
|
 |dI dH }| d d }| |
 d| I dH S )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`r4  r6  )Zparent_commitmanifestri   rN  r'  commitrP  rZ  )r_  r*   rT   Zlangchain_core.load.dumpr  ImportErrorre   loadsrU  rQ  r\   r\  )r0   rR  r  r  r  Zjson_objectZmanifest_dictrD  rW  rX  rM  Zrequest_dictrZ   rP  r!   r!   r$   create_commit  s4   


zAsyncClient.create_commit)r#  ry  rz  rg  rh  c                  s   |   I dH }|r|jstdi }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< t|\}	}
}| jdd	|	 d
|
 |dI dH }|  | S )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|  r#  ry  rg  rh  rz  r   rp  r4  r'  )rC  rF  r   r*   rU  r\   rV  re   )r0   rR  r#  ry  rz  rg  rh  rG  re   rD  rW  rX  rZ   r!   r!   r$   update_prompt  s.   
zAsyncClient.update_promptc                   s^   t |\}}}| |I dH s| d|I dH | dd| d| I dH }|  dS )a6  Delete 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   rp  r4  )r*   rU  rH  rL  r\   rV  rw  r!   r!   r$   delete_promptB  s   
zAsyncClient.delete_promptinclude_modelr  ls_schemas.PromptCommitc             
     s`   t |\}}}| dd| d| d| |rdnd I dH }tjdi ||d| S )	a  Pull 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.
        rc   rN  r4  z?include_model=truer}  NrD  ru  r!   )r*   rU  r\   r   ZPromptCommitre   )r0   rR  r  rD  rW  rP  rZ   r!   r!   r$   pull_prompt_commitW  s   


zAsyncClient.pull_prompt_commitra   r`   r  3AsyncGenerator[ls_schemas.ListedPromptCommit, None]c                C s   t |\}}}|durtd|n|||d}d}		 ||d< | jdd| d	| d	|d
I dH }
|
 }|d }|d }|sAdS |D ]}|durP|	|krP dS tjdi ||d|V  |	d7 }	qC|t|7 }||krodS q)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.
        Nrb   r  r   Tr`   rc   rN  r4  rd   rO  totalr  rK   r!   )r*   rU  r  r\   re   r   ZListedPromptCommitrf   )r0   rR  ra   r`   r  rD  rW  rX  rC   r  rZ   valrN   r  itr!   r!   r$   list_prompt_commitsv  s<   
zAsyncClient.list_prompt_commitsc                  sN  z(ddl m} ddlm} ddlm} ddlm} ddlm	} ddl
m}m}	 W n ty4   tdw zdd	lm}
 W n tyM   tjd
d }
Y nw | j||dI dH }|
  |t|j}W d   n1 snw   Y  t||st||	rt|j|rt||r|nt||	rt|j|r|jnd}|du rtd|jdu ri |_|j|j|j|jd |r%t||	r%t|j|r%t|j dkr%t|j!|s%t|j!|rt|j!j"|rt#|	|j|j!j"B }t|j dkr|j d }|	|j|j$di i |j!j%|j!}|S |}|S t|j!|r$|j|j!B }|S 	 |S )a  Pull a prompt and return it as a LangChain PromptTemplate.

        This method requires `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                   s  s    d V  d S r;   r!   r!   r!   r!   r$   r    s   
z@AsyncClient.pull_prompt.<locals>.suppress_langchain_beta_warningr  Nz-Prompt object is not a valid prompt template.)Zlc_hub_ownerZlc_hub_repoZlc_hub_commit_hashrL   r   rK   r!   )&Z#langchain_core.language_models.baser  Zlangchain_core.load.loadr  Zlangchain_core.output_parsersr  Zlangchain_core.promptsr  Z!langchain_core.prompts.structuredr  Zlangchain_core.runnables.baser  r  r  Zlangchain_core._apir  
contextlibcontextmanagerr  re   r  r  r,   firstr*   rU   r   updaterD  ru  rP  rf   Zstepslastboundr   bindrA   )r0   rR  r  r  r  r  r  r  r  r  r  Zprompt_objectr^  Zprompt_templateseqZrebound_llmr!   r!   r$   pull_prompt  s   





zAsyncClient.pull_prompt)r  r  rg  r#  ry  rz  c          	        s   |  |I dH r$tdd ||||fD r#| j|||||dI dH  n| j||dur-|nd|||dI dH  |du rD| j|dI dH S | j|||dI dH }|S )	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                 s  s    | ]}|d uV  qd S r;   r!   )r"   paramr!   r!   r$   	<genexpr>8  s    
z*AsyncClient.push_prompt.<locals>.<genexpr>rx  F)rg  r#  ry  rz  )rR  r  )r_  anyr  r~  r\  r  )	r0   rR  r  r  rg  r#  ry  rz  urlr!   r!   r$   push_prompt  s8   &
zAsyncClient.push_prompt)NNNNN)
r   r   r   r   r   r   r   r   r   r   )r3   r   )r3   r<   )r?   r<   r@   r<   rA   r   r3   rB   r;   )r]   r<   rC   r^   r3   r_   )
r]   r<   rk   rn   rl   r<   rm   r<   r3   ro   )r{   r<   r|   r}   r~   r<   ry   r   rz   r   rA   r   r3   r   )r   r   rA   r   r3   r   )r   r   r3   r   )$r   r   ry   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   ra   r   rA   r   r3   r   )r   r   r   r   r3   r<   )r   r   r3   r   )r   r   r3   r   )ry   r<   rA   r   r3   r   )NN)ry   r   r   r   r3   r   )ry   r   r   r   r3   r   )r   r<   rA   r   r3   r   )r   r   r   r   r3   r   )r   r   r3   r   )rA   r   r3   r   )NNN)r|   r}   r   r^   r   r   r   r   rA   r   r3   r   )r   r   r3   r   )r   r   r   r   rA   r   r3   r   )r   r   r   r<   r   r   r   r   r   r   rA   r   r3   r   )r   r   r   r   r   r   r   r   r   r   r   rn   r3   r   )r   r   r   r<   r   r   r   r   r   r   r3   r  )r   r   r3   r   )r   r   r   r   r  r  ra   r   rA   r   r3   r  )r   r  r3   r   )
r  r  r{   r   r  r   ra   r   r3   r  )r{   r<   r#  r   r$  r%  r3   r&  )r$  r  r3   r&  )r$  r  r{   r<   r#  r   r3   r   )r$  r  r3   r   )r$  r  r   r/  r3   r   )r$  r  r   r  r3   r   )r$  r  r2  r-   r3   r3  )r   r   r7  r<   rA   r   r3   r   )r   r   rA   r   r3   r   )r|   r<  ra   r-   r   r   r   r   rA   r   r3   r=  )r3   rB  )rD  r<   r3   r   )rI  r<   rD  r<   r3   rJ  )rK   r   )rM  r<   ra   r-   r`   r-   r3   r   )rR  r<   rS  r   r3   rT  )rR  r<   r3   r<   )rR  r<   r3   r   )rR  r<   r3   rT  )ra   r-   r`   r-   rg  r   rh  r   ri  rk  rj  rl  r   r   r3   rm  )rR  r<   r3   rt  )rR  r<   r#  r   ry  r   rz  r   rg  r   r3   r{  )rR  r<   r  r   r  r   r3   r<   )rR  r<   r#  r   ry  r   rz  r   rg  r   rh  r   r3   r}   )rR  r<   r3   r   )rR  r<   r  r   r3   r  )
rR  r<   ra   r   r`   r-   r  r   r3   r  )rR  r<   r  r   r3   r   )rR  r<   r  r   r  r<   rg  r   r#  r   ry  r   rz  r   r3   r<   )I__name__
__module____qualname____doc__	__slots__r2   r5   r:   r6   propertyr=   r>   r\   rh   rx   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.  r0  r1  r5  ls_betaZ	warn_betar:  r;  rA  rC  rH  rL  rQ  rY  r\  r_  rd  rf  r   rq  Z
updated_atrs  r]  r~  r  r  r  r  r  r  r  r!   r!   r!   r$   r      sF   #
?$ J
*:A1# W2:;:#9gr   dr<  r3   c                 C  s   dd |   D S )z&Exclude None values from a dictionary.c                 S  rD   r;   r!   rE   r!   r!   r$   rH   Y  rI   z!_exclude_none.<locals>.<dictcomp>)rN   )r  r!   r!   r$   rr  W  s   rr  )r  r<  r3   r<  )#r  
__future__r   rW   r  r  re   r   collections.abcr   r   r   r   typingr   r   r	   r
   r   r/   Z	langsmithr   r+   r   r   r   r*   Zlangsmith._internalr   r  r   r<   r  r   rr  r!   r!   r!   r$   <module>   s>                  H