o
    `+ i                     @  s   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZmZmZ ddlmZ ddlmZ G d	d
 d
e	ZG dd deeZG dd deZdS )zBase classes for chain routing.    )annotations)ABC)Mapping)Any
NamedTupleOptional)AsyncCallbackManagerForChainRunCallbackManagerForChainRun	Callbacks)
ConfigDict)Chainc                   @  s   e Zd ZU ded< ded< dS )RoutezOptional[str]destinationdict[str, Any]next_inputsN)__name__
__module____qualname____annotations__ r   r   h/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/langchain/chains/router/base.pyr      s   
 r   c                   @  s8   e Zd ZdZedddZddddZ	ddddZdS )RouterChainzHChain that outputs the name of a destination chain and the inputs to it.return	list[str]c                 C  s   ddgS )Nr   r   r   selfr   r   r   output_keys   s   zRouterChain.output_keysNinputsr   	callbacksr
   r   c                 C  s   | ||d}t |d |d S )z
        Route inputs to a destination chain.

        Args:
            inputs: inputs to the chain
            callbacks: callbacks to use for the chain

        Returns:
            a Route object
        r   r   r   )r   r   r   r   resultr   r   r   route   s   zRouterChain.routec                   s(   | j ||dI d H }t|d |d S )Nr   r   r   )acallr   r    r   r   r   aroute-   s   zRouterChain.arouter   r   N)r   r   r   r
   r   r   )r   r   r   __doc__propertyr   r"   r$   r   r   r   r   r      s    r   c                   @  s   e Zd ZU dZded< 	 ded< 	 ded< 	 dZd	ed
< 	 edddZedddZ	edddZ
	dd ddZ	dd!ddZdS )"MultiRouteChainzIUse a single chain to route an input to one of multiple candidate chains.r   router_chainzMapping[str, Chain]destination_chainsr   default_chainFboolsilent_errorsTZforbid)Zarbitrary_types_allowedextrar   r   c                 C  s   | j jS )zWWill be whatever keys the router chain prompt expects.

        :meta private:
        )r*   
input_keysr   r   r   r   r0   H   s   zMultiRouteChain.input_keysc                 C  s   g S )z=Will always return text key.

        :meta private:
        r   r   r   r   r   r   P   s   zMultiRouteChain.output_keysNr   r   run_manager$Optional[CallbackManagerForChainRun]c                 C  s   |pt  }| }| jj||d}|jt|jd t|j | j	d |js/| j
|j|dS |j| jv r@| j|j |j|dS | jrK| j
|j|dS d|j d}t|Nr   z: )verbosez)Received invalid destination chain name '')r	   get_noop_manager	get_childr*   r"   on_textstrr   r   r4   r,   r+   r.   
ValueErrorr   r   r1   Z_run_managerr   r"   msgr   r   r   _callX   s$   
zMultiRouteChain._call)Optional[AsyncCallbackManagerForChainRun]c                   s   |pt  }| }| jj||dI d H }|jt|jd t|j | j	dI d H  |js:| j
j|j|dI d H S |j| jv rO| j|j j|j|dI d H S | jr^| j
j|j|dI d H S d|j d}t|r3   )r   r6   r7   r*   r$   r8   r9   r   r   r4   r,   r#   r+   r.   r:   r;   r   r   r   _acallq   s2   zMultiRouteChain._acallr%   r&   )r   r   r1   r2   r   r   )r   r   r1   r>   r   r   )r   r   r   r'   r   r.   r   Zmodel_configr(   r0   r   r=   r?   r   r   r   r   r)   6   s,   
 
r)   N)r'   
__future__r   abcr   collections.abcr   typingr   r   r   Zlangchain_core.callbacksr   r	   r
   Zpydanticr   Zlangchain.chains.baser   r   r   r)   r   r   r   r   <module>   s    