import os# Generate your api key from: https://platform.moonshot.cn/console/api-keysos.environ["MOONSHOT_API_KEY"] = "MOONSHOT_API_KEY"
复制
向 AI 提问
from langchain_community.chat_models.moonshot import MoonshotChatfrom langchain.messages import HumanMessage, SystemMessage
复制
向 AI 提问
chat = MoonshotChat()# or use a specific model# Available models: https://platform.moonshot.cn/docs# chat = MoonshotChat(model="moonshot-v1-128k")
复制
向 AI 提问
messages = [ SystemMessage( content="You are a helpful assistant that translates English to French." ), HumanMessage( content="Translate this sentence from English to French. I love programming." ),]chat.invoke(messages)