o
    ȳg                     @   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                   @   sz   e Zd ZU dZededdZeed< dZ	eed< ded	efd
dZ
eddeded	efddZded	ef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dataEmberen)r   	algorithm	languages)headersjsonresultr   text )r   requestspostr   raise_for_statusr   get)selfr   r   payloadresponser   img r"   e/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/utilities/scenexplain.py_describe_image   s   
	z%SceneXplainAPIWrapper._describe_imagebefore)modevaluesc                 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   langchain_core.utilsr   r   pydanticr   r   r   r	   r"   r"   r"   r#   <module>   s    