Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
utils.cpython-313.pyc349 linesDownload Raw Back to __pycache__
1�

2��ju���SrSSKJr SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK3r4SSKrSSKrSSK
r
SSKrSSKrSSKJrJrJrJrJr SSKJrJr SSKJrJrJrJrJrJrJ r J!r! SSK"J#r$ SSK%r%SSK&r&SSK'J(r( SS	K)J*r* SS5K+J,r- \R\"\/5r0"SS\15r2"S
S\25r3"SS\25r4"SS\25r5"SS\25r6"SS\25r7"SS\25r8"SS\25r9"SS\25r:"SS\25r;S\Sjr<"S S!\=5r>"S"S#\>5r?S]S^S$jjr@S_S%jrAS`S&jrBSaS'jrCSbS(jrD\R�"S)S*9ScS+j5rFSdS,jrGSeS-jrHSfS.jrISgS/jrJShS0jrKSiS1jrLSjS2jrM\R�"S)S*9SkS3j5rNSlS4jrOSmS5jrPSnS6jrQ\!S7S8.SoS9jj5rR\!S]S7S8.SpS:jjj5rR\R�"S;S*9S]S7S8.SqS<jjj5rR\R�"S)S*9SrSsS=jj5rS"S>S?\R�5rU"S@SA\R�5rV"SBSC\*5rW\R�"5rY\R�StSDj5r[SuSEjr\SSSF.SvSGjjr]\R�SwSxSHjj5r^\R�SwSySIjj5r_SzSJjr`\"SK5raS{S|SLjjrbS}SMjrcS~SNjrdSSOjreSSPjrf\("SQ5rg"SRSS\5rhS�STjriS�SUjrjS�SVjrkS�SWjrl\R�"SXS*9S�SYj5rmS�S�SZjjrnS�S[jrog)�zGeneric utility functions.�)�annotationsN)�	Generator�Iterable�Iterator�Mapping�Sequence)�Future�ThreadPoolExecutor)�Any�Callable�Literal�Optional�TypeVar�Union�cast�overload)�parse)�	ParamSpec)�Retry)�schemasc��\rSrSrSrSrg)�LangSmithError�*z=An error occurred while communicating with the LangSmith API.�N��__name__�6__module__�__qualname__�__firstlineno__�__doc__�__static_attributes__r��UD:\code\apps\devtools\python\user_packages\Python313\site-packages\langsmith/utils.pyrr*s��Gr"rc��\rSrSrSrSrg)�LangSmithAPIError�.z9Internal server error while communicating with LangSmith.rNrrr"r#r%r%.s��Cr"r%c��\rSrSrSrSrg)�LangSmithRequestTimeout�2z*Client took too long to send request body.rNrrr"r#r(r(2s��4r"r(c��\rSrSrSrSrg)�LangSmithUserError�6zAUser error caused an exception when communicating with LangSmith.rNrrr"r#r+r+6s��Kr"r+c��\rSrSrSrSrg)�LangSmithRateLimitError�:z7You have exceeded the rate limit for the LangSmith API.rNrrr"r#r.r.:s��Ar"r.c��\rSrSrSrSrg)�LangSmithAuthError�>z-Couldn't authenticate with the LangSmith API.rNrrr"r#r1r1>s��7r"r1c��\rSrSrSrSrg)�LangSmithNotFoundError�Bz%Couldn't find the requested resource.rNrrr"r#r4r4Bs��/r"r4c��\rSrSrSrSrg)�LangSmithConflictError�FzThe resource already exists.rNrrr"r#r7r7F���&r"r7c��\rSrSrSrSrg)�LangSmithConnectionError�Jz&Couldn't connect to the LangSmith API.rNrrr"r#r;r;J���0r"r;c�@^�\rSrSrSrSU4SjjrSrU=r$)�LangSmithExceptionGroup�Nz%Port of ExceptionGroup for Py < 3.11.c�2>�[TU]"U0UD6 Xlg)zInitialize.N)�super�__init__�7exceptions)�selfrD�args�kwargs�	__class__s    �r#rC� LangSmithExceptionGroup.__init__Qs���	���$�)�&�)�$�r")rD)rFrrDzSequence[Exception]rGr�return�None)rrrrr rCr!�
__classcell__�rHs@r#r?r?Ns0���/�%��%�&9�%�EH�%�	
�%�%r"r?c��SUS3$)a
Get the error message for an invalid prompt identifier.8 9Used consistently across the codebase when parsing prompt identifiers fails.10 11Args:12    identifier: The invalid identifier that was provided.13 14Returns:15    A formatted error message explaining the valid formats.16z#Invalid prompt identifier format: "z�". Expected one of:17  - "prompt-name" (for private prompts)18  - "owner/prompt-name" (for prompts with explicit owner)19  - "prompt-name:commit-hash" (with commit reference)20  - "owner/prompt-name:commit-hash" (with owner and commit)r��21identifiers r#�!get_invalid_prompt_identifier_msgrQYs��.�j�\�:F�	G�r"c��\rSrSrSrSrg)�LangSmithWarning�qzBase class for warnings.rNrrr"r#rSrSqs��"r"rSc��\rSrSrSrSrg)�LangSmithMissingAPIKeyWarning�uzWarning for missing API key.rNrrr"r#rVrVur9r"rVc���SSKJs Jn SSKJnJn U=(d U"5nUSbUS$U"5(agURbUR$[S[SSS	9S	9nUS22:H$)z"Return True if tracing is enabled.rN)�get_current_run_tree�get_tracing_context�enabledT�23TRACING_V2�TRACING���default�true)�langsmith._internal._context�	_internal�_context�langsmith.run_helpersrYrZ�_GLOBAL_TRACING_ENABLED�get_env_var)�ctxrdrYrZ�tc�24var_results      r#�tracing_is_enabledrkyst��4�3�O�	�	%�#�%�B�2526�)�}� ��)�}�������'�'�3��/�/�/��\�;�y�RT�3U�V�J����r"c��[SSS9S:H$)z"Return True if testing is enabled.�
TEST_TRACKINGr^r_�false�rgrr"r#�test_tracking_is_disabledrp�s�����3�w�>�>r"c�^�SU4SjjnU$)z7Validate specified keyword args are mutually exclusive.c�N>^�[R"T5SUU4Sjj5nU$)Nc�^>^�TVs/sHn[U4SjU55PM nn[U5VVs/sHupEUS:wdM
UPM nnnU(aAUVs/sHnSRTU5PM nn[SSRU535eT	"U0TD6$s snfs snnfs snf)z3Validate exactly one arg in each group is not None.c3�P># �UHnTRU5cMSv� M g7f)N�)�get)�.0�argrGs  �r#�	<genexpr>�?xor_args.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>�s����J��#�f�j�j��o�A�A��s�&�	&ruz, zFExactly one argument in each of the following groups must be defined: )�sum�	enumerate�join�27ValueError)28rFrG�	arg_group�counts�i�count�invalid_groups�invalid_group_names�29arg_groups�funcs30 `      ��r#�wrapper�,xor_args.<locals>.decorator.<locals>.wrapper�s����31",��!+�I��J��J�J�!+�
��1:�&�0A�P�0A�H�A�U�a�Z�a�0A�N�P��IW�&X��A�t�y�y��A��'?��#�&X� ���	�	�"5�6�7�9���32��(��(�(����Q��&Xs�B�B$�B$�B*)rFrrGrrJr)�	functools�wraps)r�r�r�s` �r#�	decorator�xor_args.<locals>.decorator�s%���	����	�	)�33�	)� �r")r�rrJrr)r�r�s` r#�xor_argsr��s����(�r"c�T�UR5 g![Ra0n[R"[U5UR5UeSnAf[34Ra>n[35R"[U5SUR3URUS9UeSnAff=f)z&Raise an error with the response text.Nz: )�request�response)�raise_for_status�requests�	HTTPError�str�text�httpx�HTTPStatusErrorr�)r��es  r#�raise_for_status_with_textr��s���	��!�!�#�����?�� � ��Q�����7�Q�>��� � ���#�#��1�v�h�b�����(��$�$��36��		���s ��B'�+A�B'�)9B"�"B'c�\�[U[R5(aUR$U$)zGet the value of a string enum.)�37isinstance�enum�Enum�value)�enus r#�get_enum_valuer��s"���#�t�y�y�!�!��y�y���Jr"ru)�maxsizec�.�[RX5 g)z4Log a message at the specified level, but only once.N)�_LOGGER�log)�level�messages  r#�log_oncer��s���K�K��r"c���U(d[S5eSU;a;SU;a[SUS35eUSSRSS5R5$S	U;a[S38US35eUS	$)N�Message is empty.�lc�id�*Unexpected format for serialized message: z Message does not have an id.������Messager^�type�&Unexpected format for stored message: z Message does not have a type.)r~�replace�lower�r�s r#�_get_message_typer��s�����,�-�-��w���w���<�W�I�/�0��
��t�}�R� �(�(��B�7�=�=�?�?��� ��8��	�0�1��
��v��r"c��U(d[S5eSU;aSU;a[SUS35eUS$SU;a[SUS35eUS$)	Nr�r�rGr�z Message does not have kwargs.�datar�z Message does not have data.)r~r�s r#�_get_message_fieldsr��sy����,�-�-��w���7�"��<�W�I�0�1��
��x� � ��� ��8��	�.�/��
��v��r"c�6�[U5n[U5nXS.$)z&Extract message from a message object.�r�r�)r�r�)r��message_type�message_datas   r#�_convert_messager��s��$�W�-�L�&�w�/�L� �7�7r"c��SU;aUSVs/sHn[U5PM sn$SU;a[US5/$[SUS35es snf)z�Extract messages from the given inputs dictionary.39 40Args:41    inputs: The inputs dictionary.42 43Returns:44    A list of dictionaries representing the extracted messages.45 46Raises:47    ValueError: If no message(s) are found in the inputs dictionary.48�messagesr�z-Could not find message(s) in run with inputs �.)r�r~)�inputsr�s  r#�get_messages_from_inputsr��sd���V��9?�49�9K�L�9K�g� ��)�9K�L�L��F�� ��	�!2�3�4�4�50�D�V�H�A�N�51O�O��Ms�A52c���SU;a[SUS35eUSn[U5S:wa[S[U5SUS35eUSnSU;a[S	US5335e[US5$)z�Retrieve the message generation from the given outputs.54 55Args:56    outputs: The outputs dictionary.57 58Returns:59    The message generation.60 61Raises:62    ValueError: If no generations are found or if multiple generations are present.63�generations�,No generations found in in run with output: r�ruz3Chat examples expect exactly one generation. Found z generations: rr�z"Unexpected format for generation: z%. Generation does not have a message.)r~�lenr���outputsr��first_generations   r#�#get_message_generation_from_outputsr�
s����G�#��G��y�PQ�R�S�S��-�(�K�64�;��1���
��+�&�'�~�k�]�!�
E�65�	66�#�1�~���(�(��0�1A�0B�C3�
3�67�	68��,�Y�7�8�8r"c��SU;aUS$SU;a(USn[U5S:XaUS$[SUS35e[SUS35e)	z�Retrieve the prompt from the given inputs.69 70Args:71    inputs: The inputs dictionary.72 73Returns:74    str: The prompt.75 76Raises:77    ValueError: If the prompt is not found or if multiple prompts are present.78�prompt�promptsrurz$Multiple prompts in run with inputs z!. Please create example manually.z)Could not find prompt in run with inputs r�)r�r~)r�r�s  r#�get_prompt_from_inputsr�*st���6���h����F����#���w�<�1���1�:���2�6�(�;/�
/�79�	80��@����J�81K�Kr"c��SU;a[SUS35eUSn[U5S:wa[SU35eUSnSU;a[SU35eUS$)	z(Get the LLM generation from the outputs.r�r�r�ruzMultiple generations in run: rr�zNo text in generation: )r~r�r�s   r#�get_llm_generation_from_outputsr�Cs}���G�#��G��y�PQ�R�S�S��-�(�K�82�;��1���8��
�F�G�G�"�1�~��
�%�%��2�3C�2D�E�F�F��F�#�#r"c�v�[R"/SQ[R[RS9 SS/$![R[4ad [R"SS/[R[RS9 S/s$![R[4a [S5ef=ff=f)z7Get the correct docker compose command for this system.)�docker�compose�	--version)�stdout�stderrr�r�zdocker-composer�z�Neither 'docker compose' nor 'docker-compose' commands are available. Please install the Docker server following the instructions for your operating system at https://docs.docker.com/engine/install/)�83subprocess�84check_call�DEVNULL�CalledProcessError�FileNotFoundErrorr~rr"r#�get_docker_compose_commandr�Ps�������.��%�%��%�%�	85�86�)�$�$���)�)�+<�=��
	��!�!�!�;�/�!�)�)�!�)�)�
