跳至主要内容

MoonshotChat

Moonshot 是一家中国初创公司,为企业和个人提供 LLM 服务。

本示例介绍如何使用 LangChain 与 Moonshot Inference for Chat 交互。

import os

# Generate your api key from: https://platform.moonshot.cn/console/api-keys
os.environ["MOONSHOT_API_KEY"] = "MOONSHOT_API_KEY"
from langchain_community.chat_models.moonshot import MoonshotChat
from langchain_core.messages import HumanMessage, SystemMessage
chat = MoonshotChat()
# or use a specific model
# Available models: https://platform.moonshot.cn/docs
# chat = MoonshotChat(model="moonshot-v1-128k")
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)

此页面对您有帮助吗?


您也可以在 GitHub 上留下详细的反馈 on GitHub.