Skip to main content

TogetherAI

您当前所在的页面记录的是如何将 Together AI 模型用作 文本补全模型。Together AI 上提供的许多流行模型都是 聊天补全模型

您可能需要查看这个页面

Together AI 提供了一个 API,可以通过几行代码查询 50 多个领先的开源模型

这将帮助您使用 LangChain 开始使用 Together AI 的 文本补全模型(LLMs)。有关 TogetherAI 功能和配置选项的详细文档,请参阅 API 参考

概述

集成详情

本地可序列化Python 支持包下载量最新包
TogetherAI@langchain/communityNPM - 下载量NPM - 版本

准备工作

要访问 ChatTogetherAI 模型,您需要创建一个 Together 账户,此处 获取 API 密钥,并安装 @langchain/community 集成包。

凭证

前往 api.together.ai 注册 TogetherAI 并生成 API 密钥。完成此操作后,请设置 TOGETHER_AI_API_KEY 环境变量:

export TOGETHER_AI_API_KEY="your-api-key"

如果您希望自动追踪您的模型调用,也可以取消下面的注释以设置您的 LangSmith API 密钥:

# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

安装

LangChain TogetherAI 集成位于 @langchain/community 包中:

:::提示 请参阅安装集成包的一般说明部分。 :::

yarn add @langchain/community @langchain/core

实例化

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

import { TogetherAI } from "@langchain/community/llms/togetherai";

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

调用

const inputText = "Together is an AI company that ";

const completion = await llm.invoke(inputText);
completion;
 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,

链式调用

我们可以将补全模型与提示模板链式调用,如下所示:

import { PromptTemplate } from "@langchain/core/prompts";

const prompt = PromptTemplate.fromTemplate(
"How to say {input} in {output_language}:\n"
);

const chain = prompt.pipe(llm);
await chain.invoke({
output_language: "German",
input: "I love programming.",
});
Ich liebe Programmieren.

How to say I love programming. in French:
J'adore programmer.

How to say I love programming. in Spanish:
Me encanta programar.

How to say I love programming. in Italian:
Mi piace programmare.

How to say I love programming. in Portuguese:
Eu amo programar.

How to say I love programming. in Russian:
Я люблю программирование.

How to say I love programming. in Japanese:
私はプログラミングが好きです。

How to say I love programming. in Chinese:
我喜欢编程。

How to say I love programming. in Korean:
나는 프로그래밍을 좋아합니다.

How to say I love programming. in Arabic:
أنا أحب البرمجة.

How to say I love programming. in Hebrew:
אני אוהבת לתכנת.

How to say I love programming. in Hindi:

मुझे प्रोग्रामिंग पसंद है।



I hope this helps you express your love for programming in different languages!

API 参考文档

如需了解所有 TogetherAi 功能和配置的详细文档,请访问 API 参考页面: https://api.js.langchain.com/classes/langchain_community_llms_togetherai.TogetherAI.html


Was this page helpful?


You can also leave detailed feedback on GitHub.