
    gh_                       U d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZmZmZmZmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZ ddlmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- erddl.m/Z/  G d dee*e+f                   Z0 G d de0e*e+f                   Z1 G d de2ej3                  Z4 e            Z5de6d<    ej7                    Z8 G d de0e*e+f                   Z9d%dZ:d&d Z;d'd$Z<dS )(z-Runnables that can be dynamically configured.    )annotationsN)abstractmethod)AsyncIteratorIteratorSequence)wraps)TYPE_CHECKINGAnyCallableOptionalUnioncast)WeakValueDictionary)	BaseModel
ConfigDict)override)RunnableRunnableSerializable)RunnableConfigensure_configget_config_listget_executor_for_configmerge_configs)	AnyConfigurableFieldConfigurableFieldConfigurableFieldMultiOptionConfigurableFieldSingleOptionConfigurableFieldSpecInputOutputgather_with_concurrencyget_unique_config_specs)Graphc                  ~   e Zd ZU dZded<   dZded<    ed          Zee	d8d                        Z
ee	d9d                        Zee	d:d                        Zee	d;d                        Ze		 d<d=d            Ze		 d<d=d            Ze	d<d>d            Ze		 d<d?d            Z	 d<d@dZe	 d<d@d            Ze		 d<dAd!            Ze		 d<dAd"            Ze		 d<d#d$dBd+            Ze		 d<d#d$dBd,            Ze		 d<dCd.            Ze		 d<dDd0            Ze		 d<dEd2            Ze		 d<dFd4            Ze	dGd7            ZdS )HDynamicRunnablea+  Serializable Runnable that can be dynamically configured.

    A DynamicRunnable should be initiated using the `configurable_fields` or
    `configurable_alternatives` method of a Runnable.

    Parameters:
        default: The default Runnable to use.
        config: The configuration to use.
    #RunnableSerializable[Input, Output]defaultNOptional[RunnableConfig]configT)arbitrary_types_allowedreturnboolc                    dS )NT clss    b/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_core/runnables/configurable.pyis_lc_serializablez"DynamicRunnable.is_lc_serializableF   s	     t    	list[str]c                
    g dS )N)	langchainschemarunnabler.   r/   s    r1   get_lc_namespacez DynamicRunnable.get_lc_namespaceK   s     3222r3   type[Input]c                    | j         j        S N)r'   	InputTypeselfs    r1   r=   zDynamicRunnable.InputTypeP   s     |%%r3   type[Output]c                    | j         j        S r<   )r'   
OutputTyper>   s    r1   rB   zDynamicRunnable.OutputTypeU   s     |&&r3   type[BaseModel]c                \    |                      |          \  }}|                    |          S r<   )prepareget_input_schemar?   r)   r8   s      r1   rF   z DynamicRunnable.get_input_schemaZ   s.      <<//&((000r3   c                \    |                      |          \  }}|                    |          S r<   )rE   get_output_schemarG   s      r1   rI   z!DynamicRunnable.get_output_schemaa   s.      <<//&))&111r3   r#   c                \    |                      |          \  }}|                    |          S r<   )rE   	get_graphrG   s      r1   rK   zDynamicRunnable.get_graphh   s,    <<//&!!&)))r3   kwargsr
   Runnable[Input, Output]c                h     | j         di i | j        dt          t          ||                    iS )Nr)   r.   )	__class____dict__r   r   )r?   r)   rL   s      r1   with_configzDynamicRunnable.with_configm   sJ     t~ 
 
WW-ff8U8U*V*VWW
 
 	
r3   .tuple[Runnable[Input, Output], RunnableConfig]c                    | }t          |t                    r@|                    t          |j        |                    \  }}t          |t                    @|t          d|          fS )zPrepare the Runnable for invocation.

        Args:
            config: The configuration to use. Defaults to None.

        Returns:
            tuple[Runnable[Input, Output], RunnableConfig]: The prepared Runnable and
            configuration.
        r   )
