Source code for langchain_experimental.comprehend_moderation.intent
import asyncio
from typing import Any, Optional
from langchain_experimental.comprehend_moderation.base_moderation_exceptions import (
    ModerationIntentionError,
)
[docs]class ComprehendIntent:
[docs]    def __init__(
        self,
        client: Any,
        callback: Optional[Any] = None,
        unique_id: Optional[str] = None,
        chain_id: Optional[str] = None,
    ) -> None:
        self.client = client
        self.moderation_beacon = {
            "moderation_chain_id": chain_id,
            "moderation_type": "Intent",
            "moderation_status": "LABELS_NOT_FOUND",
        }
        self.callback = callback
        self.unique_id = unique_id
    def _get_arn(self) -> str:
        region_name = self.client.meta.region_name
        service = "comprehend"
        intent_endpoint = "document-classifier-endpoint/prompt-intent"
        return f"arn:aws:{service}:{region_name}:aws:{intent_endpoint}"
[docs]    def validate(self, prompt_value: str, config: Any = None) -> str:
        """
        Check and validate the intent of the given prompt text.
        Args:
            prompt_value (str): The input text to be checked for unintended intent.
            config (Dict[str, Any]): Configuration settings for intent checks.
        Raises:
            ValueError: If unintended intent is found in the prompt text based
            on the specified threshold.
        Returns:
            str: The input prompt_value.
        Note:
            This function checks the intent of the provided prompt text using
            Comprehend's classify_document API and raises an error if unintended