a
    •˜ëjõ  ã                   @   sœ   d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZ d dl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
ef ƒZdS )é    )ÚMapping)Ú
itemgetter)ÚAnyÚCallableÚOptionalÚUnion)ÚBaseMessage)ÚJsonOutputFunctionsParser)ÚRouterRunnableÚRunnable)ÚRunnableBindingBase)Ú	TypedDictc                   @   s*   e Zd ZU dZeed< eed< eed< dS )ÚOpenAIFunctionz&A function description for ChatOpenAI.ÚnameÚdescriptionÚ
parametersN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__Údict© r   r   úc/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain/runnables/openai_functions.pyr      s
   
r   c                       sf   e Zd ZU dZeee  ed< dee	e
eeef eegef f f eee  dœ‡ fdd„Z‡  ZS )ÚOpenAIFunctionsRouterz0A runnable that routes to the selected function.Ú	functionsN)Ú	runnablesr   c                    s€   |durFt |ƒt ˆ ƒkr$d}t|ƒ‚t‡ fdd„|D ƒƒsFd}t|ƒ‚tdd�tdƒtd	ƒd
œB tˆ ƒB }tƒ j|i |d� dS )zÐInitialize the OpenAIFunctionsRouter.

        Args:
            runnables: A mapping of function names to runnables.
            functions: Optional list of functions to check against the runnables.
        Nz?The number of functions does not match the number of runnables.c                 3   s   | ]}|d  ˆ v V  qdS )r   Nr   )Ú.0Úfunc©r   r   r   Ú	<genexpr>1   ó    z1OpenAIFunctionsRouter.__init__.<locals>.<genexpr>z6One or more function names are not found in runnables.F)Z	args_onlyr   Ú	arguments)ÚkeyÚinput)ÚboundÚkwargsr   )ÚlenÚ
ValueErrorÚallr	   r   r
   ÚsuperÚ__init__)Úselfr   r   ÚmsgZrouter©Ú	__class__r    r   r,      s    ÿþÿzOpenAIFunctionsRouter.__init__)N)r   r   r   r   r   Úlistr   r   r   r   r   r   r   r   r   r,   Ú__classcell__r   r   r/   r   r      s   
 ÷
ÿÿÿÿ
÷r   N)Úcollections.abcr   Úoperatorr   Útypingr   r   r   r   Zlangchain_core.messagesr   Z.langchain_core.output_parsers.openai_functionsr	   Zlangchain_core.runnablesr
   r   Zlangchain_core.runnables.baser   Ztyping_extensionsr   r   r   r   r   r   r   Ú<module>   s   