§
    ™Štj»  ã                  ó¢  — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddl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 ddlm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# ddl$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+  G d„ de¦  «        Z, e
ded¬¦  «         G d„ de¦  «        ¦   «         Z- e
ded¬¦  «         G d„ de¦  «        ¦   «         Z.dS )zOAttempt to implement MRKL systems as described in arxiv.org/pdf/2205.00445.pdf.é    )Úannotations)ÚCallableÚSequence)ÚAnyÚ
NamedTuple)Ú
deprecated)ÚBaseCallbackManager)ÚBaseLanguageModel)ÚPromptTemplate)ÚBaseToolÚTool)Úrender_text_description)ÚField)Úoverride)ÚAGENT_DEPRECATION_WARNING)ÚAgentÚAgentExecutorÚAgentOutputParser)Ú	AgentType©ÚMRKLOutputParser)ÚFORMAT_INSTRUCTIONSÚPREFIXÚSUFFIX)Úvalidate_tools_single_input)ÚLLMChainc                  ó2   — e Zd ZU dZded<   ded<   ded<   dS )ÚChainConfigzÉConfiguration for a chain to use in MRKL system.

    Args:
        action_name: Name of the action.
        action: Action function to call.
        action_description: Description of the action.
    ÚstrÚaction_namer   ÚactionÚaction_descriptionN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© ó    ú`/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_classic/agents/mrkl/base.pyr   r      sB   € € € € € € ðð ð ÐÐÑØÐÐÑØÐÐÑÐÐr)   r   z0.1.0z2.0.0)ÚmessageÚremovalc                  ó  ‡ — e Zd ZU dZ ee¬¦  «        Zded<   ee	d d„¦   «         ¦   «         Z
ed!d
„¦   «         Zed!d„¦   «         Zed!d„¦   «         Zeeeedfd"d„¦   «         Zeddeeedfd#d„¦   «         Zed$ˆ fd„¦   «         Zˆ xZS )%ÚZeroShotAgentz]Agent for the MRKL chain.

    Args:
        output_parser: Output parser for the agent.
    )Údefault_factoryr   Úoutput_parserÚkwargsr   Úreturnc                ó   — t          ¦   «         S )Nr   )Úclsr1   s     r*   Ú_get_default_output_parserz(ZeroShotAgent._get_default_output_parser6   s   € õ  Ñ!Ô!Ð!r)   r   c                ó   — t           j        S )z Return Identifier of agent type.)r   ÚZERO_SHOT_REACT_DESCRIPTION©Úselfs    r*   Ú_agent_typezZeroShotAgent._agent_type;   s   € õ Ô4Ð4r)   c                ó   — dS )z]Prefix to append the observation with.

        Returns:
            "Observation: "
        zObservation: r(   r8   s    r*   Úobservation_prefixz ZeroShotAgent.observation_prefix@   s	   € ð ˆr)   c                ó   — dS )zVPrefix to append the llm call with.

        Returns:
            "Thought: "
        zThought:r(   r8   s    r*   Ú
llm_prefixzZeroShotAgent.llm_prefixI   s	   € ð ˆzr)   NÚtoolsúSequence[BaseTool]ÚprefixÚsuffixÚformat_instructionsÚinput_variablesúlist[str] | Noner   c                ó  — t          t          |¦  «        ¦  «        }d                     d„ |D ¦   «         ¦  «        }|                     |¬¦  «        }|› d|› d|› d|› �}|rt	          ||¬¦  «        S t	          j        |¦  «        S )a(  Create prompt in the style of the zero shot agent.

        Args:
            tools: List of tools the agent will have access to, used to format the
                prompt.
            prefix: String to put before the list of tools.
            suffix: String to put after the list of tools.
            format_instructions: Instructions on how to use the tools.
            input_variables: List of input variables the final prompt will expect.


        Returns:
            A PromptTemplate with the template assembled from the pieces here.
        z, c                ó   — g | ]	}|j         ‘Œ
S r(   ©Úname©Ú.0Útools     r*   ú
<listcomp>z/ZeroShotAgent.create_prompt.<locals>.<listcomp>j   s   € Ð<Ð<Ð<¨d ¤	Ð<Ð<Ð<r)   )Ú
tool_namesz

)ÚtemplaterD   )r   ÚlistÚjoinÚformatr   Úfrom_template)	r4   r?   rA   rB   rC   rD   Útool_stringsrN   rO   s	            r*   Úcreate_promptzZeroShotAgent.create_promptR   sŸ   € õ. /­t°E©{¬{Ñ;Ô;ˆØ—Y’YÐ<Ð<°eÐ<Ñ<Ô<Ñ=Ô=ˆ
Ø1×8Ò8ÀJÐ8ÑOÔOÐØÐUÐU ,ÐUÐUÐ4GÐUÐUÈVÐUÐUˆØð 	VÝ!¨8À_ÐUÑUÔUÐUÝÔ+¨HÑ5Ô5Ð5r)   Úllmr
   Úcallback_managerúBaseCallbackManager | NoneúAgentOutputParser | Noner   c	                óà   — |                       |¦  «         |                      |||||¬¦  «        }
t          ||
|¬¦  «        }d„ |D ¦   «         }|p|                      ¦   «         } | d|||dœ|	¤ŽS )a  Construct an agent from an LLM and tools.

        Args:
            llm: The LLM to use as the agent LLM.
            tools: The tools to use.
            callback_manager: The callback manager to use.
            output_parser: The output parser to use.
            prefix: The prefix to use.
            suffix: The suffix to use.
            format_instructions: The format instructions to use.
            input_variables: The input variables to use.
            kwargs: Additional parameters to pass to the agent.
        )rA   rB   rC   rD   )rV   ÚpromptrW   c                ó   — g | ]	}|j         ‘Œ
S r(   rH   rJ   s     r*   rM   z4ZeroShotAgent.from_llm_and_tools.<locals>.<listcomp>˜   s   € Ð2Ð2Ð2 D�d”iÐ2Ð2Ð2r)   )Ú	llm_chainÚallowed_toolsr0   r(   )Ú_validate_toolsrU   r   r5   )r4   rV   r?   rW   r0   rA   rB   rC   rD   r1   r[   r]   rN   Ú_output_parsers                 r*   Úfrom_llm_and_toolsz ZeroShotAgent.from_llm_and_toolsq   s¼   € ð4 	×Ò˜EÑ"Ô"Ð"Ø×"Ò"ØØØØ 3Ø+ð #ñ 
ô 
ˆõ ØØØ-ð
ñ 
ô 
ˆ	ð
 3Ð2¨EÐ2Ñ2Ô2ˆ
Ø&ÐJ¨#×*HÒ*HÑ*JÔ*JˆØˆsð 
ØØ$Ø(ð
ð 
ð ð	
ð 
ð 	
r)   ÚNonec                ó  •— t          | j        |¦  «         t          |¦  «        dk    rd| j        › d�}t          |¦  «        ‚|D ]#}|j        €d|j        › d�}t          |¦  «        ‚Œ$t          ¦   «                              |¦  «         d S )Nr   zGot no tools for z%. At least one tool must be provided.zGot a tool zN without a description. For this agent, a description must always be provided.)r   r#   ÚlenÚ
ValueErrorÚdescriptionrI   Úsuperr_   )r4   r?   ÚmsgrL   Ú	__class__s       €r*   r_   zZeroShotAgent._validate_tools¡   s¯   ø€ å# C¤L°%Ñ8Ô8Ð8Ýˆu‰:Œ:˜Š?ˆ?àW C¤LÐWÐWÐWð õ ˜S‘/”/Ð!Øð 	&ð 	&ˆDØÔÐ'ð> $¤)ð >ð >ð >ð õ ! ‘o”oÐ%ð (õ 	‰Œ×Ò Ñ&Ô&Ð&Ð&Ð&r)   )r1   r   r2   r   )r2   r   )r?   r@   rA   r   rB   r   rC   r   rD   rE   r2   r   )rV   r
   r?   r@   rW   rX   r0   rY   rA   r   rB   r   rC   r   rD   rE   r1   r   r2   r   )r?   r@   r2   rb   )r#   r$   r%   r&   r   r   r0   r'   Úclassmethodr   r5   Úpropertyr:   r<   r>   r   r   r   rU   ra   r_   Ú__classcell__)ri   s   @r*   r.   r.   (   sk  ø€ € € € € € ðð ð (- uÐ=MÐ'NÑ'NÔ'N€MÐNÐNÐNÑNàØð"ð "ð "ñ „Xñ „[ð"ð ð5ð 5ð 5ñ „Xð5ð ðð ð ñ „Xðð ðð ð ñ „Xðð ð ØØ#6Ø,0ð6ð 6ð 6ð 6ñ „[ð6ð< ð
 8<Ø26ØØØ#6Ø,0ð-
ð -
ð -
ð -
ñ „[ð-
ð^ ð'ð 'ð 'ð 'ð 'ñ „[ð'ð 'ð 'ð 'ð 'r)   r.   c                  ó*   — e Zd ZdZedd
„¦   «         ZdS )Ú	MRKLChainz&Chain that implements the MRKL system.rV   r
   Úchainsúlist[ChainConfig]r1   r   r2   r   c                óf   — d„ |D ¦   «         }t                                ||¦  «        } | d||dœ|¤ŽS )a�  User-friendly way to initialize the MRKL chain.

        This is intended to be an easy way to get up and running with the
        MRKL chain.

        Args:
            llm: The LLM to use as the agent LLM.
            chains: The chains the MRKL system has access to.
            **kwargs: parameters to be passed to initialization.

        Returns:
            An initialized MRKL chain.
        c                óP   — g | ]#}t          |j        |j        |j        ¬ ¦  «        ‘Œ$S ))rI   Úfuncrf   )r   r    r!   r"   )rK   Úcs     r*   rM   z)MRKLChain.from_chains.<locals>.<listcomp>Ï   sI   € ð 
ð 
ð 
ð õ Ø”]Ø”XØÔ0ðñ ô ð
ð 
ð 
r)   )Úagentr?   r(   )r.   ra   )r4   rV   ro   r1   r?   ru   s         r*   Úfrom_chainszMRKLChain.from_chains»   sV   € ð(
ð 
ð ð
ñ 
ô 
ˆõ ×0Ò0°°eÑ<Ô<ˆØˆsÐ6˜ eÐ6Ð6¨vÐ6Ð6Ð6r)   N)rV   r
   ro   rp   r1   r   r2   r   )r#   r$   r%   r&   rj   rv   r(   r)   r*   rn   rn   ³   s:   € € € € € ð 1Ð0àð7ð 7ð 7ñ „[ð7ð 7ð 7r)   rn   N)/r&   Ú
__future__r   Úcollections.abcr   r   Útypingr   r   Úlangchain_core._apir   Úlangchain_core.callbacksr	   Úlangchain_core.language_modelsr
   Úlangchain_core.promptsr   Úlangchain_core.toolsr   r   Úlangchain_core.tools.renderr   Úpydanticr   Útyping_extensionsr   Ú"langchain_classic._api.deprecationr   Úlangchain_classic.agents.agentr   r   r   Ú$langchain_classic.agents.agent_typesr   Ú+langchain_classic.agents.mrkl.output_parserr   Ú$langchain_classic.agents.mrkl.promptr   r   r   Úlangchain_classic.agents.utilsr   Úlangchain_classic.chainsr   r   r.   rn   r(   r)   r*   ú<module>r‰      s\  ðØ UÐ Uà "Ð "Ð "Ð "Ð "Ð "à .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à *Ð *Ð *Ð *Ð *Ð *Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø <Ð <Ð <Ð <Ð <Ð <Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &à HÐ HÐ HÐ HÐ HÐ HØ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RØ :Ð :Ð :Ð :Ð :Ð :Ø HÐ HÐ HÐ HÐ HÐ HØ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TØ FÐ FÐ FÐ FÐ FÐ FØ -Ð -Ð -Ð -Ð -Ð -ðð ð ð ð �*ñ ô ð ð €ØØ%Øðñ ô ð
C'ð C'ð C'ð C'ð C'�Eñ C'ô C'ñô ð
C'ðL €ØØ%Øðñ ô ð
 7ð  7ð  7ð  7ð  7�ñ  7ô  7ñô ð
 7ð  7ð  7r)   