> ## 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.

# (MODULE_NAME) 集成

> 使用 LangChain Python 集成 (MODULE_NAME) 对话模型。

如何使用此 Python 对话模型模板：

* [ ] 将 (MODULE\_NAME) 替换为模块名称，例如 Anthropic、OpenAI 等（`command + F` 是你的好帮手）
* [ ] 更新链接指向正确模块
* [ ] 在详细信息和功能表格下，更新 ✅/❌ 以反映对话模型的实际功能
* [ ] 如需更新，修改 PyPI/注册表包名称
* [ ] 设置 `integration` 前置元数据（`name` 是 LangChain 类；省略 `pypi` 对于 N/A 下载量；省略未文档化的能力键）。除非维护者要求，否则不要设置 `featured: true`
* [ ] 如需更新，修改 API 密钥环境变量名称

模板从本行开始...

本指南为快速入门提供了 (MODULE\_NAME) [对话模型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md) 的概述。要查看所有 Chat(MODULE\_NAME) 功能、参数和配置的完整列表，请访问 [Chat(MODULE\_NAME) API 参考](https://reference.langchain.com/python/langchain-\(module-name\)/chat_models/Chat\(MODULE_NAME\))。

## 概览

### 详细信息

| 类 | 包 | 可序列化 | [JS 支持](https://langchain-docs-zh.mintlify.site/langchain/oss/javascript/integrations/chat/anthropic.md) | 下载量 | 版本 |
| :- | :- | :-: | :-: | :-: | :-: |
| [Chat(MODULE\_NAME)](https://reference.langchain.com/python/langchain-\(module-name\)/chat_models/Chat\(MODULE_NAME\)) | [langchain-(MODULE\_NAME)](https://reference.langchain.com/python/langchain-\(module-name\)) | beta/❌ | ✅/❌ | ![PyPI - 下载量](https://img.shields.io/pypi/dm/langchain-\(MODULE_NAME\)?style=flat-square\&label=%20) | ![PyPI - 版本](https://img.shields.io/pypi/v/langchain-\(MODULE_NAME\)?style=flat-square\&label=%20) |

### 功能

| [工具调用](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md) | [结构化输出](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/structured-output.md) | [图像输入](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#多模态) | [音频输入](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#多模态) | [视频输入](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#多模态) | [Token 级流式输出](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/streaming.md) | 原生异步 | [Token 使用量](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#token-使用) | [对数概率](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#对数概率) |
| :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
| ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅/❌ | ✅❌ |

***

## 配置

要访问 (MODULE\_NAME) 模型，你需要创建/an (MODULE\_NAME) 账户，获取 API 密钥，并安装 `langchain-(MODULE_NAME)` 集成包。

### 凭据

```python Set API key icon="key" theme={null}
import getpass
import os

if "(MODULE_NAME)_API_KEY" not in os.environ:
    os.environ["(MODULE_NAME)_API_KEY"] = getpass.getpass("Enter your (MODULE_NAME) API key: ")
```

为自动追踪 调用 (Log each step of a model's execution to debug and improve it)，设置你的 [LangSmith](https://docs.langchain.com/langsmith/observability) API 密钥：

```python Enable tracing icon="flask" theme={null}
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
```

### 安装

LangChain (MODULE\_NAME) 集成位于 `langchain-(MODULE_NAME)` 包中：

```python pip theme={null}
pip install -U langchain-(MODULE_NAME)
```

```python uv theme={null}
uv add langchain-(MODULE_NAME)
```

***

## 实例化

现在我们可以实例化模型对象并生成响应：

```python Initialize chat model icon="robot" theme={null}
from langchain_(MODULE_NAME) import Chat(MODULE_NAME)

model = Chat(MODULE_NAME)(
    model="model-name",
    temperature=0,
    timeout=None,
    max_tokens=1024,
    max_retries=2,
    # Other params - see API reference for full list
)
```

***

## 调用

```python Dictionary format icon="book" theme={null}
messages = [
    {"role": "system", "content": "You are a poetry expert"},
    {"role": "user", "content": "Write a haiku about spring"},
]
response = model.invoke(messages)
print(response)
```

```python Message objects icon="message" theme={null}
from langchain.messages import SystemMessage, HumanMessage, AIMessage

messages = [
    SystemMessage("You are a poetry expert"),
    HumanMessage("Write a haiku about spring"),
    AIMessage("Cherry blossoms bloom...")
]
response = model.invoke(messages)
```

```plaintext Response object icon="terminal" theme={null}
TODO - replace with response.model_dump_json(indent=2) or similar
```

```python Text content icon="cursor-text" theme={null}
print(response.text)

# TODO - replace with the output of response.text
```

```python Content Blocks icon="layout-grid" theme={null}
print(response.content_blocks)

# TODO - replace with the output of response.content_blocks
```

> [!TIP]
>
> 完整指南请参考 [对话模型调用类型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#调用)、[消息类型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#消息类型) 和 [内容块](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#标准内容块)。

## TODO：特定于本模型的任何功能

删除若不适用。

参考现有模型文档示例，例如：

* [ChatAnthropic](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/anthropic.md)
* [ChatOpenAI](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/openai.md)
* [ChatGenAI](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/google_generative_ai.md)

示例：

* &#x20;工具调用
* &#x20;推理输出 / 扩展推理
* &#x20;详略程度
* &#x20;引用
* &#x20;内置工具
  * &#x20;网页搜索
  * &#x20;代码执行
  * &#x20;远程 MCP
* &#x20;多模态输入/输出
* &#x20;缓存
* &#x20;链式调用
* &#x20;流式使用元数据
* &#x20;微调
* &#x20;弹性处理
* &#x20;自定义基础 URL 或代理行为

***

## API 参考

要查看所有 Chat(MODULE\_NAME) 功能和配置的详细文档，请访问 [API 参考](LINK)。

***

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


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