�87%�%�%���-�-�/@�A�	��E��
�	���s!�7:�B8�6B�B8�&B4�4B8c��URSUR0S.nUR(a-[UR5S:�a0UREUSS'U$)z*Convert a LangChain message to an example.�contentr�rr��additional_kwargs)r�r�r�r�)r��	converteds  r#�convert_langchain_messager�ks\������G�O�O�,�!�I�88� � �S��)B�)B�%C�a�%G�1N�G�4M�4M�1N�	�&��-�.��r"c89���[[[USS5[5[[USS5[5[US5=(a [[US5[5/5$)z�Check if the given object is similar to `BaseMessage`.90 91Args:92    obj: The object to check.93 94Returns:95    bool: True if the object is similar to `BaseMessage`, `False` otherwise.96r�Nr�r�)�allr��getattrr��dict�hasattr)�objs r#�is_base_message_liker�wsZ����w�s�I�t�4�c�:��w�s�$7��>��E��C�� �J�Z���V�0D�c�%J�	97��r"c�2�Ucg[[U55$)z2Check if the given environment variable is truish.F)�	is_truishrg)r�s r#�is_env_var_truishr��s���}���[��'�(�(r")�	LANGSMITH�	LANGCHAIN)�98namespacesc��g�Nr��namer`r�s   r#rgrg�s��r"c��gr�rr�s   r#rgrg�s��r"�dc���UVs/sH	o3SU3PM nnUH?n[RRU5nUcM'UR5S:wdM=Us $ U$s snf)a�Retrieve an environment variable from a list of namespaces.99 100Args:101    name: The name of the environment variable.102    default: The default value to return if the environment variable is not found.103    namespaces: A tuple of namespaces to search for the environment variable.104 105        Defaults to `('LANGSMITH', 'LANGCHAINs')`.106 107Returns:108    The value of the environment variable if found, otherwise the default value.109�_r^)�os�environrv�strip)r�r`r��	namespace�namesr�s      r#rgrg�sb��&5?�?�J�y�{�!�D�6�
"�J�E�?����110�111���t�$��������"�!4��L���N��
@s�Ac�t�[RRS[S[SU(aSOSS9S95$)z,Get the project name for a LangSmith tracer.�HOSTED_LANGSERVE_PROJECT_NAME�PROJECT�SESSIONr`Nr_)r�r�rvrg)�return_default_values r#�get_tracer_projectr�s=���:�:�>�>�112	(��� ��0D�9�$��		113�
�r"c�>^�\rSrSrSrSSU4SjjjrSSjrSrU=r$)	�FilterPoolFullWarningi�zGFilter `urllib3` warnings logged when the connection pool isn't reused.c�0>�[TU]U5 X lg)z�Initialize the `FilterPoolFullWarning` filter.114 115Args:116    name: The name of the filter. Defaults to `""`.117    host: The host to filter. Defaults to `""`.118N)rBrC�_host)rEr��hostrHs   �r#rC�FilterPoolFullWarning.__init__�s���	������119r"c�N�UR5nSU;agURU;$)zJurllib3.connectionpool:Connection pool is full, discarding connection: ...z.Connection pool is full, discarding connectionT)�120getMessager�rE�record�msgs   r#�filter�FilterPoolFullWarning.filter�s*�����!��;�3�F���z�z��$�$r")r)r^r^)r�r�rr�rJrK�rJ�bool)	rrrrr rCrr!rLrMs@r#rr�s���Q���%�%r"rc�"�\rSrSrSrSSjrSrg)�FilterLangSmithRetryi�z!Filter for retries from this lib.c�,�UR5nSU;$)z!Filter retries from this library.�LangSmithRetry)rr	s   r#r�FilterLangSmithRetry.filter�s�����!���s�*�*r"rNr)rrrrr rr!rr"r#rr�s121��+�+r"rc��\rSrSrSrSrg)ri�z&Wrapper to filter logs with this name.rNrrr"r#rr�r=r"rc#�# �[ UHnURU5 M SSS5 Sv� [ UHnURU5 M SSS5 g!,(df   N>=f![a [RS5 MUf=f!,(df   g=f![ UH;nURU5 M![a [RS5 M9f=f SSS5 f!,(df   f=f=f7f)z�Temporarily adds specified filters to a logger.122 123Parameters:124- logger: The logger to which the filters will be added.125- filters: A sequence of `logging.Filter` objects to be temporarily added126    to the logger.127NzFailed to remove filter)�_FILTER_LOCK�	addFilter�removeFilter�
BaseExceptionr��warning)�logger�filtersrs   r#�filter_logsr�s����128��F����V�$��129�?�
�
�!��?��'�'��/�"��\�130���%�?��O�O�$=�>�?��	�\��\�!��?��'�'��/��$�?��O�O�$=�>�?��"��\�\�s��D131�A�D132�B$�D133�B�A-�B�	D134�135A*�&D136�-B�B�B�B�137B!�D138�$D�+C6�2C�C6�C(�$C6�'C(�(C6�-	D�6139D�D�D140c� �UbU$[SSS9$)z�Get the testing cache directory.141 142Args:143    cache: The cache path.144 145Returns:146    The cache path if provided, otherwise the value from the `LANGSMITH_TEST_CACHE`147    environment variable.148N�149TEST_CACHEr_ro)�caches r#�
get_cache_dirr"s��
�����|�T�2�2r"��ignore_hosts�allow_hostsc�2^^�U(a[U4SjU55(agU(aT[R"TR5nUR150=(d Sm[UU4SjU55nU(dg0TlT$![a gf=f)zAFilter request headers based on `ignore_hosts` and `allow_hosts`.c3�Z># �UH nTRRU5v� M" g7fr�)�url�151startswith)rwrr�s  �r#ry�)filter_request_headers.<locals>.<genexpr>(s#����R�\�T�G�K�K�2�2�4�8�8�\�s�(+Nr^c3��># �UHVnURS5(aTRRU5OTU:H=(d TRSU35v� MX g7f))zhttp://zhttps://r�N)r)r(�endswith)rwrr��request_hosts  ��r#ryr*3sa����	152�$���?�?�#:�;�;����&�&�t�,�!�T�)�N�\�-B�-B�Q�t�f�:�-N�O�$�s�AA!)�any�urllib_parse�urlparser(�	Exception�hostname�headers)r�r$r%�153parsed_url�host_matchesr-s`    @r#�filter_request_headersr6 s������R�\�R�R�R���	�%�.�.�w�{�{�;�J�"�*�*�0�b���	154�$�	155�	156�����G�O��N��'�	��	�s� B	�	157B�Bc	#�^^# �SSKnSSKJn UR	5 [158RRU5upVURURS5(dURS5(aSOSUS	/S159QSS/UU4S
jS9nURU5 Sv� SSS5 g![a [S5ef=f!,(df   g=f7f)�Use a cache for requests.rNzNvcrpy is required to use caching. Install with:pip install -U "langsmith[vcr]")�_patchz.yamlz.yml�yaml�json�new_episodes)�uri�method�path�body�
authorizationz160Set-Cookiec�>�[UTTS9$)Nr#)r6)r�r%r$s ��r#�<lambda>�with_cache.<locals>.<lambda>es���.D��,�K�/161r")�162serializer�cassette_library_dir�record_mode�match_on�filter_headers�before_record_request)�vcr�ImportError�langsmith._internalr9�
patch_urllib3r�r?�split�VCRr,�use_cassette)r?r$r%rKrN�	cache_dir�163cache_file�ls_vcrs ``     r#�164with_cacherUDs�����165��<����!��G�G�M�M�$�/��I�
�W�W��"�"�7�+�+�z�/B�/B�6�/J�/J�
��&�#�2�'��6�166���F� 167�	�	�Z�	(�
�168)�	(��9�169��
.�170�	171�172��8173)�	(�s4�C�B+�BC�C�"	C�+C�C�174C�Cc#�p# �Ub[XU5 Sv� SSS5 gSv� g!,(df   g=f7f)r8N)rU)r?r$r%s   r#�with_optional_cacherWms/�����
��K�
8��9�
8�	�9�
8�s�6�%�6�1753�6c��[R"[R"56nUVs/sH
nSU;dMUPM nnSR	U5$s snf)Nz176langsmith/r^)�	traceback�format_exception�sys�exc_infor})�tb_lines�line�filtered_liness   r#�_format_excr`{sH���)�)�3�<�<�>�:�H�'/�L�x�t�<�t�3K�d�x�N�L�
�7�7�>�"�"��Ms177�178A�A�Tc�^^^�[U5n[USS5nUb	U"T5$TT:�aU$[U[5(aDUR5VVs0sH&upg[
UTTTS-5[
UTTTS-5_M( snn$[U[5(a"UVs/sHn[
UTTTS-5PM sn$[U[5(a[UUU4SjU55$[U[5(a"UVs1sHn[
UTTTS-5iM sn$U$![a GN179f=fs snnfs snfs snf)N�__deepcopy__ruc3�F># �UHn[UTTTS-5v� M g7f)ruN)�_middle_copy)rw�item�_depth�	max_depth�memos  ���r#ry�_middle_copy.<locals>.<genexpr>�s%����U�QT��\�$��i��!��D�D�QT�s�!)180r�r�rr�r��itemsre�list�tuple�set)	�valrirhrg�cls�copier�k�vrfs	 ```     r#rere�sO����s�)�C�
�S�.�$�
/�F�
��	��$�<������181��#�t���182�	�	��	183�$���
��D�)�V�a�Z�8�,��4��F�Q�J�;�
�$�	184�	185��#�t���LO�P�C�D��T�4��F�Q�J�?�C�P�P��#�u����U�QT�U�U�U��#�s���LO�P�C�D��T�4��F�Q�J�?�C�P�P��J��%�	��	��186187��Q��Qs#�D%�-D6�"D<�E�%188D3�2D3c��0n[R"X5$![a4n[R	S[U55 [
X5sSnA$SnAff=f)z�Deep copy a value with a compromise for uncopyable objects.189 190Args:191    val: The value to be deep copied.192 193Returns:194    The deep copied value.195zFailed to deepcopy input: %sN)�copy�deepcopyrr��debug�reprre)rorir�s   r#�deepish_copyry�sM���D�'��}�}�S�'�'���'�196	�
�
�4�d�1�g�>��C�&�&��
'�s��197A�)A�
A�Ac�Z�SSKJn URU5nURU5nX4:�$)zGCheck if the current version is greater or equal to the target version.r)�version)�	packagingr{r)�current_version�target_versionr{�current�targets     r#�is_version_greater_or_equalr��s*��!��m�m�O�,�G�
�]�]�>�
*�F���r"c���U(aAURS5S:�d,URS5(dURS5(a[[	U55eURSS5nUSn[
U5S:�aUSOSnSU;a:URSS5upEU(aU(d[[	U55eXEU4$U(d[[	U55eSX#4$)aParse a string in the format of `owner/name:hash`, `name:hash`, `owner/name`, or `name`.198 199Args:200    identifier: The prompt identifier to parse.201 202Returns:203    A tuple containing `(owner, name, hash)`.204 205Raises:206    ValueError: If the identifier doesn't match the expected formats.207�/ru�:r�latest�-)r�r)r,r~rQrOr�)rP�parts�208owner_name�commit�ownerr�s      r#�parse_prompt_identifierr��s���
����C� �1�$�� � ��%�%����s�#�#��:�:�F�G�G����S�!�$�E��q��J��U��a��U�1�X�X�F�209�j�� �&�&�s�A�.����D��>�z�J�K�K��F�"�"���>�z�J�K�K��J�&�&r"c��[U5$)aGParse a hub repo identifier (``owner/name:hash``, ``name``, etc.).210 211Agents, skills, and prompts share the same identifier grammar on Hub.212 213Args:214    identifier: The hub identifier to parse.215 216Returns:217    A tuple containing ``(owner, name, hash)``.218 219Raises:220    ValueError: If the identifier doesn't match the expected formats.221)r�rOs r#�parse_hub_identifierr��s��#�:�.�.r"�Pc�l^�\rSrSrSrS	U4SjjrSSS.S222U4SjjjrSrU=r$)�ContextThreadPoolExecutori�z?ThreadPoolExecutor that copies the context to the child thread.c223�>�[TU][[S[4[224R"[R"5RU/UQ70UD655$)aSubmit a function to the executor.225 226Args:227    func (Callable[..., T]): The function to submit.228    *args (Any): The positional arguments to the function.229    **kwargs (Any): The keyword arguments to the function.230 231Returns:232    Future[T]: The future for the function.233.)234rB�submitrrrar��partial�contextvars�copy_context�run)rEr�rFrGrHs    �r#r�� ContextThreadPoolExecutor.submit�s\��� �w�~����a�� ��!�!��,�,�.�2�2�D��;?��CI��
�235�	236r"Nru��timeout�	chunksizec��>^^�[[US55Vs/sHn[R"5PM snmSUU4Sjjn[TU]"U/UQ7UUS.6$s snf)aAReturn an iterator equivalent to stdlib map.237 238Each function will receive its own copy of the context from the parent thread.239 240Args:241    fn: A callable that will take as many arguments as there are242        passed iterables.243    timeout: The maximum number of seconds to wait. If None, then there244        is no limit on the wait time.245    chunksize: The size of the chunks the iterable will be broken into246        before being passed to a child process. This argument is only247        used by ProcessPoolExecutor; it is ignored by248        ThreadPoolExecutor.249 250Returns:251    An iterator equivalent to: map(func, *iterables) but the calls may252    be evaluated out-of-order.253 254Raises:255    TimeoutError: If the entire result iterator could not be generated256        before the given timeout.257    Exception: If fn(*args) raises for any values.258rc�F>�TR5R"T/UQ76$r�)�popr�)rF�contexts�fns ��r#�_wrapped_fn�2ContextThreadPoolExecutor.map.<locals>._wrapped_fn4s����<�<�>�%�%�b�0�4�0�0r"r�)rFrrJra)�ranger�r�r�rB�map)	rEr�r�r��	iterablesr�r�r�rHs	 `     @�r#r��ContextThreadPoolExecutor.mapsm���<9>�c�)�A�,�>O�8P�Q�8P�1�K�,�,�.�8P�Q��	1�	1��w�{��259�
�260���	261�	262��Rs�Ar)r�zCallable[P, T]rFzP.argsrGzP.kwargsrJz	Future[T])263r�zCallable[..., T]r�z
Iterable[Any]r�zOptional[float]r��intrJzIterator[T])	rrrrr r�r�r!rLrMs@r#r�r��ss���I�264��265��266��	267�268269�270�:$(��(271��(272�"�(273�!�	(274�275�(276�277�
(278�(279r"r�c���U=(d [[[SSS95nUR5(d[	S5eUR5RS5RS5RS5$)zBGet the LangSmith API URL from the environment or the given value.�ENDPOINTzhttps://api.smith.langchain.comr_z!LangSmith API URL cannot be empty�"�'r�)rr�rgr�r+�rstrip)�api_url�_api_urls  r#�get_api_urlr�?sm����$����5�	280��H��>�>��� �!D�E�E��>�>��!�!�#�&�,�,�S�1�8�8��=�=r"c��UbUO	[SSS9nUbUR5(dgUR5RS5RS5$)z8Get the API key from the environment or the given value.N�API_KEYr_r�r��rgr�)�api_key�api_key_s  r#�get_api_keyr�MsN��!�-�w�;�y�RV�3W�H���x�~�~�/�/���>�>��!�!�#�&�,�,�S�1�1r"c��UbUO	[SSS9nUbUR5(dgUR5RS5RS5$)zGet workspace ID.N�WORKSPACE_IDr_r�r�r�)�workspace_id�
workspace_id_s  r#�get_workspace_idr�Us\���#�	�
���
6��281��M�$7�$7�$9�$9����� �&�&�s�+�1�1�#�6�6r"c�2�[R"U5RRS5Sn[R282"U5nUS:H=(d) UR
S5=(d UR
S5$![Ra gf=f)z�Check if the URL is localhost.283 284Parameters285----------286url : str287    The URL to check.288 289Returns:290-------291bool292    True if the URL is localhost, False otherwise.293r�rz	127.0.0.1z0.0.0.0z::F)r/�urlsplit�netlocrO�socket�
gethostbynamer)�gaierror)r(r��ips   r#�
_is_localhostr�asz����&�&�s�+�2�2�8�8��=�a�@��
�
!�
!�&�
)���[� �S�B�M�M�)�$<�S��
�
�d�@S�S���?�?����s�A<A?�?B�B�c�294�U(aU$[R"U5n[U5(aSnU$[UR5RS5(aM[UR5R
SS5Sn[R"URUS95nU$[UR5RS5(aM[UR5R
SS5Sn[R"URUS95nU$[UR5RS5(aSnU$[UR5RS	5(aS295nU$[UR5RS5(aSnU$[UR5RS
5(aSnU$[UR5RS5(aSnU$SnU$)z1Get the host URL based on the web URL or API URL.zhttp://localhostz/apirur)r?z/api/v1zeu.zhttps://eu.smith.langchain.comzaws.zhttps://aws.smith.langchain.comzapac.z https://apac.smith.langchain.comzdev.zhttps://dev.smith.langchain.comzbeta.z https://beta.smith.langchain.comzhttps://smith.langchain.com)r/r0r�r�r?r,�rsplit�296urlunparse�_replacer�r))�web_urlr�r4�link�new_paths     r#�get_host_urlr�vs�������&�&�w�/�J��W���!��&�K�%297
�Z�_�_�	�	&�	&�v�	.�	.��z���'�.�.�v�q�9�!�<���&�&�z�':�':��':�'I�J�� �K�298
�Z�_�_�	�	&�	&�y�	1�	1��z���'�.�.�y�!�<�Q�?���&�&�z�':�':��':�'I�J���K�299
�Z�
�
�	�	*�	*�5�	1�	1�/���K�300
�Z�
�
�	�	*�	*�6�	2�	2�0���K�301
�Z�
�
�	�	*�	*�7�	3�	3�1���K�
302
�Z�
�
�	�	*�	*�6�	2�	2�0��303�K�	304
�Z�
�
�	�	*�	*�7�	3�	3�1���K�-���Kr"c���US:�d[U5(d[U5$[US5(aUR$[	U[305R5(a[URUS-5$[US5(a[[US5(a1[URS5(aURR$[URUS-5$[U5$)Nr�rru�__call__rH)�callabler�r�rr�r�r��_get_function_namer�rHr�)r��depths  r#r�r��s����q�y������2�w���r�:����{�{���"�i�'�'�(�(�!�"�'�'�5�1�9�5�5��r�:����2�{�#�#�����j�(I�(I��<�<�(�(�(�!�"�+�+�u�q�y�9�9��r�7�Nr"c��[U[5(aUR5S:H=(d US:H$[U5$)z�Check if the value is truish.306 307Args:308    val (Any): The value to check.309 310Returns:311    bool: True if the value is truish, False otherwise.312ra�1)r�r�r�r)ros r#r�r��s5���#�s����y�y�{�f�$�2��s�313�2���9�r")rPr�rJr�r�)rhzOptional[dict]rJzUnion[bool, Literal['local']]r)r�ztuple[str, ...]rJr)r�z(Union[requests.Response, httpx.Response]rJrK)r�zUnion[enum.Enum, str]rJr�)r�r�r�r�rJrK)r��Mapping[str, Any]rJr�)r�r�rJr�)r�r�rJ�dict[str, Any])r�r�rJzlist[dict[str, Any]])r�r�rJr�)r�r�rJr�)r�r�rJr�)rJz	list[str])r�zls_schemas.BaseMessageLikerJr�)r��objectrJr)r��
Optional[str]rJr)r�r�r`r�r�rmrJr�)r�r�r`rKr�rmrJr�)r�r�r`r�r�rmrJr�)T)rJr�)rzlogging.LoggerrzSequence[logging.Filter]rJ�Generator[None, None, None])r!r�rJr�)r�rr$�Optional[Sequence[str]]r%r�rJr)NN)r?zUnion[str, pathlib.Path]r$r�r%r�rJr�)r?z"Optional[Union[str, pathlib.Path]]r$r�r%r�rJr�)rJr�)�r)314rorarizdict[int, Any]rhr�rgr�rJra)rorarJra)r}r�r~r�rJr)rPr�rJztuple[str, str, str])r�r�rJr�)r�r�rJr�)r�r�rJr�)r(r�rJr)r�r�r�r�)r)r�rr�r�rJr�)rorrJr)pr �315__future__r�316contextlibr�rur�r��loggingr��pathlibr�r�r[�	threadingrY�collections.abcrrrrr�concurrent.futuresr	r317�typingrrr
rrrrr�urllibrr/r�r��typing_extensionsr�urllib3.utilr�	langsmithr�318ls_schemas�	getLoggerrr�r1rr%r(r+r.r1r4r7r;r?rQ�UserWarningrSrVrkrpr�r�r��	lru_cacher�r�r�r�r�r�r�r�r�r�r�r�rgr�Filterrrr�RLockr�contextmanagerrr"r6rUrWr`rareryr�r�r�r�r�r�r�r�r�r�r�r�rr"r#�<module>r�s�� �"�������	��
��319���L�L�9�	�	�	�)���'��+�320�321�322�H�323%��H�Y�H�D��D�5�n�5�L��L�B�n�B�8��8�0�^�0�'�^�'�1�~�1�%�n�%��0#�{�#�'�$4�'� �0?�324�4
�6�
�	�
� ����Q�� � � �325�&�&8�P�&9�:L�2326$����Q��� ��4	��$)�327�3283�	�329
��
���	�330	��331��332���3�	�333
��
���	�334��335�����S�!�"��3�	�336
��
���	�337��"��4���Q��� ��&%�G�N�N�%�*+�7�>�>�+�1�U�1���� �����?��?�%=�?� �?��?�23�$-1�+/�	!�
�!�*�!�)�	!�338	�!�H���-1�+/�%�339"�%�)�%�)�%�!�	%��%�P���-1�+/�340�341,�342�)�343�)�344�!�	345��346�#��C�L��EF��	347�� ��-0��>A����<'�*� '�F/�"�c�N��D348� 2�D349�N>�2�	7��*���Q��� ��8�$r"
codekingpro/portable-devtools · Team Ai