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

# TogetherAI 集成

> 使用 LangChain JavaScript 集成 TogetherAI LLM。

> [!WARNING]
>
> **您当前所在的页面正在记录 Together AI 模型作为文本完成模型的使用方法。Together AI 上许多流行的模型是 [对话完成模型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md)。**
>
> 您可能需要查找 [这个页面](https://langchain-docs-zh.mintlify.site/langchain/oss/javascript/integrations/chat/togetherai.md)。

[Together AI](https://www.together.ai/) 提供了一个 API，可以在几行代码中查询 [50+ 领先的开源模型](https://docs.together.ai/docs/inference-models)。

这将帮助您使用 LangChain 开始使用 Together AI 文本完成模型（LLMs）。有关 `TogetherAI` 功能和配置选项的详细文档，请参阅 [API 参考](https://reference.langchain.com/javascript/langchain-together-ai/TogetherAI)。

## 概述

### 集成详情

| 类 | 包 | 本地 | 可序列化 | [PY 支持](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/llms/together.md) | 下载 | 版本 |
| :- | :- | :-: | :-: | :-: | :-: | :-: |
| [`TogetherAI`](https://reference.langchain.com/javascript/langchain-together-ai/TogetherAI) | [`@langchain/together-ai`](https://www.npmjs.com/package/@langchain/together-ai) | ❌ | ✅ | ✅ | ![NPM - 下载](https://img.shields.io/npm/dm/@langchain/together-ai?style=flat-square\&label=%20&) | ![NPM - 版本](https://img.shields.io/npm/v/@langchain/together-ai?style=flat-square\&label=%20&) |

## 设置

要访问遗留 `TogetherAI` 完成类，请创建一个 Together 账户，[获取 API 密钥](https://api.together.xyz/)，并安装 `@langchain/together-ai` 集成包。对于对话和指令模型，请优先使用 [`ChatTogetherAI`](https://langchain-docs-zh.mintlify.site/langchain/oss/javascript/integrations/chat/togetherai)。

### 凭证

前往 [api.together.ai](https://api.together.ai/) 注册 Together AI 并生成 API 密钥。设置 `TOGETHER_AI_API_KEY` 环境变量：

```bash theme={null}
export TOGETHER_AI_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 TogetherAI 集成位于 `@langchain/together-ai` 包中：

```bash npm theme={null}
npm install @langchain/together-ai @langchain/core
```

```bash yarn theme={null}
yarn add @langchain/together-ai @langchain/core
```

```bash pnpm theme={null}
pnpm add @langchain/together-ai @langchain/core
```

## 实例化

实例化完成模型：

```typescript theme={null}
import { TogetherAI } from "@langchain/together-ai";

const llm = new TogetherAI({
  model: "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo",
  maxTokens: 256,
});
```

## 调用

```typescript theme={null}
const inputText = "Together is an AI company that "

const completion = await llm.invoke(inputText)
completion
```

```text theme={null}
 offers a range of AI-powered solutions to help businesses and organizations improve their customer service, sales, and marketing efforts. Their platform uses natural language processing (NLP) and machine learning algorithms to analyze customer interactions and provide insights and recommendations to help businesses improve their customer experience.
Together's solutions include:
1. Customer Service: Together's customer service solution uses AI to analyze customer interactions and provide insights and recommendations to help businesses improve their customer experience. This includes analyzing customer feedback, sentiment analysis, and predictive analytics to identify areas for improvement.
2. Sales: Together's sales solution uses AI to analyze customer interactions and provide insights and recommendations to help businesses improve their sales efforts. This includes analyzing customer behavior, sentiment analysis, and predictive analytics to identify opportunities for upselling and cross-selling.
3. Marketing: Together's marketing solution uses AI to analyze customer interactions and provide insights and recommendations to help businesses improve their marketing efforts. This includes analyzing customer behavior, sentiment analysis, and predictive analytics to identify areas for improvement.
Together's platform is designed to be easy to use and integrates with a range of popular CRM and marketing automation tools. Their solutions are available as a cloud-based subscription service, making it easy for businesses to get started with AI-powered customer service, sales, and marketing.
Overall,
```

***

## API 参考

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

***

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


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