chain with an Amazon SageMaker Jumpstart hosted LLM. You should have an Amazon SageMaker Jumpstart hosted LLM endpoint within your AWS Account. endpoint_name = "<SAGEMAKER_ENDPOINT_NAME>" # replace with your SageMaker Endpoint namefrom langchain.llms import SagemakerEndpointfrom langchain.llms.sagemaker_endpoint import LLMContentHandlerfrom langchain.chains import LLMChainfrom langchain.prompts import load_prompt, PromptTemplateimport jsonclass ContentHandler(LLMContentHandler):    content_type = "application/json"    accepts = "application/json"    def transform_input(self, prompt: str, model_kwargs: dict) -> bytes:        input_str = json.dumps({"text_inputs": prompt,  **model_kwargs})        return input_str.encode('utf-8')        def transform_output(self, output: bytes) -> str:        response_json = json.loads(output.read().decode("utf-8"))        return response_json['generated_texts'][0]content_handler = ContentHandler()#prompt template for input textllm_prompt = PromptTemplate(input_variables=["input_text"], template="{input_text}")llm_chain = LLMChain(    llm=SagemakerEndpoint(        endpoint_name=endpoint_name,         region_name='us-east-1',        model_kwargs={"temperature":0.97,                      "max_length": 200,                      "num_return_sequences": 3,                      "top_k": 50,                      "top_p": 0.95,                      "do_sample": True},        content_handler=content_handler    ),    prompt=llm_prompt)Create a configuration and initialize an Amazon Comprehend Moderation chainmoderation_config = {         "filters":[ BaseModerationFilters.PII, BaseModerationFilters.TOXICITY ],        "pii":{"action": BaseModerationActions.ALLOW, "threshold":0.5, "labels":["SSN"], "mask_character": "X"},        "toxicity":{"action": BaseModerationActions.STOP, "threshold":0.5},        "intent":{"action": BaseModerationActions.ALLOW, "threshold":0.5,},   }amazon_comp_moderation =
This notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity.
This notebook shows how to use Amazon Comprehend to detect and handle Personally Identifiable Information (PII) and toxicity. ->: chain with an Amazon SageMaker Jumpstart hosted LLM. You should have an Amazon SageMaker Jumpstart hosted LLM endpoint within your AWS Account. endpoint_name = "<SAGEMAKER_ENDPOINT_NAME>" # replace with your SageMaker Endpoint namefrom langchain.llms import SagemakerEndpointfrom langchain.llms.sagemaker_endpoint import LLMContentHandlerfrom langchain.chains import LLMChainfrom langchain.prompts import load_prompt, PromptTemplateimport jsonclass ContentHandler(LLMContentHandler):    content_type = "application/json"    accepts = "application/json"    def transform_input(self, prompt: str, model_kwargs: dict) -> bytes:        input_str = json.dumps({"text_inputs": prompt,  **model_kwargs})        return input_str.encode('utf-8')        def transform_output(self, output: bytes) -> str:        response_json = json.loads(output.read().decode("utf-8"))        return response_json['generated_texts'][0]content_handler = ContentHandler()#prompt template for input textllm_prompt = PromptTemplate(input_variables=["input_text"], template="{input_text}")llm_chain = LLMChain(    llm=SagemakerEndpoint(        endpoint_name=endpoint_name,         region_name='us-east-1',        model_kwargs={"temperature":0.97,                      "max_length": 200,                      "num_return_sequences": 3,                      "top_k": 50,                      "top_p": 0.95,                      "do_sample": True},        content_handler=content_handler    ),    prompt=llm_prompt)Create a configuration and initialize an Amazon Comprehend Moderation chainmoderation_config = {         "filters":[ BaseModerationFilters.PII, BaseModerationFilters.TOXICITY ],        "pii":{"action": BaseModerationActions.ALLOW, "threshold":0.5, "labels":["SSN"], "mask_character": "X"},        "toxicity":{"action": BaseModerationActions.STOP, "threshold":0.5},        "intent":{"action": BaseModerationActions.ALLOW, "threshold":0.5,},   }amazon_comp_moderation =