
    Ng-	                     V    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e          Z
dS )zUtil that calls Lambda.    N)AnyDictOptional)	BaseModel
ConfigDictmodel_validatorc                       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          Z ed	
          ededefd                        Zde	de	f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_descriptionforbid)extrabefore)modevaluesreturnc                 |    	 ddl }n# t          $ r t          d          w xY w|                    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   s      c/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/awslambda.pyvalidate_environmentz"LambdaWrapper.validate_environment%   s_    
	LLLL 	 	 	T  	
 #(,,x"8"8s    !queryc                 D   | j                             | j        dt          j        d|i                    }	 |d         }|                                                    d          }t          j        |          d         }n# t          $ r Y dS w xY w||dk    r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.
        RequestResponsebody)FunctionNameInvocationTypePayloadr#   zutf-8z$Failed to parse response from LambdaN zRequest failed.zResult: )	r   invoker   jsondumpsreaddecodeloadsStopIteration)selfr   respayload_streampayload_stringanswers         r   runzLambdaWrapper.run5   s      ''+,J// ( 
 
	: ^N+002299'BBNZ//7FF 	: 	: 	:999	: >Vr\\$$&f&&&s   A	B 
BB)__name__
__module____qualname____doc__r   r   __annotations__r   r   strr   r   r   model_configr   classmethodr   r   r1        r   r
   r
   	   s           M3%#'M8C='''*)-#---904444;:  L _(###$ 3    [ $#' ' ' ' ' ' ' 'r;   r
   )r5   r&   typingr   r   r   pydanticr   r   r   r
   r:   r;   r   <module>r>      s       & & & & & & & & & & ; ; ; ; ; ; ; ; ; ;H' H' H' H' H'I H' H' H' H' H'r;   