本页还没有译文
本页 19 段还没译成简体中文,下面显示的是英文原文。ChatMistralAI integration
还没翻译译自英文(docs.langchain.com)本页 19 段都还没译
This will help you get started with Mistral chat models. For detailed documentation of all ChatMistralAI features and configurations head to the API reference. The ChatMistralAI class is built on top of the Mistral API. For a list of all the models supported by Mistral, check out this page.
Overview
Integration details
| Class | Package | Serializable | JS support | Downloads | Version |
|---|---|---|---|---|---|
ChatMistralAI | langchain-mistralai | beta | ✅ |
Model features
| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |
Setup
To access ChatMistralAI models you'll need to create a Mistral account, get an API key, and install the langchain-mistralai integration package.
Credentials
A valid API key is needed to communicate with the API. Once you've done this set the MISTRAL_API_KEY environment variable:
import getpass
import os
if "MISTRAL_API_KEY" not in os.environ:
os.environ["MISTRAL_API_KEY"] = getpass.getpass("Enter your Mistral API key: ")To enable automated tracing of your model calls, set your LangSmith API key:
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"Installation
The LangChain Mistral integration lives in the langchain-mistralai package:
pip install -qU langchain-mistralaiInstantiation
Now we can instantiate our model object and generate chat completions:
from langchain_mistralai import ChatMistralAI
llm = ChatMistralAI(
model="mistral-large-latest",
temperature=0,
max_retries=2,
# other params...
)Invocation
messages = [
(
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
),
("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msgAIMessage(content='Sure, I\'d be happy to help you translate that sentence into French! The English sentence "I love programming" translates to "J\'aime programmer" in French. Let me know if you have any other questions or need further assistance!', response_metadata={'token_usage': {'prompt_tokens': 32, 'total_tokens': 84, 'completion_tokens': 52}, 'model': 'mistral-small', 'finish_reason': 'stop'}, id='run-64bac156-7160-4b68-b67e-4161f63e021f-0', usage_metadata={'input_tokens': 32, 'output_tokens': 52, 'total_tokens': 84})print(ai_msg.content)Sure, I'd be happy to help you translate that sentence into French! The English sentence "I love programming" translates to "J'aime programmer" in French. Let me know if you have any other questions or need further assistance!API reference
Head to the API reference for detailed documentation of all attributes and methods.