聊天模型
¥Chat models
聊天模型 是语言模型,以 messages 序列为输入,返回消息作为输出(而不是使用纯文本)。这些通常是较新的模型。
¥Chat models are language models that use a sequence of messages as inputs and return messages as outputs (as opposed to using plain text). These are generally newer models.
info
如果你想编写自己的聊天模型,请参阅 此操作指南。如果你想贡献集成,请参阅 贡献集成。
¥If you'd like to write your own chat model, see this how-to. If you'd like to contribute an integration, see Contributing integrations.
Pick your chat model:
- Groq
- OpenAI
- Anthropic
- Google Gemini
- FireworksAI
- MistralAI
- VertexAI
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/groq
yarn add @langchain/groq
pnpm add @langchain/groq
Add environment variables
GROQ_API_KEY=your-api-key
Instantiate the model
import { ChatGroq } from "@langchain/groq";
const model = new ChatGroq({
model: "llama-3.3-70b-versatile",
temperature: 0
});
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/openai
yarn add @langchain/openai
pnpm add @langchain/openai
Add environment variables
OPENAI_API_KEY=your-api-key
Instantiate the model
import { ChatOpenAI } from "@langchain/openai";
const model = new ChatOpenAI({ model: "gpt-4o-mini" });
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/anthropic
yarn add @langchain/anthropic
pnpm add @langchain/anthropic
Add environment variables
ANTHROPIC_API_KEY=your-api-key
Instantiate the model
import { ChatAnthropic } from "@langchain/anthropic";
const model = new ChatAnthropic({
model: "claude-3-5-sonnet-20240620",
temperature: 0
});
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/google-genai
yarn add @langchain/google-genai
pnpm add @langchain/google-genai
Add environment variables
GOOGLE_API_KEY=your-api-key
Instantiate the model
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
const model = new ChatGoogleGenerativeAI({
model: "gemini-2.0-flash",
temperature: 0
});
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/community
yarn add @langchain/community
pnpm add @langchain/community
Add environment variables
FIREWORKS_API_KEY=your-api-key
Instantiate the model
import { ChatFireworks } from "@langchain/community/chat_models/fireworks";
const model = new ChatFireworks({
model: "accounts/fireworks/models/llama-v3p1-70b-instruct",
temperature: 0
});
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/mistralai
yarn add @langchain/mistralai
pnpm add @langchain/mistralai
Add environment variables
MISTRAL_API_KEY=your-api-key
Instantiate the model
import { ChatMistralAI } from "@langchain/mistralai";
const model = new ChatMistralAI({
model: "mistral-large-latest",
temperature: 0
});
Install dependencies
- npm
- yarn
- pnpm
npm i @langchain/google-vertexai
yarn add @langchain/google-vertexai
pnpm add @langchain/google-vertexai
Add environment variables
GOOGLE_APPLICATION_CREDENTIALS=credentials.json
Instantiate the model
import { ChatVertexAI } from "@langchain/google-vertexai";
const model = new ChatVertexAI({
model: "gemini-1.5-flash",
temperature: 0
});
await model.invoke("Hello, world!")
特色提供商
¥Featured providers
Model | Stream | JSON mode | Tool Calling | withStructuredOutput() | Multimodal |
---|---|---|---|---|---|
BedrockChat | ✅ | ❌ | 🟡 (Bedrock Anthropic only) | 🟡 (Bedrock Anthropic only) | 🟡 (Bedrock Anthropic only) |
ChatBedrockConverse | ✅ | ❌ | ✅ | ✅ | ✅ |
ChatAnthropic | ✅ | ❌ | ✅ | ✅ | ✅ |
ChatCloudflareWorkersAI | ✅ | ❌ | ❌ | ❌ | ❌ |
ChatCohere | ✅ | ❌ | ✅ | ✅ | ✅ |
ChatFireworks | ✅ | ✅ | ✅ | ✅ | ✅ |
ChatGoogleGenerativeAI | ✅ | ❌ | ✅ | ✅ | ✅ |
ChatVertexAI | ✅ | ❌ | ✅ | ✅ | ✅ |
ChatGroq | ✅ | ✅ | ✅ | ✅ | ✅ |
ChatMistralAI | ✅ | ✅ | ✅ | ✅ | ✅ |
ChatOllama | ✅ | ✅ | ✅ | ✅ | ✅ |
ChatOpenAI | ✅ | ✅ | ✅ | ✅ | ✅ |
ChatTogetherAI | ✅ | ✅ | ✅ | ✅ | ✅ |
ChatXAI | ✅ | ✅ | ✅ | ✅ | ❌ |
所有聊天模型
¥All chat models
Name | Description |
---|---|
阿里巴巴统一 | chatalibabatongyi} |
百度千帆 | chatbaiduqianfan} |
深度基础设施 | chatdeepinfra} |
DeepSeek | 这将帮助你开始使用 DeepSeek 聊天模型。有关 ChatDeepSeek 所有功能和配置的详细文档,请参阅 API 参考。 |
伪 LLM | fake-llm} |
友情链接 | friendli} |
Llama CPP | llama-cpp} |
Minimax | minimax} |
Moonshot | chatmoonshot} |
困惑 | 本指南将帮助你开始使用 Perplexity 聊天模型。有关 ChatPerplexity 所有功能和配置的详细文档,请参阅 API 参考。 |
PremAI | chatprem} |
腾讯混元 | chattencenthunyuan} |
WebLLM | webllm} |
YandexGPT | chatyandexgpt} |
ZhipuAI | chatzhipuai} |