
    dh                         S SK JrJrJrJrJr  S SKJr  S SKJ	r	J
r
  S SKJr  S SKJrJr  S SKJrJr  S SKJrJr  S SKJrJrJrJr  S S	KJr  S
\\   S\\\\\\\\\\\4   4      4   4      4S jr " S S\5      rg)    )AnyDictListOptionalUnion)ClientSession)AsyncCallbackManagerForLLMRunCallbackManagerForLLMRun)BaseChatModel)	AIMessageBaseMessage)ChatGeneration
ChatResultconvert_to_secret_strget_from_dict_or_env)
ConfigDictField	SecretStrmodel_validator)Requestsmessagesreturnc                     / nU  Hc  nUR                   S:X  a   UR                  SUR                  S.5        M3  UR                   S:X  d  ME  UR                  SUR                  S.5        Me     U$ )Nhumanuser)rolecontentsystem)typeappendr   )r   formatted_messagesmessages      _/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/chat_models/dappier.py_format_dappier_messagesr%      sb     <<7"%%v'//&RS\\X%%%xGOO&TU	      c                   R   \ rS rSr% SrSr\\S'   Sr\\S'   \	" SSS	9r
\\   \S
'   \" SS9r\" SS9\S\S\4S j5       5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r  SS\\   S\\\      S\\   S\S\4
S jjr  SS\\   S\\\      S\\   S\S\4
S jjrSr g)ChatDappierAI$   aY  `Dappier` chat large language models.

`Dappier` is a platform enabling access to diverse, real-time data models.
Enhance your AI applications with Dappier's pre-trained, LLM-ready data models
and ensure accurate, current responses with reduced inaccuracies.

To use one of our Dappier AI Data Models, you will need an API key.
Please visit Dappier Platform (https://platform.dappier.com/) to log in
and create an API key in your profile.

Example:
    .. code-block:: python

        from langchain_community.chat_models import ChatDappierAI
        from langchain_core.messages import HumanMessage

        # Initialize `ChatDappierAI` with the desired configuration
        chat = ChatDappierAI(
            dappier_endpoint="https://api.dappier.com/app/datamodel/dm_01hpsxyfm2fwdt2zet9cg6fdxt",
            dappier_api_key="<YOUR_KEY>")

        # Create a list of messages to interact with the model
        messages = [HumanMessage(content="hello")]

        # Invoke the model with the provided messages
        chat.invoke(messages)


you can find more details here : https://docs.dappier.com/introductionz1https://api.dappier.com/app/datamodelconversationdappier_endpointdm_01hpsxyfm2fwdt2zet9cg6fdxtdappier_modelNzDappier API Token)descriptiondappier_api_keyforbid)extrabefore)modevaluesr   c                 8    [        [        USS5      5      US'   U$ )z,Validate that api key exists in environment.r.   DAPPIER_API_KEYr   )clsr3   s     r$   validate_environment"ChatDappierAI.validate_environmentM   s)     %: ):<MN%
 ! r&   c                      SSK Jn   SU  3$ )Nr   __version__z
langchain/)langchain_communityr;   r:   s    r$   get_user_agentChatDappierAI.get_user_agentV   s    3K=))r&   c                     g)zReturn type of chat model.zdappier-realtimesearch-chat selfs    r$   	_llm_typeChatDappierAI._llm_type\   s     -r&   c                 Z    U R                   (       a  U R                   R                  5       $ g)N )r.   get_secret_valuerA   s    r$   _api_keyChatDappierAI._api_keya   s#    ''88::r&   r   stoprun_managerkwargsc                 6   U R                    nSU R                   3U R                  5       S.n[        US9nU R                  US.n[        US9n	U	R                  XXS9n
U
R                  5         U
R                  5       nUS   n[        [        [        US9S	9/S
9$ )NBearer Authorizationz
User-Agentr   modelconversation)headers)urldatar#   r   r#   generations)r*   rH   r=   r%   r,   r   postraise_for_statusjsonr   r   r   )rB   r   rJ   rK   rL   rV   rU   
user_querypayloadrequestresponserW   message_responses                r$   	_generateChatDappierAI._generateg   s     &&'&t}}o6--/
 .x@
''&#

 7+<<C<6!!#}}	?'	BR0STU
 	
r&   c           
      Z  #    U R                    nSU R                   3U R                  5       S.n[        US9nU R                  US.n[        5        IS h  vN n	U	R                  XXUS9 IS h  vN n
U
R                  5         U
R                  5       I S h  vN nUS   n[        [        [        US9S9/S	9sS S S 5      IS h  vN   sS S S 5      IS h  vN   $  N Nm NG N N! , IS h  vN  (       d  f       O= fS S S 5      IS h  vN    g ! , IS h  vN  (       d  f       g = f7f)
NrN   rO   rQ   rR   )r^   rU   r#   rX   rY   rZ   )r*   rH   r=   r%   r,   r   r\   r]   r^   r   r   r   )rB   r   rJ   rK   rL   rV   rU   r_   r`   sessionrb   rW   rc   s                r$   
_agenerateChatDappierAI._agenerate   s      &&'&t}}o6--/
 .x@
''&#

 !??g||Cw|GG8))+%]]_,#'	? !&yAQ/RS! HGG #??G, H #GGG #?????s   AD+CD+D/C0D3$C%C C%8DC!D	D+C#D+DC%!D#D+%C<	+C.,C<	8D?D+
DD+D(DD($D+r@   )NN)!__name__
__module____qualname____firstlineno____doc__r*   str__annotations__r,   r   r.   r   r   r   model_configr   classmethodr   r   r7   staticmethodr=   propertyrC   rH   r   r   r
   r   rd   r	   rh   __static_attributes__r@   r&   r$   r(   r(   $   sl   N< PcO8M38+0CV+WOXi(WL (#$ 3   $ *C * *
 -3 - - #   %):>	
{#
 tCy!
 67	

 
 

B %)?C	{# tCy! ;<	
  
 r&   r(   N) typingr   r   r   r   r   aiohttpr   langchain_core.callbacksr	   r
   *langchain_core.language_models.chat_modelsr   langchain_core.messagesr   r   langchain_core.outputsr   r   langchain_core.utilsr   r   pydanticr   r   r   r   &langchain_community.utilities.requestsr   ro   r%   r(   r@   r&   r$   <module>r      s    3 3 ! > L B B ;;	$sE#tE#tCH~*=$>??@@
AB}M }r&   