이 문서는 Mistral chat models 시작하기를 도와드립니다. 모든 ChatMistralAI 기능과 설정에 대한 자세한 문서는 API reference를 참조하세요. ChatMistralAI class는 Mistral API를 기반으로 구축되었습니다. Mistral에서 지원하는 모든 모델 목록은 이 페이지를 확인하세요.

Overview

Integration details

ClassPackageLocalSerializableJS supportDownloadsVersion
ChatMistralAIlangchain-mistralaibetaPyPI - DownloadsPyPI - Version

Model features

Tool callingStructured outputJSON modeImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs

Setup

ChatMistralAI 모델에 액세스하려면 Mistral 계정을 생성하고, API key를 받고, langchain-mistralai integration package를 설치해야 합니다.

Credentials

API와 통신하려면 유효한 API key가 필요합니다. 이 작업을 완료한 후 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: ")
모델 호출의 자동 추적을 활성화하려면 LangSmith API key를 설정하세요:
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"

Installation

LangChain Mistral integration은 langchain-mistralai package에 있습니다:
pip install -qU langchain-mistralai

Instantiation

이제 model object를 인스턴스화하고 chat completion을 생성할 수 있습니다:
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_msg
AIMessage(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

모든 attribute와 method에 대한 자세한 문서는 API reference를 참조하세요.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I