
    gh                         d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ  G d d	e
e                   Zd
S )-Image prompt template for a multimodal model.    )Any)Field)ImagePromptValueImageURLPromptValue)BasePromptTemplate)DEFAULT_FORMATTER_MAPPINGPromptTemplateFormat)run_in_executorc                        e Zd ZU dZ ee          Zeed<   	 dZe	ed<   	 de
ddf fd	Zedefd
            Zedee         fd            Zde
defdZde
defdZde
defdZde
defdZ	 ddedefdZ xZS )ImagePromptTemplater   )default_factorytemplatezf-stringtemplate_formatkwargsreturnNc                     d|vrg |d<   t          |d                   h dz  }|rd| }t          |           t                      j        di | dS )z Create an image prompt template.input_variables>   urlpathdetailz`input_variables for the image template cannot contain any of 'url', 'path', or 'detail'. Found: N )set
ValueErrorsuper__init__)selfr   overlapmsg	__class__s       Y/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_core/prompts/image.pyr   zImagePromptTemplate.__init__   s    F**(*F$%f./003L3L3LL 	"%"% % 
 S//!""6"""""    c                     dS )zReturn the prompt type key.zimage-promptr   )r   s    r"   _prompt_typez ImagePromptTemplate._prompt_type(   s	     ~r#   c                 
    g dS )z*Get the namespace of the langchain object.)	langchainpromptsimager   )clss    r"   get_lc_namespacez$ImagePromptTemplate.get_lc_namespace-   s     1000r#   c                 8    t           | j        di |          S )zFormat the prompt with the inputs.

        Args:
            kwargs: Any arguments to be passed to the prompt template.

        Returns:
            A formatted string.
        	image_urlr   )r   formatr   r   s     r"   format_promptz!ImagePromptTemplate.format_prompt2   s'      +$+*?*?*?*?@@@@r#   c                 H   K   t           | j        di | d{V           S )zAsync format the prompt with the inputs.

        Args:
            kwargs: Any arguments to be passed to the prompt template.

        Returns:
            A formatted string.
        Nr-   r   )r   aformatr0   s     r"   aformat_promptz"ImagePromptTemplate.aformat_prompt=   s=        0F0Fv0F0F*F*F*F*F*F*FGGGGr#   c                 Z   i }| j                                         D ];\  }}t          |t                    rt	          | j                 |fi |||<   6|||<   <|                    d          p|                    d          }|                    d          s|                    d          rd}t          |          |                    d          p|                    d          }|sd}t          |          t          |t                    sd}t          |          d|i}|r||d<   |S )a  Format the prompt with the inputs.

        Args:
            kwargs: Any arguments to be passed to the prompt template.

        Returns:
            A formatted string.

        Raises:
            ValueError: If the url is not provided.
            ValueError: If the url is not a string.

        Example:

            .. code-block:: python

                prompt.format(variable1="foo")
        r   r   znLoading images from 'path' has been removed as of 0.3.15 for security reasons. Please specify images by 'url'.r   zMust provide url.zurl must be a string.)r   items
isinstancestrr
   r   getr   )	r   r   	formattedkvr   r    r   outputs	            r"   r/   zImagePromptTemplate.formatH   sU   , 	M'')) 	! 	!DAq!S!! !89MN      	!  !	!jj79==#7#7::f 	"v!6!6 	";  S//!H%%@x)@)@ 	"%CS//!#s## 	")CS//!!3< 	&%F8r#   c                 8   K   t          d| j        fi | d{V S )a  Async format the prompt with the inputs.

        Args:
            kwargs: Any arguments to be passed to the prompt template.

        Returns:
            A formatted string.

        Raises:
            ValueError: If the path or url is not a string.
        N)r   r/   r0   s     r"   r3   zImagePromptTemplate.aformatz   s4       %T4;AA&AAAAAAAAAr#   Fhtmlc                     t           )zReturn a pretty representation of the prompt.

        Args:
            html: Whether to return an html formatted string.

        Returns:
            A pretty representation of the prompt.
        )NotImplementedError)r   r?   s     r"   pretty_reprzImagePromptTemplate.pretty_repr   s
     "!r#   )F)__name__
__module____qualname____doc__r   dictr   __annotations__r   r   r   r   propertyr8   r%   classmethodlistr+   r   r1   r4   r   r/   r3   boolrB   __classcell__)r!   s   @r"   r   r      s        77U4000Hd000",6O)6666# # # # # # # # c    X 1c 1 1 1 [1	Ac 	Ak 	A 	A 	A 	A	HS 	H[ 	H 	H 	H 	H00 
0 0 0 0dBc Bh B B B B  " "" 
" " " " " " " "r#   r   N)rF   typingr   pydanticr   langchain_core.prompt_valuesr   r   r   langchain_core.prompts.baser	   langchain_core.prompts.stringr
   r   langchain_core.runnablesr   r   r   r#   r"   <module>rT      s    3 3             P P P P P P P P P P : : : : : :        5 4 4 4 4 4D" D" D" D" D",X6 D" D" D" D" D"r#   