o
    .ifY                     @   sx   d Z ddlmZmZmZ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 G dd deZG d	d
 d
eZdS )zEChain pipeline where the outputs of one step feed directly into next.    )AnyDictListOptional)Extraroot_validator)get_color_mapping)AsyncCallbackManagerForChainRunCallbackManagerForChainRun)Chainc                	   @   s   e Zd ZU dZee ed< ee ed< ee ed< dZe	ed< G dd dZ
ed	ee fd
dZed	ee fddZeddded	efddZ	ddeeef dee d	eeef fddZ	ddeeef dee d	eeef fddZdS )SequentialChainz=Chain where the outputs of one chain feed directly into next.chainsinput_variablesoutput_variablesF
return_allc                   @      e Zd ZdZejZdZdS )zSequentialChain.Config'Configuration for this pydantic object.TN__name__
__module____qualname____doc__r   forbidextraarbitrary_types_allowed r   r   T/var/www/html/corbot_env/lib/python3.10/site-packages/langchain/chains/sequential.pyConfig       r   returnc                 C      | j S )zIReturn expected input keys to the chain.

        :meta private:
        )r   selfr   r   r   
input_keys      zSequentialChain.input_keysc                 C   r    z3Return output key.

        :meta private:
        )r   r!   r   r   r   output_keys$   r$   zSequentialChain.output_keysT)prevaluesc           
      C   sR  |d }|d }t  }d|v r:|d dur:	 |d j}t|t|r:t|t|@ }tdd| d| dt|| }|D ]6}t|j|}|jrV||jj}|rbtd	| d
| ||j	}|rqtd| |t|j	O }qBd|vr|
ddr||}	n|d j	}	|	|d< |S t|d |}|rtd| d|S )z6Validate that the correct inputs exist for all chains.r   r   memoryNzThe input key(s)  z are found in the Memory keys (z8) - please use input and memory keys that don't overlap.zMissing required input keys: z, only had z(Chain returned keys that already exist: r   r   Fz/Expected output variables that were not found: .)listmemory_variablessetintersection
ValueErrorjoinr#   
differencer)   r&   get)
clsr(   r   r   memory_keysoverlapping_keysknown_variableschainmissing_varsr&   r   r   r   validate_chains,   sT   


zSequentialChain.validate_chainsNinputsrun_managerc                    s\   |   |p	t }t| jD ]\}}| }| d|d} | q fdd| jD S )NTreturn_only_outputs	callbacksc                       i | ]}| | qS r   r   .0kknown_valuesr   r   
<dictcomp>k       z)SequentialChain._call.<locals>.<dictcomp>)copyr
   get_noop_manager	enumerater   	get_childupdater   )r"   r<   r=   _run_managerir9   r@   outputsr   rE   r   _call`   s   zSequentialChain._callc                    sf   |   |p
t }| }t| jD ]\}}|j d|dI d H } | q fdd| jD S )NTr>   c                    rA   r   r   rB   rE   r   r   rG   z   rH   z*SequentialChain._acall.<locals>.<dictcomp>)	rI   r	   rJ   rL   rK   r   acallrM   r   )r"   r<   r=   rN   r@   rO   r9   rP   r   rE   r   _acallm   s   zSequentialChain._acallN)r   r   r   r   r   r   __annotations__strr   boolr   propertyr#   r&   r   r   r;   r   r
   rQ   r   r	   rS   r   r   r   r   r      s:   
 6




r   c                	   @   s   e Zd ZU dZee ed< dZeed< dZ	e
ed< dZe
ed< G d	d
 d
Zedee
 fddZedee
 fddZe dedefddZ	ddee
e
f dee dee
e
f fddZ	ddee
ef dee dee
ef fddZdS )SimpleSequentialChainzCSimple chain where the outputs of one step feed directly into next.r   Fstrip_outputsinput	input_keyoutput
output_keyc                   @   r   )zSimpleSequentialChain.Configr   TNr   r   r   r   r   r      r   r   r   c                 C      | j gS )z2Expect input key.

        :meta private:
        )r\   r!   r   r   r   r#         z SimpleSequentialChain.input_keysc                 C   r_   r%   )r^   r!   r   r   r   r&      r`   z!SimpleSequentialChain.output_keysr(   c                 C   sf   |d D ],}t |jdkrtd| dt |j dt |jdkr0td| dt |j dq|S )z1Validate that chains are all single input/output.r      z=Chains used in SimplePipeline should all have one input, got z with z inputs.z>Chains used in SimplePipeline should all have one output, got z	 outputs.)lenr#   r1   r&   )r5   r(   r9   r   r   r   r;      s&   z%SimpleSequentialChain.validate_chainsNr<   r=   c                 C   s   |pt  }|| j }tdd tt| jD }t| jD ](\}}|j||	d|d  d}| j
r8| }|j||t| d| jd q| j|iS )Nc                 S      g | ]}t |qS r   rV   rC   rO   r   r   r   
<listcomp>       z/SimpleSequentialChain._call.<locals>.<listcomp>step_ra   r@   
colorendverbose)r
   rJ   r\   r   rangerb   r   rK   runrL   rZ   stripon_textrV   rn   r^   r"   r<   r=   rN   _inputcolor_mappingrO   r9   r   r   r   rQ      s   

zSimpleSequentialChain._callc                    s   |pt  }|| j }tdd tt| jD }t| jD ].\}}|j||	d|d  dI d H }| j
r<| }|j||t| d| jdI d H  q| j|iS )Nc                 S   rc   r   rd   re   r   r   r   rf      rg   z0SimpleSequentialChain._acall.<locals>.<listcomp>rh   ra   ri   rj   rk   )r	   rJ   r\   r   ro   rb   r   rK   arunrL   rZ   rq   rr   rV   rn   r^   rs   r   r   r   rS      s   

zSimpleSequentialChain._acallrT   )r   r   r   r   r   r   rU   rZ   rW   r\   rV   r^   r   rX   r#   r&   r   r   r;   r   r
   rQ   r   r	   rS   r   r   r   r   rY   }   s:   
 




rY   N)r   typingr   r   r   r   langchain_core.pydantic_v1r   r   langchain_core.utils.inputr   langchain.callbacks.managerr	   r
   langchain.chains.baser   r   rY   r   r   r   r   <module>   s    o