a
    bg-	                     @   sH   d Z ddlZddlmZmZmZ ddlmZmZm	Z	 G dd deZ
dS )zUtil that calls Lambda.    N)AnyDictOptional)	BaseModel
ConfigDictmodel_validatorc                   @   s   e Zd ZU dZdZeed< dZee	 ed< dZ
ee	 ed< dZee	 ed< eddZed	d
eeedddZe	e	dddZdS )LambdaWrappera7  Wrapper for AWS Lambda SDK.
    To use, you should have the ``boto3`` package installed
    and a lambda functions built from the AWS Console or
    CLI. Set up your AWS credentials with ``aws configure``

    Example:
        .. code-block:: bash

            pip install boto3

            aws configure

    Nlambda_clientfunction_nameawslambda_tool_nameawslambda_tool_descriptionZforbid)extrabefore)mode)valuesreturnc                 C   s:   zddl }W n ty&   tdY n0 |d|d< |S )z3Validate that python package exists in environment.r   NzBboto3 is not installed. Please install it with `pip install boto3`lambdar	   )boto3ImportErrorclient)clsr   r    r   u/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/utilities/awslambda.pyvalidate_environment%   s    
z"LambdaWrapper.validate_environment)queryr   c                 C   s~   | j j| jdtd|id}z(|d }| d}t|d }W n tyZ   Y dS 0 |du sl|dkrpd	S d
| S dS )z
        Invokes the lambda function and returns the
        result.

        Args:
            query: an input to passed to the lambda
                function as the ``body`` of a JSON
                object.
        ZRequestResponsebody)ZFunctionNameZInvocationTypePayloadr   zutf-8z$Failed to parse response from LambdaN zRequest failed.zResult: )	r	   Zinvoker
   jsondumpsreaddecodeloadsStopIteration)selfr   resZpayload_streamZpayload_stringZanswerr   r   r   run5   s    
zLambdaWrapper.run)__name__
__module____qualname____doc__r	   r   __annotations__r
   r   strr   r   r   Zmodel_configr   classmethodr   r   r&   r   r   r   r   r   	   s   
r   )r*   r   typingr   r   r   Zpydanticr   r   r   r   r   r   r   r   <module>   s   