
    Ng                        d Z ddlmZ ddlmZ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 erddlmZ d	eed	d	d
d	dddd	fd)d(Zd	S )*zOpenAPI spec agent.    )annotations)TYPE_CHECKINGAnyDictListOptional)BaseCallbackManager)BaseLanguageModel)OPENAPI_PREFIXOPENAPI_SUFFIX)OpenAPIToolkitAgentExecutorN   forceFllmr
   toolkitr   callback_managerOptional[BaseCallbackManager]prefixstrsuffixformat_instructionsOptional[str]input_variablesOptional[List[str]]max_iterationsOptional[int]max_execution_timeOptional[float]early_stopping_methodverboseboolreturn_intermediate_stepsagent_executor_kwargsOptional[Dict[str, Any]]kwargsr   returnr   c                    ddl m} ddlm} ddlm} |                                }|d|ini } |j        |f|||d|} || ||          }d	 |D             } |d||d
|} |j        d||||
||||	d|pi S )a  Construct an OpenAPI agent from an LLM and tools.

    *Security Note*: When creating an OpenAPI agent, check the permissions
        and capabilities of the underlying toolkit.

        For example, if the default implementation of OpenAPIToolkit
        uses the RequestsToolkit which contains tools to make arbitrary
        network requests against any URL (e.g., GET, POST, PATCH, PUT, DELETE),

        Control access to who can submit issue requests using this toolkit and
        what network access it has.

        See https://python.langchain.com/docs/security for more information.

    Args:
        llm: The language model to use.
        toolkit: The OpenAPI toolkit.
        callback_manager: Optional. The callback manager. Default is None.
        prefix: Optional. The prefix for the prompt. Default is OPENAPI_PREFIX.
        suffix: Optional. The suffix for the prompt. Default is OPENAPI_SUFFIX.
        format_instructions: Optional. The format instructions for the prompt.
            Default is None.
        input_variables: Optional. The input variables for the prompt. Default is None.
        max_iterations: Optional. The maximum number of iterations. Default is 15.
        max_execution_time: Optional. The maximum execution time. Default is None.
        early_stopping_method: Optional. The early stopping method. Default is "force".
        verbose: Optional. Whether to print verbose output. Default is False.
        return_intermediate_steps: Optional. Whether to return intermediate steps.
            Default is False.
        agent_executor_kwargs: Optional. Additional keyword arguments
            for the agent executor.
        kwargs: Additional arguments.

    Returns:
        The agent executor.
    r   r   )ZeroShotAgent)LLMChainNr   )r   r   r   )r   promptr   c                    g | ]	}|j         
S  )name).0tools     k/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/agent_toolkits/openapi/base.py
<listcomp>z(create_openapi_agent.<locals>.<listcomp>^   s    ...$)...    )	llm_chainallowed_tools)agenttoolsr   r"   r$   r   r   r!   r.   )	langchain.agents.agentr   langchain.agents.mrkl.baser*   langchain.chains.llmr+   	get_toolscreate_promptfrom_agent_and_tools)r   r   r   r   r   r   r   r   r   r!   r"   r$   r%   r'   r   r*   r+   r8   prompt_paramsr,   r5   
tool_namesr7   s                          r2   create_openapi_agentrA      s:   h 544444888888------E * 
 344 
 )]('	 
  F )  I
 /....JMRIZRR6RRE-=- 
)";%-3
 
 !&B
 
 
r4   )r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r"   r#   r$   r#   r%   r&   r'   r   r(   r   )__doc__
__future__r   typingr   r   r   r   r   langchain_core.callbacksr	   langchain_core.language_modelsr
   1langchain_community.agent_toolkits.openapi.promptr   r   2langchain_community.agent_toolkits.openapi.toolkitr   r9   r   rA   r.   r4   r2   <module>rI      s     " " " " " " ; ; ; ; ; ; ; ; ; ; ; ; ; ; 8 8 8 8 8 8 < < < < < <        N M M M M M 5444444 7;  )-+/$&*.!(&+6:V V V V V V Vr4   