
    Ig                     \    d 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  G d dee      Zy)	z$Wrapper around Moonshot chat models.    )Dict)convert_to_secret_strget_from_dict_or_envpre_init)
ChatOpenAI)MOONSHOT_SERVICE_URL_BASEMoonshotCommonc                   *    e Zd ZdZededefd       Zy)MoonshotChata  Moonshot large language models.

    To use, you should have the ``openai`` python package installed, and the
    environment variable ``MOONSHOT_API_KEY`` set with your API key.
    (Moonshot's chat API is compatible with OpenAI's SDK.)

    Referenced from https://platform.moonshot.cn/docs

    Example:
        .. code-block:: python

            from langchain_community.chat_models.moonshot import MoonshotChat

            moonshot = MoonshotChat(model="moonshot-v1-8k")
    valuesreturnc                    t        t        |g dd            |d<   	 ddl}|d   j	                         d|v r|d   nt
        d}|j                  d	      s) |j                  di |j                  j                  |d	<   |j                  d
      s) |j                  di |j                  j                  |d
<   |S # t        $ r t        d      w xY w)z2Validate that the environment is set up correctly.)moonshot_api_keyapi_keyopenai_api_keyMOONSHOT_API_KEYr   r   NzTCould not import openai python package. Please install it with `pip install openai`.base_url)r   r   clientasync_client )r   r   openaiImportErrorget_secret_valuer   getOpenAIchatcompletionsAsyncOpenAI)clsr   r   client_paramss       e/var/www/html/answerous/venv/lib/python3.12/site-packages/langchain_community/chat_models/moonshot.pyvalidate_environmentz!MoonshotChat.validate_environment    s     &; A"&
!"	 01BBDV# z**	
 zz(#,v}}=}=BBNNF8zz.)%7V%7%7 &&d;; >" )  	? 	s   B: :CN)__name__
__module____qualname____doc__r   r   r"   r       r!   r   r      s)      !$ !4 ! !r'   r   N)r&   typingr   langchain_core.utilsr   r   r   langchain_community.chat_modelsr   !langchain_community.llms.moonshotr   r	   r   r   r'   r!   <module>r,      s+    *   7 W3>: 3r'   