
    dh                     Z    S r SSKJrJr  SSKrSSKJrJr  SSKJ	r	J
r
Jr   " S S\	5      rg)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                       \ rS rSr% Sr\" S\" S5      S9r\\	S'   Sr
\\	S'   S	\S
\4S jr\" SS9\S\S
\4S j5       5       rS	\S
\4S jrSrg)SceneXplainAPIWrapper   a(  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                    SU R                    3SS.nSUSS/S./0n[        R                  " U R                  X#S9nUR	                  5         UR                  5       R                  S	/ 5      nU(       a  US
   O0 nUR                  SS5      $ )Nztoken zapplication/json)z	x-api-keyzcontent-typedataJellyen)r   	algorithm	languages)headersjsonresultr   text )r   requestspostr   raise_for_statusr   get)selfr   r   payloadresponser   imgs          a/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/scenexplain.py_describe_image%SceneXplainAPIWrapper._describe_image   s    !$"5"5!67.

 "!("&
 ==!4!4gT!!#$$Xr2!fQirwwvr""    before)modevaluesc                 (    [        USS5      nX!S'   U$ )z,Validate that api key exists in environment.r   r   )r   )clsr,   r   s      r&   validate_environment*SceneXplainAPIWrapper.validate_environment2   s'     .$&6
 $2 r)   c                 8    U R                  U5      nU(       d  gU$ )z Run SceneXplain image explainer.zNo description found.)r'   )r"   r   descriptions      r&   runSceneXplainAPIWrapper.run=   s    **51*r)    N)__name__
__module____qualname____firstlineno____doc__r   r   r   str__annotations__r   r'   r	   classmethodr   r   r/   r3   __static_attributes__r5   r)   r&   r   r      s      X>N5OPNCPBNCB#S #S #* (#$ 3   $  r)   r   )r:   typingr   r   r   langchain_core.utilsr   r   pydanticr   r   r	   r   r5   r)   r&   <module>rB      s'      ? 6 63I 3r)   