跳到主要内容

Anthropic

所有与 Anthropic 模型相关的功能。

Anthropic 是一家 AI 安全和研究公司,也是 Claude 的创建者。本页涵盖 Anthropic 模型和 LangChain 之间的所有集成。

Prompting 最佳实践

与 OpenAI 模型相比,Anthropic 模型有几个 prompting 最佳实践。

系统消息只能是第一个消息

Anthropic 模型要求任何系统消息都必须是提示中的第一个。

ChatAnthropic

ChatAnthropic 是 LangChain 的 ChatModel 的子类,这意味着它最适合 ChatPromptTemplate。您可以使用以下代码导入此包装器

提示

请参阅此部分以获取有关安装集成包的通用说明。

npm install @langchain/anthropic @langchain/core
import { ChatAnthropic } from "@langchain/anthropic";
const model = new ChatAnthropic({});

当使用 ChatModels 时,建议您将提示设计为 ChatPromptTemplate。以下是一个示例:

import { ChatPromptTemplate } from "langchain/prompts";

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" });

请参阅 聊天模型集成页面 以获取更多示例,包括多模态输入。


此页对您有帮助吗?


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