a
    ”˜ëj  ã                   @  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
 ddlmZ ddlmZ ddlmZmZmZmZ G d	d
„ d
eeƒZG dd„ deƒZG dd„ deƒZG dd„ dedd�ZG dd„ deƒZG dd„ deƒZdS )z´**Prompt values** for language model prompts.

Prompt values are used to represent different pieces of prompts.
They can be used to represent text, images, or chat message pieces.
é    )Úannotations)ÚABCÚabstractmethod)ÚSequence)ÚLiteralÚcast)Ú	TypedDict)ÚSerializable)Ú
AnyMessageÚBaseMessageÚHumanMessageÚget_buffer_stringc                   @  sX   e Zd ZdZeddœdd„ƒZeddœdd„ƒZed	dœd
d„ƒZeddœdd„ƒZ	dS )ÚPromptValuez¡Base abstract class for inputs to any language model.

    PromptValues can be converted to both LLM (pure text-generation) inputs and
    ChatModel inputs.
    Úbool©Úreturnc                 C  s   dS )z*Return True as this class is serializable.T© ©Úclsr   r   ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain_core/prompt_values.pyÚis_lc_serializable   s    zPromptValue.is_lc_serializableú	list[str]c                 C  s   g d¢S )zÈGet the namespace of the langchain object.

        This is used to determine the namespace of the object when serializing.

        Returns:
            ``["langchain", "schema", "prompt"]``
        )Ú	langchainZschemaÚpromptr   r   r   r   r   Úget_lc_namespace$   s    	zPromptValue.get_lc_namespaceÚstrc                 C  s   dS )zReturn prompt value as string.Nr   ©Úselfr   r   r   Ú	to_string/   s    zPromptValue.to_stringúlist[BaseMessage]c                 C  s   dS )z$Return prompt as a list of Messages.Nr   r   r   r   r   Úto_messages3   s    zPromptValue.to_messagesN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr   r   r   r   r    r   r   r   r   r      s   
r   c                   @  sT   e Zd ZU dZded< d Zded< eddœdd	„ƒZddœd
d„Zddœdd„Z	dS )ÚStringPromptValuezString prompt value.r   ÚtextzLiteral['StringPromptValue']Útyper   r   c                 C  s   g d¢S )zÇGet the namespace of the langchain object.

        This is used to determine the namespace of the object when serializing.

        Returns:
            ``["langchain", "prompts", "base"]``
        )r   ÚpromptsÚbaser   r   r   r   r   r   ?   s    	z"StringPromptValue.get_lc_namespacec                 C  s   | j S ©zReturn prompt as string.)r'   r   r   r   r   r   J   s    zStringPromptValue.to_stringr   c                 C  s   t | jd�gS )zReturn prompt as messages.©Úcontent)r   r'   r   r   r   r   r    N   s    zStringPromptValue.to_messagesN)
r!   r"   r#   r$   Ú__annotations__r(   r%   r   r   r    r   r   r   r   r&   8   s   

r&   c                   @  sH   e Zd ZU dZded< ddœdd„Zddœd	d
„Zeddœdd„ƒZdS )ÚChatPromptValuezRChat prompt value.

    A type of a prompt value that is built from messages.
    zSequence[BaseMessage]Úmessagesr   r   c                 C  s
   t | jƒS r+   )r   r0   r   r   r   r   r   \   s    zChatPromptValue.to_stringr   c                 C  s
   t | jƒS )z$Return prompt as a list of messages.)Úlistr0   r   r   r   r   r    `   s    zChatPromptValue.to_messagesr   c                 C  s   g d¢S )zÇGet the namespace of the langchain object.

        This is used to determine the namespace of the object when serializing.

        Returns:
            ``["langchain", "prompts", "chat"]``
        )r   r)   Zchatr   r   r   r   r   r   d   s    	z ChatPromptValue.get_lc_namespaceN)	r!   r"   r#   r$   r.   r   r    r%   r   r   r   r   r   r/   S   s   
r/   c                   @  s"   e Zd ZU dZded< ded< dS )ÚImageURLz
Image URL.zLiteral['auto', 'low', 'high']Zdetailr   ÚurlN)r!   r"   r#   r$   r.   r   r   r   r   r2   p   s   
r2   F)Útotalc                   @  sB   e Zd ZU dZded< d Zded< ddœdd	„Zd
dœdd„ZdS )ÚImagePromptValuezImage prompt value.r2   Ú	image_urlzLiteral['ImagePromptValue']r(   r   r   c                 C  s
   | j d S )z$Return prompt (image URL) as string.r3   )r6   r   r   r   r   r   †   s    zImagePromptValue.to_stringr   c                 C  s   t td| jƒgd�gS )z&Return prompt (image URL) as messages.Údictr,   )r   r   r6   r   r   r   r   r    Š   s    zImagePromptValue.to_messagesN)r!   r"   r#   r$   r.   r(   r   r    r   r   r   r   r5      s
   
r5   c                   @  s&   e Zd ZU dZded< d Zded< dS )ÚChatPromptValueConcretezqChat prompt value which explicitly lists out the message types it accepts.

    For use in external schemas.
    zSequence[AnyMessage]r0   z"Literal['ChatPromptValueConcrete']r(   N)r!   r"   r#   r$   r.   r(   r   r   r   r   r8   �   s   
r8   N)r$   Ú
__future__r   Úabcr   r   Úcollections.abcr   Útypingr   r   Ztyping_extensionsr   Z langchain_core.load.serializabler	   Zlangchain_core.messagesr
   r   r   r   r   r&   r/   r2   r5   r8   r   r   r   r   Ú<module>   s    