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

# ChatFireworks 集成

> 集成 ChatFireworks 对话模型使用 LangChain JavaScript.

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

本指南将帮助你开始使用 `ChatFireworks` [对话模型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md)。有关所有 `ChatFireworks` 功能和配置的详细文档，请前往 [API 参考](https://reference.langchain.com/javascript/langchain-fireworks/ChatFireworks)。

## 概述

### 集成详情

| 类 | 包 | 可序列化 | [PY 支持](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/fireworks.md) | 下载次数 | 版本 |
| :- | :- | :-: | :-: | :-: | :-: |
| [`ChatFireworks`](https://reference.langchain.com/javascript/langchain-fireworks/ChatFireworks) | [`@langchain/fireworks`](https://www.npmjs.com/package/@langchain/fireworks) | ✅ | ✅ | ![NPM - 下载次数](https://img.shields.io/npm/dm/@langchain/fireworks?style=flat-square\&label=%20&) | ![NPM - 版本](https://img.shields.io/npm/v/@langchain/fireworks?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#多模态) | 音频输入 | 视频输入 | [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-使用) | [Logprobs](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#对数概率) |
| :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |

## 设置

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

### 凭证

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

```bash theme={null}
export FIREWORKS_API_KEY="your-api-key"
```

如果你希望自动跟踪你的模型调用，可以通过取消注释以下内容来设置你的 [LangSmith](https://docs.langchain.com/langsmith/observability) API 密钥：

```bash theme={null}
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
```

### 安装

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

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

```bash yarn theme={null}
yarn add @langchain/fireworks @langchain/core
```

```bash pnpm theme={null}
pnpm add @langchain/fireworks @langchain/core
```

## 实例化

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

```typescript theme={null}
import { ChatFireworks } from "@langchain/fireworks"

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

## 调用

```typescript theme={null}
const aiMsg = await llm.invoke([
    [
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ],
    ["human", "I love programming."],
])
aiMsg
```

```text theme={null}
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={null}
console.log(aiMsg.content)
```

```text theme={null}
J'adore la programmation.
```

***

## API 参考

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

***

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


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