
    Ng                     d    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dS )	z$Wrapper around Moonshot chat models.    )Dict)convert_to_secret_strget_from_dict_or_envpre_init)
ChatOpenAI)MOONSHOT_SERVICE_URL_BASEMoonshotCommonc                   2    e Zd ZdZededefd            ZdS )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}n# t          $ r t          d          w xY w|d                                         d|v r|d         nt
          d}|                    d	          s |j        di |j        j	        |d	<   |                    d
          s |j
        di |j        j	        |d
<   |S )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       d/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/chat_models/moonshot.pyvalidate_environmentz!MoonshotChat.validate_environment    s7    &; AAA" &
 &
!"	MMMM 	 	 	?  	 01BBDDV## z***	
 
 zz(## 	O,v}==}==BNF8zz.)) 	%7V%7 & && &; >" s	   * AN)__name__
__module____qualname____doc__r   r   r"   r       r!   r   r      sL           !$ !4 ! ! ! X! ! !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 6 6 6 6 6 W W W W W W W W3 3 3 3 3>: 3 3 3 3 3r'   