Skip to main content

TogetherAI

You are currently on a page documenting the use of Together AI models as text completion models. Many popular models available on Together AI are chat completion models.

You may be looking for this page instead.

Together AI offers an API to query 50+ leading open-source models in a couple lines of code.

This will help you get started with Together AI text completion models (LLMs) using LangChain. For detailed documentation on TogetherAI features and configuration options, please refer to the API reference.

Overview

Integration details

ClassPackageLocalSerializablePY supportPackage downloadsPackage latest
TogetherAI@langchain/communityNPM - DownloadsNPM - Version

Setup

To access ChatTogetherAI models you’ll need to create a Together account, get an API key here, and install the @langchain/community integration package.

Credentials

Head to api.together.ai to sign up to TogetherAI and generate an API key. Once you’ve done this set the TOGETHER_AI_API_KEY environment variable:

export TOGETHER_AI_API_KEY="your-api-key"

If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

# export LANGCHAIN_TRACING_V2="true"
# export LANGCHAIN_API_KEY="your-api-key"

Installation

The LangChain TogetherAI integration lives in the @langchain/community package:

yarn add @langchain/community

Instantiation

Now we can instantiate our model object and generate chat completions:

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

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

Invocation

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,

Chaining

We can chain our completion model with a prompt template like so:

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 reference

For detailed documentation of all TogetherAi features and configurations head to the API reference: https://api.js.langchain.com/classes/langchain_community_llms_togetherai.TogetherAI.html


Was this page helpful?


You can also leave detailed feedback on GitHub.