
    7|h                     Z    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e	      Zy)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                       e Zd ZU dZ ed ed            Zeed<   dZ	eed<   ded	efd
Z
 ed      eded	efd              Zded	efdZy)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                    d| j                    dd}d|ddgdgi}t        j                  | j                  ||      }|j	                          |j                         j                  d	g       }|r|d
   ni }|j                  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   imgs          h/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/utilities/scenexplain.py_describe_imagez%SceneXplainAPIWrapper._describe_image   s    !$"5"5!67.

 "!("&
 ==!4!4gGT!!#$$Xr2!fQirwwvr""    before)modevaluesc                 *    t        |dd      }||d<   |S )z,Validate that api key exists in environment.r   r   )r   )clsr*   r   s      r%   validate_environmentz*SceneXplainAPIWrapper.validate_environment2   s)     .$&6
 $2 r'   c                 .    | j                  |      }|sy|S )z Run SceneXplain image explainer.zNo description found.)r&   )r!   r   descriptions      r%   runzSceneXplainAPIWrapper.run=   s    **51*r'   N)__name__
__module____qualname____doc__r   r   r   str__annotations__r   r&   r	   classmethodr   r   r-   r0    r'   r%   r   r      s      X>N5OPNCPBNCB#S #S #* (#$ 3   $  r'   r   )r4   typingr   r   r   langchain_core.utilsr   r   pydanticr   r   r	   r   r8   r'   r%   <module>r<      s'      ? 6 63I 3r'   