
    dh                         S SK JrJrJrJrJr  S SKrS SKJr  S SK	J
r
  S SKJr  S SKJr   " S S5      r " S	 S
\
5      rg)    )AnyDictListMappingOptionalN)CallbackManagerForLLMRun)LLM)
ConfigDict)enforce_stop_tokensc            	       h    \ rS rSrSr\S\S\\\4   S\\\4   4S j5       r	\S\S\4S j5       r
S	rg
)ContentHandlerAmazonAPIGateway   zAdapter to prepare the inputs from Langchain to a format
that LLM model expects.

It also provides helper function to extract
the generated text from the model response.promptmodel_kwargsreturnc                 
    XS.$ )N)inputs
parameters )clsr   r   s      c/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/llms/amazon_api_gateway.pytransform_input.ContentHandlerAmazonAPIGateway.transform_input   s     !==    responsec                 .    UR                  5       S   S   $ )Nr   generated_text)json)r   r   s     r   transform_output/ContentHandlerAmazonAPIGateway.transform_output   s    }}q!"233r   r   N)__name__
__module____qualname____firstlineno____doc__classmethodstrr   r   r   r   __static_attributes__r   r   r   r   r      se    3 >>(,S#X>	c3h> >
 4 4 4 4r   r   c                       \ rS rSr% Sr\\S'    Sr\\	   \S'    Sr
\\	   \S'    \" 5       r\\S'    \" SS	9r\S
\\\4   4S j5       r\S
\4S j5       r  SS\S\\\      S\\   S\S
\4
S jjrSrg)AmazonAPIGateway   z6Amazon API Gateway to access LLM models hosted on AWS.api_urlNheadersr   content_handlerforbid)extrar   c                 j    U R                   =(       d    0 n0 U R                  U R                  S.ESU0E$ )zGet the identifying parameters.)r,   r-   r   )r   r,   r-   )self_model_kwargss     r   _identifying_params$AmazonAPIGateway._identifying_params3   s@     ))/R
,,4<<@
}-
 	
r   c                     g)zReturn type of llm.amazon_api_gatewayr   )r2   s    r   	_llm_typeAmazonAPIGateway._llm_type<   s     $r   r   stoprun_managerkwargsc                 N   U R                   =(       d    0 nU R                  R                  X5      n [        R                  " U R
                  U R                  US9nU R                  R                  U5      nUb  [        X5      nU$ ! [         a  n	[        SU	 35      eSn	A	ff = f)a  Call out to Amazon API Gateway model.

Args:
    prompt: The prompt to pass into the model.
    stop: Optional list of stop words to use when generating.

Returns:
    The string generated by the model.

Example:
    .. code-block:: python

        response = se("Tell me a joke.")
)r-   r   zError raised by the service: N)r   r.   r   requestspostr,   r-   r   	Exception
ValueErrorr   )
r2   r   r:   r;   r<   r3   payloadr   texterrors
             r   _callAmazonAPIGateway._callA   s    * ))/R&&66vM		F}}H
 ''88BD
 &t2D  	F<UGDEE	Fs   AB 
B$BB$r   )NN)r!   r"   r#   r$   r%   r'   __annotations__r-   r   r   r   r   r.   r
   model_configpropertyr   r   r4   r8   r   r   rE   r(   r   r   r   r*   r*      s    @L"GXd^"C#'L(4.'16T6VO3V
 L 
WS#X%6 
 
 $3 $ $ %):>	&& tCy!& 67	&
 & 
& &r   r*   )typingr   r   r   r   r   r>   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   pydanticr
   langchain_community.llms.utilsr   r   r*   r   r   r   <module>rO      s2    5 5  = 3  >4 4$Js Jr   