a
    bg`
                     @  sz   d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ eeZG dd de	ZG d	d
 d
eZdS )    )annotationsN)OptionalType)CallbackManagerForToolRun)	BaseModelField)
EdenaiToolc                   @  s    e Zd ZU eddZded< dS )TextModerationInputzText to moderate)descriptionstrqueryN)__name__
__module____qualname__r   r   __annotations__ r   r   ~/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/tools/edenai/text_moderation.pyr	      s   
r	   c                   @  sz   e Zd ZU dZdZded< dZded< eZded< ded	< d
Z	ded< dZ
ded< dddddZdddddddZdS )EdenAiTextModerationToolai  Tool that queries the Eden AI Explicit text detection.

    for api reference check edenai documentation:
    https://docs.edenai.co/reference/image_explicit_content_create.

    To use, you should have
    the environment variable ``EDENAI_API_KEY`` set with your API token.
    You can find your token here: https://app.edenai.run/admin/account/settings

    Z&edenai_explicit_content_detection_textr   namea  A wrapper around edenai Services explicit content detection for text. Useful for when you have to scan text for offensive, 
        sexually explicit or suggestive content,
        it checks also if there is any content of self-harm,
        violence, racist or hate speech.the structure of the output is : 
        'the type of the explicit content : the likelihood of it being explicit'
        the likelihood is a number 
        between 1 and 5, 1 being the lowest and 5 the highest.
        something is explicit if the likelihood is equal or higher than 3.
        for example : 
        nsfw_likelihood: 1
        this is not explicit.
        for example : 
        nsfw_likelihood: 3
        this is explicit.
        Input should be a string.r
   zType[BaseModel]args_schemalanguagetextfeatureZ
moderation
subfeaturelist)responsereturnc              	   C  sp   g }|D ]\}d|  v r.|dt|d   t|d |d D ]"\}}|d| dt|  q@qd|S )NZnsfw_likelihoodznsfw_likelihood: label
likelihood"z": 
)keysappendr   zipjoin)selfr   Zformatted_resultresultr   r   r   r   r   _parse_response:   s    z(EdenAiTextModerationTool._parse_responseNz#Optional[CallbackManagerForToolRun])r   run_managerr   c                 C  s   || j d}| |S )zUse the tool.)r   r   )r   Z_call_eden_ai)r%   r   r(   Zquery_paramsr   r   r   _runG   s    zEdenAiTextModerationTool._run)N)r   r   r   __doc__r   r   r
   r	   r   r   r   r'   r)   r   r   r   r   r      s   

 r   )
__future__r   loggingtypingr   r   Zlangchain_core.callbacksr   Zpydanticr   r   Z1langchain_community.tools.edenai.edenai_base_toolr   	getLoggerr   loggerr	   r   r   r   r   r   <module>   s   
