a
    ”˜ëjB  ã                   @   s„   d Z ddlmZ ddlmZ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mZ ddlmZ G d	d
„ d
ee
 ƒZdS )ú-Image prompt template for a multimodal model.é    )ÚAny)ÚFieldÚmodel_validator)ÚSelf)ÚImagePromptValueÚImageURLÚPromptValue)ÚBasePromptTemplate)ÚDEFAULT_FORMATTER_MAPPINGÚPromptTemplateFormatÚget_template_variables)Úrun_in_executorc                       sÚ   e Zd ZU dZeed�Zeed< dZe	ed< e
ddœ‡ fdd	„Zed
d�edœdd„ƒZeedœdd„ƒZeee dœdd„ƒZe
edœdd„Ze
edœdd„Ze
edœdd„Ze
edœdd„Zdeedœdd„Z‡  ZS ) ÚImagePromptTemplater   )Údefault_factoryÚtemplatezf-stringÚtemplate_formatN)ÚkwargsÚreturnc                    sP   d|vrg |d< t |d ƒh d£@ }|r:d|› �}t|ƒ‚tƒ jf i |¤Ž dS )z©Create an image prompt template.

        Raises:
            ValueError: If the input variables contain ``'url'``, ``'path'``, or
                ``'detail'``.
        Zinput_variables>   ÚpathÚurlÚ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__© ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain_core/prompts/image.pyr      s    þÿzImagePromptTemplate.__init__Úafter)Úmode)r   c                 C   s*   | j  ¡ D ]}t|tƒr
t|| jƒ q
| S )z7Validate template string values after Pydantic parsing.)r   ÚvaluesÚ
isinstanceÚstrr   r   )r   Úvaluer!   r!   r"   Úvalidate_template0   s    
z%ImagePromptTemplate.validate_templatec                 C   s   dS )zReturn the prompt type key.zimage-promptr!   )r   r!   r!   r"   Ú_prompt_type8   s    z ImagePromptTemplate._prompt_typec                 C   s   g d¢S )zwGet the namespace of the langchain object.

        Returns:
            ``["langchain", "prompts", "image"]``
        )Z	langchainZpromptsÚimager!   )Úclsr!   r!   r"   Úget_lc_namespace=   s    z$ImagePromptTemplate.get_lc_namespacec                 K   s   t | jf i |¤Žd�S )z³Format the prompt with the inputs.

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

        Returns:
            A formatted string.
        ©Z	image_url)r   Úformat©r   r   r!   r!   r"   Úformat_promptF   s    	z!ImagePromptTemplate.format_promptc                 Ë   s   t | jf i |¤ŽI dH d�S )ú¹Async format the prompt with the inputs.

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

        Returns:
            A formatted string.
        Nr.   )r   Úaformatr0   r!   r!   r"   Úaformat_promptQ   s    	z"ImagePromptTemplate.aformat_promptc           	      K   sÌ   i }| j  ¡ D ]6\}}t|tƒr<t| j |fi |¤Ž||< q|||< q| d¡pX| d¡}| d¡sn| d¡rzd}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.
            ValueError: If ``'path'`` is provided in the template or kwargs.

        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   Úitemsr&   r'   r   r   Úgetr   )	r   r   Ú	formattedÚkÚvr   r   r   Úoutputr!   r!   r"   r/   \   s2    
ÿÿ
ÿ
zImagePromptTemplate.formatc                 Ë   s   t d| jfi |¤ŽI dH S )r2   N)r   r/   r0   r!   r!   r"   r3   �   s    	zImagePromptTemplate.aformatF)Úhtmlr   c                 C   s   t ‚dS )zÈReturn a pretty representation of the prompt.

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

        Returns:
            A pretty representation of the prompt.
        N)ÚNotImplementedError)r   r;   r!   r!   r"   Úpretty_repr›   s    zImagePromptTemplate.pretty_repr)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Údictr   Ú__annotations__r   r   r   r   r   r   r)   Úpropertyr'   r*   ÚclassmethodÚlistr-   r	   r1   r4   r   r/   r3   Úboolr=   Ú__classcell__r!   r!   r   r"   r      s*   
ý4 þýr   N)rA   Útypingr   Zpydanticr   r   Ztyping_extensionsr   Zlangchain_core.prompt_valuesr   r   r	   Zlangchain_core.prompts.baser
   Zlangchain_core.prompts.stringr   r   r   Zlangchain_core.runnablesr   r   r!   r!   r!   r"   Ú<module>   s   