
    7|h                         d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
Z
ddlmZ ddlmZ ddlmZmZmZmZ ddlmZmZ dd	lmZ dd
lmZ dee   ddfdZ	 ddee   de	ee      defdZ G d de      Zy)z<ChatModel wrapper which returns user input as the response..    )StringIO)AnyCallableDictListMappingOptionalN)CallbackManagerForLLMRun)BaseChatModel)BaseMessageHumanMessage_message_from_dictmessages_to_dict)ChatGeneration
ChatResult)Field)enforce_stop_tokensmessagesreturnc           	          t        |       }|D ]A  }t        j                  |ddddd       }t        ddd       t        |       t        dd       C y )	NFTi'  )default_flow_style	sort_keysallow_unicodewidth
line_break
z ======= start of message =======z

z======= end of message =======)r   yamldumpprint)r   dict_messagesmessageyaml_strings       d/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/chat_models/human.py_display_messagesr$      s]    $X.M  8ii$
 	d6?k.78    stopc                    g }	 t               j                         sn)|rt        fd|D              rn|j                         Ddj	                  |      }	 t        t        j                  t        |                  }|t        d      S |rBt        |j                  t              rt        |j                  |      |_        |S t        d      |S # t        j                  $ r t        d      t        $ r t        d      w xY w)z3Collects and returns user input as a single string.c              3   &   K   | ]  }|v  
 y wN ).0seqlines     r#   	<genexpr>z&_collect_yaml_input.<locals>.<genexpr>0   s     4t4s   r    )contentz'Cannot use when output is not a string.zInvalid YAML string entered.zInvalid message entered.)inputstripanyappendjoinr   r   	safe_loadr   r   
isinstancer0   strr   
ValueError	YAMLError)r   r&   linesr"   r!   r-   s        @r#   _collect_yaml_inputr<   '   s     E
wzz|C4t44T  ))E"K5$T^^H[4I%JK?++'//3/"5goot"L  !!JKK>> 9788 53445s   4C 8C 	C 2Dc                       e Zd ZU dZ ed       Zeed<    ed       Zeed<   dZ	e
ed<   i Zee
ef   ed	<   i Zee
ef   ed
<   edee
ef   fd       Zede
fd       Z	 	 ddee   deee
      dee   dedef
dZy)HumanInputChatModelz3ChatModel which returns user input as the response.c                      t         S r)   )r<   r*   r%   r#   <lambda>zHumanInputChatModel.<lambda>I   s    9L r%   )default_factory
input_funcc                      t         S r)   )r$   r*   r%   r#   r@   zHumanInputChatModel.<lambda>J   s    ;L r%   message_funcr   	separatorinput_kwargsmessage_kwargsr   c                 \    | j                   j                  | j                  j                  dS )N)rB   rD   )rB   __name__rD   selfs    r#   _identifying_paramsz'HumanInputChatModel._identifying_paramsO   s*     //22 --66
 	
r%   c                      y)zReturns the type of LLM.zhuman-input-chat-modelr*   rJ   s    r#   	_llm_typezHumanInputChatModel._llm_typeV   s     (r%   Nr   r&   run_managerkwargsc                      | j                   |fi | j                    | j                  |fd|i| j                  }t	        t        |      g      S )a  
        Displays the messages to the user and returns their input as a response.

        Args:
            messages (List[BaseMessage]): The messages to be displayed to the user.
            stop (Optional[List[str]]): A list of stop strings.
            run_manager (Optional[CallbackManagerForLLMRun]): Currently not used.

        Returns:
            ChatResult: The user's input as a response.
        r&   )r!   )generations)rD   rG   rB   rF   r   r   )rK   r   r&   rO   rP   
user_inputs         r#   	_generatezHumanInputChatModel._generate[   sR    $ 	(:d&9&9:$T__XNDND<M<MN
~j'I&JKKr%   )NN)rI   
__module____qualname____doc__r   rB   r   __annotations__rD   rE   r8   rF   r   r   rG   propertyr   rL   rN   r   r   r	   r
   r   rT   r*   r%   r#   r>   r>   F   s    = 1LMJM"3LML(MIs&(L'#s(#((*NGCH%*
T#s(^ 
 
 (3 ( ( %):>	L{#L tCy!L 67	L
 L 
Lr%   r>   r)   )rW   ior   typingr   r   r   r   r   r	   r   langchain_core.callbacksr
   *langchain_core.language_models.chat_modelsr   langchain_core.messagesr   r   r   r   langchain_core.outputsr   r   pydanticr   langchain_community.llms.utilsr   r$   r8   r<   r>   r*   r%   r#   <module>rb      s    B  ? ?  E  >  >8[ 1 8d 8" >B5;5'/S	':55>)L- )Lr%   