Deploy Mistral Large to Azure and create a conversation with Python and LangChain
Tags: ai, mistral, llm, rag
Published: 2024-02-27 11:34:22

---
title: Deploy Mistral Large to Azure and create a conversation with Python and LangChain
published: true
date: 2024-02-27 01:59:48 UTC
tags: AI, mistral, llm, rag
canonical_url: https://neon.tech/blog/deploy-mistral-large-to-azure-and-chat-with-langchain
---

![](https://neondatabase.wpengine.com/wp-content/uploads/2024/02/neon-mistral-large-1024x576.jpg)

**We’re Neon, and we’re redefining the database experience with our cloud-native serverless Postgres solution. If you’ve been looking for a database for your RAG apps that adapts to your application loads, you’re in the right place.** [Learn more about Neon and give it a try](https://neon.tech), **and let us know what you think. Neon is cloud-native Postgres and scales your AI apps to millions of users with pgvector. In this post, Raouf is going to tell you what you need to know about Mistral Large, the most advanced LLM by MistralAI.**

[Mistral AI](https://mistral.ai/)has recently unveiled its most advanced open-source large language model (LLM) yet, [Mistral Large](https://mistral.ai/news/mistral-large/), alongside its ChatGPT competitor, [Le Chat (beta)](https://chat.mistral.ai/chat). Le Chat includes other models such as Next, and Small, to let you explore Mistral AI’s capabilities. 

![](https://lh7-us.googleusercontent.com/8gIqi97fGwzEyoTi2KZT0VEu5V5f6K97FSHSZDxienTF5OjhFd6q1iYetEISe_PlEeOZbTrdgPFtY5Gfn39WGj7wGa1UUN3Mqcg4LQIyhuIwyLobLxM1Ny28P5Z3VWzJEEPSVFZP5WDkJYrKQF3Yo4A)

For those waiting to get their hands on Le Chat but stuck in the queue, this guide will show you how to deploy Mistral Large on Azure and start using it immediately with LangChain.

Before we dive into the deployment process, let’s briefly explore Mistral Large.

## Mistral Large

Mistral Large is Mistral AI’s most advanced model with unparalleled reasoning capabilities across multiple languages, including French, Spanish, German and Italian. It has a generous 32k token context window making interesting for Retrieval Augmented Generation applications. 

![](https://lh7-us.googleusercontent.com/cxDxRUeLm6wWrMNszLuhRULvsEzEBhHt8wd2vHiLbtm-DIG918JKnDKrkVoTQX8JZ89sI-fVamTsgczVvu6xvA3SbYtPpAsRnq00Q5qwQPEMj2tVk3S4F67tHbRXMhFxBdb9Fu6at-fiOmKXiIzKdg4)
_Comparison measuring massive multitask language understanding_

And most importantly, Mistral Large is pretty good at coding and math. The model ranks the highest in the MassiveText Benchmarks for Programming Problems (MBPP), which covers a wide range of difficulty levels and programming concepts and is designed to evaluate models on several fronts, including accuracy and efficiency.

Mistral Large also ranks the highest in the GSM8K, which measures the capabilities of AI models in educational contexts and reasoning in mathematics.

![](https://lh7-us.googleusercontent.com/8J_GrBLxGXn9Nc6F17IDeM67h7ExNr9aDoXTry0vW6sZZDu89Ik-wOYjDh2KkDL3r5EhEhvx5mrUZ7RIaYhIGBlNdP1kyukckWF8CtGqONU9EJH6Z_LWv40Kc-pDZK0-p9neoJVbGhV0J-rjQ2PU6Mw)

But don’t believe the benchmarks. Next, we’ll deploy the Mistral Large model to Azure and try it for ourselves.

## Deploy your own Mistral Large model to Azure

As part of the launch, [Mistral AI announced its partnership with Microsoft](https://techcommunity.microsoft.com/t5/ai-machine-learning-blog/mistral-large-mistral-ai-s-flagship-llm-debuts-on-azure-ai/ba-p/4066996), making the Mistral Large model available on Azure. Below are the steps to deploy the model:

1. **Access Azure AI Studio** : Sign into your Azure account and navigate to [AI Studio](https://aka.ms/aistudio/landing/mistral-large).
2. **Deploy Mistral Large** : Look for the “Deploy” option and select Mistral Large for deployment.

![](https://lh7-us.googleusercontent.com/PfnrRJlLi2QkBbCQduHnQolVAVvIpboPWVS2BbvDI0LNp3urRqKVzZOP6aYaNuD7P3AQMcXgVzqjvvZ8OiEHbbnsvqcozZrt9sRC7C_mhQUpdryrxd9vfsS7xY_jsWXLIOoBS-AynTld7yvsmmwUD1Q)

1. **Create a Project** : If you haven’t already, set up a new project, opting for the Pay-As-You-Go plan and choosing France Central as your region.

![](https://lh7-us.googleusercontent.com/0wSELK9qf2A2wRW-X2OL5vOr3xyqESk7w9QV30SvxORwk5nKoY3eKXMlV4H4xjUdX-WfqKaDwuFXtzoHNuGAeoX6g3USIQgQKB8n0mLvOExqmSDXaVxwPCwlB23AYB9Sw0jSrxEpXApkbrRSWAAOCdM)

1. **Review and Create** : Double-check your resource information before finalizing your AI project.

![](https://lh7-us.googleusercontent.com/FKZnA38G-1NsyZSrXPf9blXdJM2HXuiwp2jMkAKze9ikcn_XQGMd8hZKNiyV8gkR4iUWLLvZe4BUaruVHaOHidMvvrPV_UiVkWwLC3VzpGY8DiTuMZJvVqOYdYfeVNCWYq2Qy-lZ4W9PkjGstWAh8vo)

1. **Finalize Deployment** : After creating your AI project, proceed to deploy Mistral Large. Choose a name for your deployment; this will be your inference endpoint’s identifier.

1. **Select a Deployment Name** : This is the name that will be displayed on your inference endpoint.

![](https://lh7-us.googleusercontent.com/guIBz98FTh8vG_v6taDCz7GcQLj792GnMV-F0waGEMM_u6v6cp-RKR0E3w7JE6nIxy6ticXYMg40bqnJUWjJjaLvV8jYMUQilPYRFy8RuSRK6EfKPMavf_pTBRYT1SXKGXBWtQRtXdyGJ6PPNroI0rs)

Congratulations 🎉 You’ve successfully deployed Mistral Large on Azure!

## How to use Mistral Large with LangChain

After deployment, you’ll receive an API endpoint and a security key for making inferences. We’ll use those further below.

![](https://lh7-us.googleusercontent.com/pvRNJlPtU4hNkDD2wFZ21Jfzh_-M3URrLdMctrJphRsYZ73F_nYoj2iW7_lpZcAnl194JZx-Gjpu8mybCxJfHnnmle5__LtTszAYEBgKl5r1l-QL71-m72KYYIK0WO1e89Ou0EgjDwwDIygkjRh_LOY)

To use Mistral Large with LangChain, follow these steps:

1. **Create project**

```bash
mkdir mistral-large-example
cd mistral-large-example">
```

1. **Create and activate Python environment:** Run the following command to create an environment.

```bash
python -m venv myenv
source myenv/bin/activate
```

1. **Install packages and project dependencies:**

```bash
pip install langchain langchain_mistralai
```

1. **Create a LangChain conversation:** first, create a file:

```bash
touch main.py
```

Here’s an example of how to create a LangChain conversation chain with Mistral Large:

```python
from langchain.chains import LLMChain
from langchain.memory import ConversationBufferMemory
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder
from langchain.schema import SystemMessage
from langchain_mistralai.chat_models import ChatMistralAI

# Configuration for prompting
prompt = ChatPromptTemplate.from_messages([
    SystemMessage(content="You are a chatbot engaging in a conversation with a human, often incorporating French cultural references."),
    MessagesPlaceholder(variable_name="chat_history"),
    HumanMessagePromptTemplate.from_template("{human_input}"),
])

# Memory configuration
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)

# Configuring the Mistral model endpoint and API key
chat_model = ChatMistralAI(
    endpoint="https://&lt;endpoint&gt;.francecentral.inference.ai.azure.com",
    mistral_api_key="&lt;api-key",
)

# Setting up the conversation chain
chat_llm_chain = LLMChain(
    llm=chat_model,
    prompt=prompt,
    memory=memory,
    verbose=True,
)

# Example usage
result = chat_llm_chain.predict(human_input="Hi there, my friend")
print(result)
```

Copy/Paste the code above to the `main.py` file and run the following:

```bash
python main.py
```

Here is how the output should look like:

```bash
python3 main.py 

Entering new LLMChain chain...

Prompt after formatting:

System: You are a chatbot engaging in a conversation with a human, often incorporating French cultural references.

Human: Hi there, my friend

&gt; Finished chain.

 Hello! It's a pleasure to chat with you. As you've noticed, I enjoy incorporating French cultural references into our conversations. Did you know that the Eiffel Tower, one of France's most iconic landmarks, was initially criticized by some of France's leading artists and intellectuals for its design when it was first built? How can I assist you today?">
```

## Conclusion

There has never been a better time to develop AI-powered applications. With rapid deployments to robust and scalable infrastructures such as Azure’s, developers can create applications that are more intelligent, interactive, and impactful.

If you are building a RAG application, or simply need a Postgres database that scales, Neon with its autoscaling capabilities offers elastic vector search and fast index build with pgvector, making your AI apps fast and scalable to millions of users.

[Start building with Neon for free today](https://console.neon.tech), join us on [Discord](https://neon.tech/discord) and let us know what you’re working on and how we can help you build better apps. 

## Resources

- [Mixtral 8x7B: What you need to know about Mistral AI’s latest model](https://dev.to/neon-postgres/mixtral-8x7b-what-you-need-to-know-about-mistral-ais-latest-model-l3n)
- [Mistral 7B and BAAI on Workers AI vs. OpenAI Models for RAG](https://dev.to/neon-postgres/mistral-7b-and-baai-on-workers-ai-vs-openai-models-for-rag-4pb6)
- [pgvector: 30x Faster Index Build for your Vector Embeddings](https://dev.to/neon-postgres/pgvector-30x-faster-index-build-for-your-vector-embeddings-46da)
- [Building an AI-powered ChatBot using Vercel, OpenAI, and Postgres](https://dev.to/raoufchebri/building-an-ai-powered-chatbot-using-vercel-openai-and-postgres-5cob-temp-slug-5539820)