a
    bg                     @   sT   d Z ddlmZmZ ddlZddlmZmZ ddlm	Z	m
Z
mZ G dd de	ZdS )a&  Util that calls SceneXplain.

In order to set this up, you need API key for the SceneXplain API.
You can obtain a key by following the steps below.
- Sign up for a free account at https://scenex.jina.ai/.
- Navigate to the API Access page (https://scenex.jina.ai/api) and create a new API key.
    )AnyDictN)from_envget_from_dict_or_env)	BaseModelFieldmodel_validatorc                   @   st   e Zd ZU dZededdZeed< dZ	eed< eedd	d
Z
eddeeedddZeedddZdS )SceneXplainAPIWrappera@  Wrapper for SceneXplain API.

    In order to set this up, you need API key for the SceneXplain API.
    You can obtain a key by following the steps below.
    - Sign up for a free account at https://scenex.jina.ai/.
    - Navigate to the API Access page (https://scenex.jina.ai/api)
      and create a new API key.
    .SCENEX_API_KEY)default_factoryscenex_api_keyz&https://api.scenex.jina.ai/v1/describescenex_api_url)imagereturnc                 C   sl   d| j  dd}d|ddgdgi}tj| j||d}|  | d	g }|r\|d
 ni }|ddS )Nztoken zapplication/json)z	x-api-keyzcontent-typedataZEmberen)r   	algorithm	languages)headersjsonresultr   text )r   requestspostr   raise_for_statusr   get)selfr   r   payloadresponser   Zimg r    w/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/utilities/scenexplain.py_describe_image   s    
	z%SceneXplainAPIWrapper._describe_imagebefore)mode)valuesr   c                 C   s   t |dd}||d< |S )z,Validate that api key exists in environment.r   r
   )r   )clsr%   r   r    r    r!   validate_environment2   s
    z*SceneXplainAPIWrapper.validate_environmentc                 C   s   |  |}|sdS |S )z Run SceneXplain image explainer.zNo description found.)r"   )r   r   descriptionr    r    r!   run=   s    
zSceneXplainAPIWrapper.runN)__name__
__module____qualname____doc__r   r   r   str__annotations__r   r"   r   classmethodr   r   r'   r)   r    r    r    r!   r	      s   
		r	   )r-   typingr   r   r   Zlangchain_core.utilsr   r   Zpydanticr   r   r   r	   r    r    r    r!   <module>   s
   