U
    ™ÀÂhñ  ã                   @   sV   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„ 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                   @   s$   e Zd ZdZeeedœd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                 C   s¦   t t|dddgdƒƒ|d< zddl}W n tk
rB   tdƒ‚Y nX |d  ¡ d|kr^|d ntd	œ}| d
¡s„|jf |Žjj	|d
< | d¡s¢|j
f |Žjj	|d< |S )z2Validate that the environment is set up correctly.Zmoonshot_api_keyÚapi_keyZopenai_api_keyZMOONSHOT_API_KEYr   NzTCould not import openai python package. Please install it with `pip install openai`.Úbase_url)r   r   ÚclientZasync_client)r   r   ÚopenaiÚImportErrorZget_secret_valuer   ÚgetZOpenAIZchatZcompletionsZAsyncOpenAI)Úclsr
   r   Zclient_params© r   úL/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/chat_models/moonshot.pyÚvalidate_environment    s2    ýÿÿ

ÿ
ü

ÿz!MoonshotChat.validate_environmentN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	      s   r	   N)r   Útypingr   Zlangchain_core.utilsr   r   r   Zlangchain_community.chat_modelsr   Z!langchain_community.llms.moonshotr   r   r	   r   r   r   r   Ú<module>   s
   