Skip to main content
Mistral AI is a platform that offers hosting for their powerful open source models. This will help you getting started with Mistral chat models. For detailed documentation of all ChatMistralAI features and configurations head to the API reference.

概述

集成详情

模型功能

请参阅下表标题中的链接,了解如何使用特定功能。

设置

要访问 Mistral AI models,你需要create a Mistral AI account, get an API key, and install the @langchain/mistralai integration package.

凭证

Visit the Mistral console to sign up and generate an API key. Once you’ve done this set the MISTRAL_API_KEY environment variable:
如果你想要自动追踪模型调用,还可以设置你的 LangSmith API 密钥,取消注释以下内容:

安装

LangChain 的 ChatMistralAI 集成位于 @langchain/mistralai 包中:

实例化

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

调用

When sending chat messages to mistral, there are a few requirements to follow:
  • The first message can not be an assistant (ai) message.
  • Messages must alternate between user and assistant (ai) messages.
  • Messages can not end with an assistant (ai) or system message.

工具调用

Mistral’s API supports tool calling for a subset of their models. You can see which models support tool calling on this page. The examples below demonstrates how to use it:

Hooks

Mistral AI supports custom hooks for three events: beforeRequest, requestError, and response. Examples of the function signature for each hook type can be seen below:
To add these hooks to the chat model, either pass them as arguments and they are automatically added:
Or assign and add them manually after instantiation:
The method addAllHooksToHttpClient clears all currently added hooks before assigning the entire updated hook lists to avoid hook duplication. Hooks can be removed one at a time, or all hooks can be cleared from the model at once.

API 参考

有关所有 ChatMistralAI 功能和配置的详细文档,请前往 API 参考