An integration package connecting Mistral and LangChain
Project description
langchain-mistralai
This package contains the LangChain integrations for MistralAI through their mistralai SDK.
Installation
pip install -U langchain-mistralai
Chat Models
This package contains the ChatMistralAI
class, which is the recommended way to interface with MistralAI models.
To use, install the requirements, and configure your environment.
export MISTRAL_API_KEY=your-api-key
Then initialize
from langchain_core.messages import HumanMessage
from langchain_mistralai.chat_models import ChatMistralAI
chat = ChatMistralAI(model="mistral-small")
messages = [HumanMessage(content="say a brief hello")]
chat.invoke(messages)
ChatMistralAI
also supports async and streaming functionality:
# For async...
await chat.ainvoke(messages)
# For streaming...
for chunk in chat.stream(messages):
print(chunk.content, end="", flush=True)
Embeddings
With MistralAIEmbeddings
, you can directly use the default model 'mistral-embed', or set a different one if available.
Choose model
embedding.model = 'mistral-embed'
Simple query
res_query = embedding.embed_query("The test information")
Documents
res_document = embedding.embed_documents(["test1", "another test"])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file langchain_mistralai-0.2.2.tar.gz
.
File metadata
- Download URL: langchain_mistralai-0.2.2.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ff8d318f7c811a49feba7d15e4dad003957e33b12cdcc733839eae1f04bab9d |
|
MD5 | e88eefce6c09b9b3b4976f350fb031ff |
|
BLAKE2b-256 | 164710153a59681613b26d50c5a8c8d09ff6de07e626e2ca2b9d959fef2ce62a |
File details
Details for the file langchain_mistralai-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: langchain_mistralai-0.2.2-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2245b3590ba2f8e2f24108d6753f85238c154ca86851499c8431af75b9f7e07d |
|
MD5 | 4547769b7aae8197a5738899313b6ac1 |
|
BLAKE2b-256 | 117e5fc19264fb7fae020f0562d1614f545d60ecaf93dc5fb8fc778399f2d026 |