所有与 Anthropic 模型相关的功能。
Anthropic 是一家 AI 安全和研究公司,也是 Claude 的创造者。 本页面涵盖 Anthropic 模型与 LangChain 之间的所有集成。
提示最佳实践
与 OpenAI 模型相比,Anthropic 模型有几条提示最佳实践。
系统消息只能作为第一条消息
Anthropic 模型要求任何系统消息都必须是提示中的第一条。
ChatAnthropic
ChatAnthropic 是 LangChain 的 ChatModel的子类,这意味着它最适合与 ChatPromptTemplate. 你可以使用以下代码导入此包装器:
npm install @langchain/anthropic @langchain/core
const model = new ChatAnthropic({});
使用 ChatModels 时,建议将提示设计为 ChatPromptTemplates. 以下是相关示例:
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful chatbot"],
["human", "Tell me a joke about {topic}"],
]);
然后你可以按以下方式在链中使用它:
const chain = prompt.pipe(model);
await chain.invoke({ topic: "bears" });
参阅 聊天模型集成页面 了解更多示例,包括多模态输入。