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

# ChatFireworks 集成

> 使用 LangChain JavaScript 集成 ChatFireworks 聊天模型。

[Fireworks AI](https://fireworks.ai/) 是一个用于运行和定制模型的 AI 推理平台。有关 Fireworks 提供的所有模型列表，请参阅 [Fireworks 文档](https://fireworks.ai/models)。

本指南将帮助您开始使用 `ChatFireworks` [聊天模型](/oss/javascript/langchain/models)。有关 `ChatFireworks` 所有功能和配置的详细文档，请前往 [API 参考](https://reference.langchain.com/javascript/langchain-community/chat_models/fireworks/ChatFireworks)。

## 概述

### 集成详情

| 类                                                                                                                     | 包                                                                            | 可序列化 | [Python 支持](https://python.langchain.com/docs/integrations/chat/fireworks) |                                                  下载量                                                 |                                                 版本                                                |
| :-------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------- | :--: | :------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------: |
| [`ChatFireworks`](https://reference.langchain.com/javascript/langchain-community/chat_models/fireworks/ChatFireworks) | [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) |   ✅  |                                      ✅                                     | ![NPM - Downloads](https://img.shields.io/npm/dm/@langchain/community?style=flat-square\&label=%20&) | ![NPM - Version](https://img.shields.io/npm/v/@langchain/community?style=flat-square\&label=%20&) |

### 模型特性

有关如何使用特定功能的指南，请参阅下表标题中的链接。

| [工具调用](/oss/javascript/langchain/tools) | [结构化输出](/oss/javascript/langchain/structured-output) | [图像输入](/oss/javascript/langchain/messages#multimodal) | 音频输入 | 视频输入 | [令牌级流式传输](/oss/javascript/langchain/streaming/) | [令牌使用量](/oss/javascript/langchain/models#token-usage) | [对数概率](/oss/javascript/langchain/models#log-probabilities) |
| :-------------------------------------: | :--------------------------------------------------: | :---------------------------------------------------: | :--: | :--: | :---------------------------------------------: | :---------------------------------------------------: | :--------------------------------------------------------: |
|                    ✅                    |                           ✅                          |                           ❌                           |   ❌  |   ❌  |                        ✅                        |                           ✅                           |                              ✅                             |

## 设置

要访问 `ChatFireworks` 模型，您需要创建一个 Fireworks 账户，获取 API 密钥，并安装 `@langchain/community` 集成包。

### 凭证

前往 [Fireworks 网站](https://fireworks.ai/login) 注册 Fireworks 并生成 API 密钥。完成后，设置 `FIREWORKS_API_KEY` 环境变量：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export FIREWORKS_API_KEY="your-api-key"
```

如果您希望自动追踪模型调用，还可以通过取消注释以下内容来设置 [LangSmith](/langsmith/home) API 密钥：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
```

### 安装

LangChain 的 `ChatFireworks` 集成位于 `@langchain/community` 包中：

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/community @langchain/core
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/community @langchain/core
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/community @langchain/core
  ```
</CodeGroup>

## 实例化

现在我们可以实例化模型对象并生成聊天补全：

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import { ChatFireworks } from "@langchain/community/chat_models/fireworks"

const llm = new ChatFireworks({
    model: "accounts/fireworks/models/llama-v3p1-70b-instruct",
    temperature: 0,
    maxTokens: undefined,
    timeout: undefined,
    maxRetries: 2,
    // 其他参数...
})
```

## 调用

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const aiMsg = await llm.invoke([
    [
        "system",
        "你是一个将英语翻译成法语的助手。请翻译用户的句子。",
    ],
    ["human", "I love programming."],
])
aiMsg
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
AIMessage {
  "id": "chatcmpl-9rBYHbb6QYRrKyr2tMhO9pH4AYXR4",
  "content": "J'adore la programmation.",
  "additional_kwargs": {},
  "response_metadata": {
    "tokenUsage": {
      "completionTokens": 8,
      "promptTokens": 31,
      "totalTokens": 39
    },
    "finish_reason": "stop"
  },
  "tool_calls": [],
  "invalid_tool_calls": [],
  "usage_metadata": {
    "input_tokens": 31,
    "output_tokens": 8,
    "total_tokens": 39
  }
}
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
console.log(aiMsg.content)
```

```text theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
J'adore la programmation.
```

***

## API 参考

有关 `ChatFireworks` 所有功能和配置的详细文档，请前往 [API 参考](https://reference.langchain.com/javascript/langchain-community/chat_models/fireworks/ChatFireworks)。

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\javascript\integrations\chat\fireworks.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
