
    gh              
          d Z ddl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mZ ddlmZ  G d	 d
eeef                   Zdeded         dee         fdZdeeef         deeef         ded         deeef         fdZdS )zDict prompt template.    N)cached_property)AnyLiteralOptionaldumpd)DEFAULT_FORMATTER_MAPPINGget_template_variables)RunnableConfigRunnableSerializable)ensure_configc            	       v   e Zd ZU dZeeef         ed<   ed         ed<   e	de
e         fd            Zdedeeef         fdZdedeeef         fd	Z	 ddedee         dedefdZe	defd            Zedeeef         fd            Zedefd            Zede
e         fd            ZdddedefdZd
S )DictPromptTemplatezTemplate represented by a dict.

    Recognizes variables in f-string or mustache formatted string dict values. Does NOT
    recognize variables in dict keys. Applies recursively.
    templatezf-stringmustachetemplate_formatreturnc                 6    t          | j        | j                  S )zTemplate input variables.)_get_input_variablesr   r   selfs    X/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/langchain_core/prompts/dict.pyinput_variablesz"DictPromptTemplate.input_variables   s     $DM43GHHH    kwargsc                 8    t          | j        || j                  S )"Format the prompt with the inputs.)_insert_input_variablesr   r   r   r   s     r   formatzDictPromptTemplate.format   s    &t}fd>RSSSr   c                     K    | j         di |S )r    r!   r    s     r   aformatzDictPromptTemplate.aformat#   s      t{$$V$$$r   Ninputconfigc                 T       j          fd|t          |          fd j        d|S )zInvoke the prompt.c                      j         di | S )Nr#   r$   )xr   s    r   <lambda>z+DictPromptTemplate.invoke.<locals>.<lambda>,   s    kdk&&A&& r   prompt)run_type
serialized)_call_with_configr   _serialized)r   r&   r'   r   s   `   r   invokezDictPromptTemplate.invoke'   sU     &t%&&&&&!!
 '
 
 
 
 	
r   c                     dS )Nzdict-promptr#   r   s    r   _prompt_typezDictPromptTemplate._prompt_type4   s    }r   c                      t          |           S Nr   r   s    r   r0   zDictPromptTemplate._serialized8   s    T{{r   c                     dS )zQReturn whether or not the class is serializable.

        Returns: True.
        Tr#   clss    r   is_lc_serializablez%DictPromptTemplate.is_lc_serializable<   s	     tr   c                 
    g dS )zSerialization namespace.)langchain_corepromptsdictr#   r7   s    r   get_lc_namespacez#DictPromptTemplate.get_lc_namespaceD   s     5444r   F)htmlr?   c                    t           )zHuman-readable representation.

        Args:
            html: Whether to format as HTML. Defaults to False.

        Returns:
            Human-readable representation.
        )NotImplementedError)r   r?   s     r   pretty_reprzDictPromptTemplate.pretty_reprI   s
     "!r   r5   )__name__
__module____qualname____doc__r=   strr   __annotations__r   propertylistr   r!   r%   r   r   r1   r3   r   r0   classmethodboolr9   r>   rB   r#   r   r   r   r      s          38n34444Ic I I I XITs TtCH~ T T T T%c %d38n % % % %
 ?C
 

#+N#;
NQ
	
 
 
 
 c    X T#s(^    _ 4    [ 5c 5 5 5 [5 +0 	" 	" 	"4 	"C 	" 	" 	" 	" 	" 	"r   r   r   r   r   r   c                    g }|                                  D ]}t          |t                    r|t          ||          z  }+t          |t                    r|t          ||          z  }Tt          |t          t          f          rW|D ]S}t          |t                    r|t          ||          z  }+t          |t                    r|t          ||          z  }Tǌt          t          |                    S r5   )	values
isinstancerG   r
   r=   r   rJ   tupleset)r   r   r   vr*   s        r   r   r   U   s    O__  a 	5aIIIOO4   		3AGGGOOD%=)) 	 P Pa%% P#'=a'Q'QQOO4(( P#';A'O'OOO	P O$$%%%r   inputsc           	         i }t           |         }|                                 D ]$\  }}t          |t                    r ||fi |||<   (t          |t                    r7|dk    rd|v rd}t          j        |d           t          |||          ||<   tt          |t          t          f          rg }|D ]m}	t          |	t                    r|
                     ||	fi |           4t          |	t                    r$|
                    t          |	||                     n t          |          |          ||<   |||<   &|S )N	image_urlpathzSpecifying image inputs via file path in environments with user-input paths is a security vulnerability. Out of an abundance of caution, the utility has been removed to prevent possible misuse.   )
stacklevel)r	   itemsrO   rG   r=   warningswarnr   rJ   rP   appendtype)
r   rS   r   	formatted	formatterkrR   msgformatted_vr*   s
             r   r   r   i   s   
 I)/:I    1a 	$9Q11&11IaLL4   	KFaKK  ca000021foNNIaLLD%=)) 	K  a%% &&yy'='=f'='=>>>>4(( &&/6?KK   #477;//IaLLIaLLr   )rF   rZ   	functoolsr   typingr   r   r   langchain_core.loadr   langchain_core.prompts.stringr	   r
   langchain_core.runnablesr   r   langchain_core.runnables.configr   r=   r   rJ   rG   r   r   r#   r   r   <module>ri      s~      % % % % % % ) ) ) ) ) ) ) ) ) ) % % % % % %        J I I I I I I I 9 9 9 9 9 9B" B" B" B" B"-dDj9 B" B" B"J&&%,-C%D&	#Y& & & &( 38n cN  34  
#s(^	           r   