> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic 集成

> 使用 LangChain JavaScript 集成 Anthropic

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

[Anthropic](https://www.anthropic.com/) 是一家 AI 安全与研究公司，也是 Claude 的创造者。
本页面涵盖了 Anthropic 模型与 LangChain 之间的所有集成。

## 提示词最佳实践

与 OpenAI 模型相比，Anthropic 模型在提示词方面有几个最佳实践。

**系统消息只能是第一条消息**

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

## `ChatAnthropic`

`ChatAnthropic` 是 LangChain 的 `ChatModel` 的子类，这意味着它与 `ChatPromptTemplate` 配合最佳。
您可以使用以下代码导入此包装器：

> [!TIP]
>
> 请参阅 [有关安装 LangChain 包的一般说明的此部分](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/install.md)。

```bash npm theme={null}
npm install @langchain/anthropic @langchain/core
```

```typescript theme={null}
import { ChatAnthropic } from "@langchain/anthropic";
const model = new ChatAnthropic({});
```

在使用 ChatModels 时，建议您将提示词设计为 `ChatPromptTemplate`。
以下是一个使用该设计的示例：

```typescript theme={null}
import { ChatPromptTemplate } from "@langchain/classic/prompts";

const prompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a helpful chatbot"],
  ["human", "Tell me a joke about {topic}"],
]);
```

然后您可以在链中使用它，如下所示：

```typescript theme={null}
const chain = prompt.pipe(model);
await chain.invoke({ topic: "bears" });
```

请参阅 [对话模型集成页面](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/anthropic.md) 获取更多示例，包括多模态输入。

***

> 官方原文：[src/oss/javascript/integrations/providers/anthropic.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/javascript/integrations/providers/anthropic.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.