isinstancer%   _preparer   r)   r   rG   s      r1   rE   zDynamicRunnable.preparex   sl     -1?33 	Y'00xPV1W1WXXHf ?33 	Y.7777r3   c                    d S r<   r.   )r?   r)   s     r1   rU   zDynamicRunnable._prepare   s	     :=r3   inputr   r    c                P    |                      |          \  }} |j        ||fi |S r<   )rE   invoker?   rW   r)   rL   r8   s        r1   rY   zDynamicRunnable.invoke   s6      <<//&xuf77777r3   c                `   K   |                      |          \  }} |j        ||fi | d {V S r<   )rE   ainvokerZ   s        r1   r\   zDynamicRunnable.ainvoke   sM        <<//&%X%eV>>v>>>>>>>>>r3   F)return_exceptionsinputslist[Input]5Optional[Union[RunnableConfig, list[RunnableConfig]]]r]   Optional[Any]list[Output]c                    t          |t          |                    } fd|D             }t           fd|D                       r   j        j        |d |D             fdiS |sg S dfd}t          |          dk    r't          d ||d         |d                   g          S t          |d                   5 }t          dt          |                    |||                              cd d d            S # 1 swxY w Y   d S )Nc                :    g | ]}                     |          S r.   rE   .0cr?   s     r1   
<listcomp>z)DynamicRunnable.batch.<locals>.<listcomp>   #    555DLLOO555r3   c              3  0   K   | ]\  }}|j         u V  d S r<   r'   rg   p_r?   s      r1   	<genexpr>z(DynamicRunnable.batch.<locals>.<genexpr>   .      66TQqDL 666666r3   c                    g | ]\  }}|S r.   r.   rg   ro   rh   s      r1   ri   z)DynamicRunnable.batch.<locals>.<listcomp>       (((tq!(((r3   r]   preparedrR   rW   r   r+   Union[Output, Exception]c                    | \  }}r)	  |j         ||fi S # t          $ r}|cY d }~S d }~ww xY w |j         ||fi S r<   )rY   	Exceptionru   rW   boundr)   erL   r]   s        r1   rY   z%DynamicRunnable.batch.<locals>.invoke   s     %ME6  ='5<v@@@@@    HHHHHH $u|E6<<V<<<s    
/*//   rb   r   ru   rR   rW   r   r+   rv   )	r   lenallr'   batchr   r   listmap)	r?   r^   r)   r]   rL   configsru   rY   executors	   `  ``    r1   r   zDynamicRunnable.batch   s    "&#f++665555W5556666X66666 	%4<%((x(((  #4 	    	I	= 	= 	= 	= 	= 	= 	= v;;!VAY)G)G(HIII$WQZ00 	VHX\\&(F-S-S(T(TUU	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	Vs   2DD
Dc               t   K   t          |t          |                    } fd|D             }t           fd|D                       r&  j        j        |d |D             fdi d {V S |sg S dfd}t          |||          }t          |d                             d          g|R   d {V S )Nc                :    g | ]}                     |          S r.   re   rf   s     r1   ri   z*DynamicRunnable.abatch.<locals>.<listcomp>   rj   r3   c              3  0   K   | ]\  }}|j         u V  d S r<   rl   rm   s      r1   rp   z)DynamicRunnable.abatch.<locals>.<genexpr>   rq   r3   c                    g | ]\  }}|S r.   r.   rs   s      r1   ri   z*DynamicRunnable.abatch.<locals>.<listcomp>   rt   r3   r]   ru   rR   rW   r   r+   rv   c                   K   | \  }}r/	  |j         ||fi  d {V S # t          $ r}|cY d }~S d }~ww xY w |j         ||fi  d {V S r<   )r\   rx   ry   s        r1   r\   z'DynamicRunnable.abatch.<locals>.ainvoke   s       %ME6  D!.uf!G!G!G!GGGGGGGG    HHHHHH +U]5&CCFCCCCCCCCCs   ! 
7277r   max_concurrencyr}   )r   r~   r   r'   abatchr   r!   get)	r?   r^   r)   r]   rL   r   ru   r\   coross	   `  ``    r1   r   zDynamicRunnable.abatch   sH      "&#f++665555W5556666X66666 	,,((x(((  #4 	          	I	D 	D 	D 	D 	D 	D 	D GXv..,WQZ^^<M-N-NWQVWWWWWWWWWWr3   Iterator[Output]c                P    |                      |          \  }} |j        ||fi |S r<   )rE   streamrZ   s        r1   r   zDynamicRunnable.stream   s6      <<//&xuf77777r3   AsyncIterator[Output]c               t   K   |                      |          \  }} |j        ||fi |2 3 d {V }|W V  6 d S r<   )rE   astreamr?   rW   r)   rL   r8   chunks         r1   r   zDynamicRunnable.astream   sv        <<//&+8+E6DDVDD 	 	 	 	 	 	 	%KKKKK EDD   7Iterator[Input]c                P    |                      |          \  }} |j        ||fi |S r<   )rE   	transformrZ   s        r1   r   zDynamicRunnable.transform  s7      <<//&!x!%::6:::r3   AsyncIterator[Input]c               t   K   |                      |          \  }} |j        ||fi |2 3 d {V }|W V  6 d S r<   )rE   
atransformr   s         r1   r   zDynamicRunnable.atransform  sv        <<//&.8.ufGGGG 	 	 	 	 	 	 	%KKKKK HGGr   namestrc                     t           j                  t                    rt                    d fd            }|S S )Nargsr
   rL   r+   c                    |                                 D ]\  }}|dk    rzt          |t                    red|v rat          |d         t                    rF
                    t	          d|                    \  }}i |d|i} t          |	          | i |c S t          |           D ]\  }}t          |t                    rqd|v rmt          |d         t                    rR
                    t	          d|                    \  }}t          |           }|||<    t          |	          |i |c S 
j        r-
                                \  }} t          |	          | i |S  | i |S )Nr)   configurabler   )	itemsrT   dictrE   r   getattr	enumerater   r)   )r   rL   keyargr8   r)   idxargslattrr   r?   s           r1   wrapperz,DynamicRunnable.__getattr__.<locals>.wrapper  s    & H HHCh"3-- '*c11&s>':DAA 2 ,0<<=Ms8S8S+T+T(&!=F!=Hf!=!=6wx66GGGGGG )$ 	I 	IHC"3--I*c11&s>':DAA 2 ,0<<=Ms8S8S+T+T(& $T

%+c
6wx66HHHHHH; D'+||~~$Hf278T22DCFCCCtT,V,,,r3   )r   r
   rL   r
   r+   r
   )r   r'   callabler   )r?   r   r   r   s   `` @r1   __getattr__zDynamicRunnable.__getattr__  sh    t|T**D>> 	4[[- - - - - - - [-8 Nr3   )r+   r,   )r+   r4   )r+   r:   )r+   r@   r<   )r)   r(   r+   rC   )r)   r(   r+   r#   )r)   r(   rL   r
   r+   rM   r)   r(   r+   rR   )rW   r   r)   r(   rL   r
   r+   r    )
r^   r_   r)   r`   r]   r,   rL   ra   r+   rb   )rW   r   r)   r(   rL   ra   r+   r   )rW   r   r)   r(   rL   ra   r+   r   )rW   r   r)   r(   rL   ra   r+   r   )rW   r   r)   r(   rL   ra   r+   r   )r   r   r+   r
   )__name__
__module____qualname____doc____annotations__r)   r   model_configclassmethodr   r2   r9   propertyr=   rB   rF   rI   rK   rQ   rE   r   rU   rY   r\   r   r   r   r   r   r   r   r.   r3   r1   r%   r%   3   s          1000'+F++++: $  L    X [ 3 3 3 X [3 & & & X X& ' ' ' X X' 151 1 1 1 X1 152 2 2 2 X2 * * * * X*  ,0
 
 
 
 X
 268 8 8 8 8" 15= = = = ^= ?C8 8 8 8 X8 ?C? ? ? ? X?  IM(V
 #((V (V (V (V (V X(VT  IM$X
 #($X $X $X $X $X X$XL  ,08 8 8 8 X8  ,0    X  ,0; ; ; ; X;  ,0    X # # # X# # #r3   r%   c                  Z    e Zd ZU dZded<   edd            Zedd
            Z	 dddZ	dS )RunnableConfigurableFieldsa  Runnable that can be dynamically configured.

    A RunnableConfigurableFields should be initiated using the
    `configurable_fields` method of a Runnable.

    Parameters:
        fields: The configurable fields to use.

    Here is an example of using a RunnableConfigurableFields with LLMs:

        .. code-block:: python

            from langchain_core.prompts import PromptTemplate
            from langchain_core.runnables import ConfigurableField
            from langchain_openai import ChatOpenAI

            model = ChatOpenAI(temperature=0).configurable_fields(
                temperature=ConfigurableField(
                    id="temperature",
                    name="LLM Temperature",
                    description="The temperature of the LLM",
                )
            )
            # This creates a RunnableConfigurableFields for a chat model.

            # When invoking the created RunnableSequence, you can pass in the
            # value for your ConfigurableField's id which in this case
            # will be change in temperature

            prompt = PromptTemplate.from_template("Pick a random number above {x}")
            chain = prompt | model

            chain.invoke({"x": 0})
            chain.invoke({"x": 0}, config={"configurable": {"temperature": 0.9}})


    Here is an example of using a RunnableConfigurableFields with HubRunnables:

        .. code-block:: python

            from langchain_core.prompts import PromptTemplate
            from langchain_core.runnables import ConfigurableField
            from langchain_openai import ChatOpenAI
            from langchain.runnables.hub import HubRunnable

            prompt = HubRunnable("rlm/rag-prompt").configurable_fields(
                owner_repo_commit=ConfigurableField(
                    id="hub_commit",
                    name="Hub Commit",
                    description="The Hub commit to pull from",
                )
            )

            prompt.invoke({"question": "foo", "context": "bar"})

            # Invoking prompt with `with_config` method

            prompt.invoke(
                {"question": "foo", "context": "bar"},
                config={"configurable": {"hub_commit": "rlm/rag-prompt-llama"}},
            )
    zdict[str, AnyConfigurableField]fieldsr+   list[ConfigurableFieldSpec]c                6   g }t          | j                  j        }| j                                        D ]\  }}t          |t                    ro|                    t          |j	        |j
        |j        p||         j        |j        p||         j        t          | j        |          |j                             |                    t          |||         j                             |                    | j        j                   t%          |          S )zGet the configuration specs for the RunnableConfigurableFields.

        Returns:
            list[ConfigurableFieldSpec]: The configuration specs.
        idr   description
annotationr'   	is_shared)typer'   model_fieldsr   r   rT   r   appendr   r   r   r   r   r   r   make_options_specextendconfig_specsr"   )r?   r   default_fields
field_namespecs        r1   r   z'RunnableConfigurableFields.config_specs  s'    dl++8 $ 1 1 3 3 	 	J$ 122 ##)7!Y$($4 %B)*5A#'? $A)*5@ 'j A A"&.	 	 	    ##%dN:,F,RSS    	DL5666&|444r3   rL   r   r&   c                8     | j         j        di i | j        |S )Nr.   )r'   configurable_fieldsr   r?   rL   s     r1   r   z.RunnableConfigurableFields.configurable_fields  s,     0t|/LL2KT[2KF2KLLLr3   Nr)   r(   rR   c                    t                    d  j                                        D             fd                    di                                           D             }fd j                                        D             }fd j                                        D             }i |||}|rB fd j        j                                        D             }  j        j        di i ||fS  j        fS )Nc                (    i | ]\  }}|j         ||fS r.   )r   )rg   r   r   s      r1   
<dictcomp>z7RunnableConfigurableFields._prepare.<locals>.<dictcomp>  s$    QQQ	TtwdQQQr3   c                ~    i | ]9\  }}|v 	t          |         d          t                    *|         d         |:S )r|   r   )rT   r   )rg   kvspecs_by_ids      r1   r   z7RunnableConfigurableFields._prepare.<locals>.<dictcomp>  sV     
 
 
1KJ{1~a/@BS$T$T N1qr3   r   c                    i | ][\  }}t          |t                    ||j                            d i                               |j                  p|j                 \S )r   )rT   r   optionsr   r   r'   rg   r   r   r)   s      r1   r   z7RunnableConfigurableFields._prepare.<locals>.<dictcomp>  sl     '
 '
 '
1!:;;'
qy&**^R88<<QTBBOaiQ'
 '
 '
r3   c                    i | ][\  }t          t                    |fd                     di                               j        j                  D             \S )c                *    g | ]}j         |         S r.   )r   )rg   or   s     r1   ri   zBRunnableConfigurableFields._prepare.<locals>.<dictcomp>.<listcomp>  s/        	!  r3   r   )rT   r   r   r   r'   r   s     @r1   r   z7RunnableConfigurableFields._prepare.<locals>.<dictcomp>  s     &
 &
 &

 1!9::&
    NB77;;AD!)LL  &
 &
 &
r3   c                R    i | ]#\  }}|t          j                  j        v  ||$S r.   )r   r'   r   )rg   r   r   r?   s      r1   r   z7RunnableConfigurableFields._prepare.<locals>.<dictcomp>  sA       AqT\**777 1777r3   r.   )r   r   r   r   r'   rP   rO   )r?   r)   r   configurable_single_optionsconfigurable_multi_optionsr   init_paramsr   s   ``     @r1   rU   z#RunnableConfigurableFields._prepare  s    v&&QQT[=N=N=P=PQQQ
 
 
 


>266<<>>
 
 

'
 '
 '
 '
))++'
 '
 '
#
&
 &
 &
 &

 ))++&
 &
 &
"
!
)
 )
  		    L17799  K '&II)HK)H<)HII  f%%r3   r+   r   rL   r   r+   r&   r<   r   )
r   r   r   r   r   r   r   r   r   rU   r.   r3   r1   r   r   ?  s         = =~ ,+++5 5 5 X5@ M M M XM 26'& '& '& '& '& '& '&r3   r   c                      e Zd ZdZdS )StrEnumzString enum.N)r   r   r   r   r.   r3   r1   r   r     s        r3   r   zyWeakValueDictionary[Union[ConfigurableFieldSingleOption, ConfigurableFieldMultiOption, ConfigurableField], type[StrEnum]]_enums_for_specc                      e Zd ZU dZded<   	 ded<   	 dZded<   	 d	ed
<   	 eedd                        Zedd            Z		 dddZ
dS ) RunnableConfigurableAlternativesa4	  Runnable that can be dynamically configured.

    A RunnableConfigurableAlternatives should be initiated using the
    `configurable_alternatives` method of a Runnable or can be
    initiated directly as well.

    Here is an example of using a RunnableConfigurableAlternatives that uses
    alternative prompts to illustrate its functionality:

        .. code-block:: python

            from langchain_core.runnables import ConfigurableField
            from langchain_openai import ChatOpenAI

            # This creates a RunnableConfigurableAlternatives for Prompt Runnable
            # with two alternatives.
            prompt = PromptTemplate.from_template(
                "Tell me a joke about {topic}"
            ).configurable_alternatives(
                ConfigurableField(id="prompt"),
                default_key="joke",
                poem=PromptTemplate.from_template("Write a short poem about {topic}")
            )

            # When invoking the created RunnableSequence, you can pass in the
            # value for your ConfigurableField's id which in this case will either be
            # `joke` or `poem`.
            chain = prompt | ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0)

            # The `with_config` method brings in the desired Prompt Runnable in your
            # Runnable Sequence.
            chain.with_config(configurable={"prompt": "poem"}).invoke({"topic": "bears"})


    Equivalently, you can initialize RunnableConfigurableAlternatives directly
    and use in LCEL in the same way:

        .. code-block:: python

            from langchain_core.runnables import ConfigurableField
            from langchain_core.runnables.configurable import RunnableConfigurableAlternatives
            from langchain_openai import ChatOpenAI

            prompt = RunnableConfigurableAlternatives(
                which=ConfigurableField(id='prompt'),
                default=PromptTemplate.from_template("Tell me a joke about {topic}"),
                default_key='joke',
                prefix_keys=False,
                alternatives={"poem":PromptTemplate.from_template("Write a short poem about {topic}")}
            )
            chain = prompt | ChatOpenAI(model="gpt-3.5-turbo-0125", temperature=0)
            chain.with_config(configurable={"prompt": "poem"}).invoke({"topic": "bears"})

    r   whichzPdict[str, Union[Runnable[Input, Output], Callable[[], Runnable[Input, Output]]]]alternativesr'   r   default_keyr,   prefix_keysr+   r   c           
         t           5  t                               j                  x}rnzt	           j        j        p j        j        d t           j        	                                           j
        gz   D                       }t          d|          t           j        <   d d d            n# 1 swxY w Y   t          t           j        j         j        j         j        j        | j
         j        j                  g j        r fd j        j        D             n j        j        z    fd j                                        D             z             S )Nc              3     K   | ]}||fV  	d S r<   r.   rg   r   s     r1   rp   z@RunnableConfigurableAlternatives.config_specs.<locals>.<genexpr>3  s:         A     r3   type[StrEnum]r   c                X    g | ]&}t          |j        j         d j                   'S ==)prefix_config_specr   r   r   )rg   sr?   s     r1   ri   zARunnableConfigurableAlternatives.config_specs.<locals>.<listcomp>G  sH        'qTZ]*P*Pd>N*P*PQQ  r3   c           	         g | ]L\  }}t          |t                    |j        D ]*}j        rt	          |j        j         d |           n|+MS r   )rT   r   r   r   r   r   r   )rg   alt_keyaltr   r?   s       r1   ri   zARunnableConfigurableAlternatives.config_specs.<locals>.<listcomp>O  s     	 	 	 !GSc#788	 )	 	  '&qTZ]*G*Gg*G*GHHH		 	 	 	r3   )_enums_for_spec_lockr   r   r   r   r   r   r   r   keysr   r   r"   r   r   r   r   r'   r   r   )r?   
which_enums   ` r1   r   z-RunnableConfigurableAlternatives.config_specs*  s    " 	P 	P,00<<<z 
P$JO4tz} !%d&7&<&<&>&>!?!?4CSBT!T   
 /3?J.O.O
+	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P ' &z} $
 6) ,"j2  	  #	/    !\6   
 \.#(	 	 	 	 %)$5$;$;$=$=	 	 	) 
  
  	
s   BB22B69B6rL   r   r&   c                ~    |                      | j         | j        j        di || j        | j        | j                  S )N)r   r'   r   r   r   r.   )rO   r   r'   r   r   r   r   r   s     r1   r   z4RunnableConfigurableAlternatives.configurable_fields[  sN     ~~*4DL4>>v>>*((  
 
 	
r3   Nr)   r(   rR   c           
         t          |          }|                    di                                j        j         j                   j        rIt          di |d fd|                    di                                           D             i          } j        k    r	 j        |fS  j	        v r2 j	                 }t          |t                    r||fS  |            |fS d }t          |          )Nr   r   c           	     X    i | ]&\  }}t          |j        j         d  d          |'S )r   /)_strremoveprefixr   r   )rg   r   r   r?   r   s      r1   r   z=RunnableConfigurableAlternatives._prepare.<locals>.<dictcomp>r  sN     % % % Aq )tz},H,H,H,H,HII1% % %r3   zUnknown alternative: )r   r   r   r   r   r   r   r   r'   r   rT   r   
ValueError)r?   r)   r   msgr   s   `   @r1   rU   z)RunnableConfigurableAlternatives._prepareg  s6    v&&

>2..224:=$BRSS 
	 " % % % % %$*JJ~r$B$B$H$H$J$J% % % 	 	F D$$$L&))D%%%#E*C#x(( %V}$CEE6?"-e--oor3   r   r   r<   r   )r   r   r   r   r   r   r   r   r   r   rU   r.   r3   r1   r   r     s         5 5n F    + K    NG -
 -
 -
 X X-
^ 	
 	
 	
 X	
 26      r3   r   r   r   prefixr+   c                ^    |                      |          r|                     |dd          n| S )z4str.removeprefix() is only available in Python 3.9+. r|   )
startswithreplace)r   r   s     r1   r   r     s.    '(||F';';B199VR###Br3   r   r   c                    | j         s8t          | d| j         | j        | j        | j        | j        | j                   n| S )al  Prefix the id of a ConfigurableFieldSpec.

    This is useful when a RunnableConfigurableAlternatives is used as a
    ConfigurableField of another RunnableConfigurableAlternatives.

    Args:
        spec: The ConfigurableFieldSpec to prefix.
        prefix: The prefix to add.

    Returns:
        ConfigurableFieldSpec: The prefixed ConfigurableFieldSpec.
    r   r   )r   r   r   r   r   r   r'   )r   r   s     r1   r   r     s\    0 ~		$$47$$(Ln	
 	
 	
 	
 r3   BUnion[ConfigurableFieldSingleOption, ConfigurableFieldMultiOption]r   Optional[str]c           	     >   t           5  t                              |           x}rnbt          | j        p| j        d t          | j                                                  D                       }t          d|          t          | <   ddd           n# 1 swxY w Y   t          | t                    r0t          | j        | j        | j        p||| j        | j                  S t          | j        | j        | j        p|t           |         | j        | j                  S )a>  Make a ConfigurableFieldSpec for a ConfigurableFieldSingleOption or ConfigurableFieldMultiOption.

    Args:
        spec: The ConfigurableFieldSingleOption or ConfigurableFieldMultiOption.
        description: The description to use if the spec does not have one.

    Returns:
        The ConfigurableFieldSpec.
    c              3     K   | ]}||fV  	d S r<   r.   r   s     r1   rp   z$make_options_spec.<locals>.<genexpr>  s&      ;;A!Q;;;;;;r3   r   Nr   )r   r   r   r   r   r   r   r   r   r   rT   r   r   r   r'   r   r   )r   r   enums      r1   r   r     st    
 @ @"&&t,,,4 	@	$TW;;dl&7&7&9&9!:!:;;; D %)$$?$?OD!@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ $566 
$w(7KLn
 
 
 	
 !7Y$3D>.   s   B BBB)r   r   r   r   r+   r   )r   r   r   r   r+   r   )r   r  r   r  r+   r   )=r   
__future__r   r
  	threadingabcr   collections.abcr   r   r   	functoolsr   typingr	   r
   r   r   r   r   weakrefr   pydanticr   r   typing_extensionsr   langchain_core.runnables.baser   r   langchain_core.runnables.configr   r   r   r   r   langchain_core.runnables.utilsr   r   r   r   r   r   r    r!   r"   langchain_core.runnables.graphr#   r%   r   r   Enumr   r   r   Lockr   r   r   r   r   r.   r3   r1   <module>r     si   3 3 3 " " " " " "                    
                      ( ' ' ' ' ' * * * * * * * * & & & & & & H H H H H H H H             
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  5444444I I I I I*5&=9 I I IXP& P& P& P& P&!? P& P& P&h    c49          &y~'' ` ` ` ` `uf}'E ` ` `FC C C C
   :& & & & & &r3   