本页还没有译文
本页 22 段还没译成简体中文,下面显示的是英文原文。ChatTogetherAI integration
还没翻译译自英文(docs.langchain.com)本页 22 段都还没译
Together AI offers an API to query 50+ leading open-source models in a couple lines of code.
This guide will help you getting started with ChatTogetherAI chat models. For detailed documentation of all ChatTogetherAI features and configurations head to the API reference.
Overview
Integration details
| Class | Package | Serializable | PY support | Downloads | Version |
|---|---|---|---|---|---|
ChatTogetherAI | @langchain/together-ai | ✅ | ✅ |
Model features
See the links in the table headers below for guides on how to use specific features.
| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Setup
To access ChatTogetherAI models, create a Together account, get an API key, and install the @langchain/together-ai integration package.
Credentials
Head to api.together.ai to sign up to Together AI and generate an API key. 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 LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"Installation
The LangChain ChatTogetherAI integration lives in the @langchain/together-ai package:
npm install @langchain/together-ai @langchain/coreyarn add @langchain/together-ai @langchain/corepnpm add @langchain/together-ai @langchain/coreInstantiation
Now we can instantiate our model object and generate chat completions:
import { ChatTogetherAI } from "@langchain/together-ai";
const llm = new ChatTogetherAI({
model: "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
temperature: 0,
// other params...
})Invocation
const aiMsg = await llm.invoke([
[
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
],
["human", "I love programming."],
])
aiMsgAIMessage {
"id": "chatcmpl-9rT9qEDPZ6iLCk6jt3XTzVDDH6pcI",
"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
}
}console.log(aiMsg.content)J'adore la programmation.API reference
For detailed documentation of all ChatTogetherAI features and configurations head to the API reference.