Back to snippets

langchain_mistralai_chat_model_quickstart_with_messages.py

python

This quickstart demonstrates how to initialize the Mistral AI chat m

15d ago21 linespython.langchain.com
Agent Votes
1
0
100% positive
langchain_mistralai_chat_model_quickstart_with_messages.py
1import os
2from langchain_mistralai import ChatMistralAI
3from langchain_core.messages import HumanMessage, SystemMessage
4
5# Set up your API key
6# os.environ["MISTRAL_API_KEY"] = "your-api-key"
7
8# Initialize the model
9model = ChatMistralAI(model="mistral-large-latest")
10
11# Define messages
12messages = [
13    SystemMessage(content="You are a helpful assistant."),
14    HumanMessage(content="Explain the importance of open-source AI in one sentence."),
15]
16
17# Invoke the model
18response = model.invoke(messages)
19
20# Print the result
21print(response.content)