Skip to content

Commit ec14ed9

Browse files
hemantmalikmiguelgrinberg
authored andcommitted
Added support for using Mistral AI Large Model
1 parent dfb9266 commit ec14ed9

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

example-apps/chatbot-rag-app/README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ ES_INDEX_CHAT_HISTORY=workplace-app-docs-chat-history
5151

5252
## Connecting to LLM
5353

54-
We support three LLM providers: Azure, OpenAI and Bedrock.
55-
56-
To use one of them, you need to set the `LLM_TYPE` environment variable:
54+
We support several LLM providers. To use one of them, you need to set the `LLM_TYPE` environment variable. For example:
5755

5856
```sh
5957
export LLM_TYPE=azure
6058
```
6159

60+
The following sub-sections define the configuration requirements of each supported LLM.
61+
6262
### OpenAI
6363

6464
To use OpenAI LLM, you will need to provide the OpenAI key via `OPENAI_API_KEY` environment variable:
@@ -72,7 +72,7 @@ You can get your OpenAI key from the [OpenAI dashboard](https://platform.openai.
7272

7373
### Azure OpenAI
7474

75-
If you are using Azure LLM, you will need to set the following environment variables:
75+
If you want to use Azure LLM, you will need to set the following environment variables:
7676

7777
```sh
7878
export LLM_TYPE=azure
@@ -84,7 +84,7 @@ export OPENAI_ENGINE=... # deployment name in Azure
8484

8585
### Bedrock LLM
8686

87-
To use Bedrock LLM you need to set the following environment variables in order to AWS.
87+
To use Bedrock LLM you need to set the following environment variables in order to authenticate to AWS.
8888

8989
```sh
9090
export LLM_TYPE=bedrock
@@ -108,7 +108,7 @@ region=...
108108

109109
### Vertex AI
110110

111-
To use Vertex AI you need to set the following environment variables. More infos [here](https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm).
111+
To use Vertex AI you need to set the following environment variables. More information [here](https://python.langchain.com/docs/integrations/llms/google_vertex_ai_palm).
112112

113113
```sh
114114
export LLM_TYPE=vertex
@@ -117,6 +117,17 @@ export VERTEX_REGION=<gcp-region> # Default is us-central1
117117
export GOOGLE_APPLICATION_CREDENTIALS=<path-json-service-account>
118118
```
119119

120+
### Mistral AI
121+
122+
To use Mistral AI you need to set the following environment variables:
123+
124+
```
125+
export LLM_TYPE=mistral
126+
export MISTRAL_API_KEY=...
127+
export MISTRAL_API_ENDPOINT=... # optional
128+
export MISTRAL_MODEL=... # optional
129+
```
130+
120131
## Running the App
121132

122133
Once you have indexed data into the Elasticsearch index, there are two ways to run the app: via Docker or locally. Docker is advised for testing & production use. Locally is advised for development.

example-apps/chatbot-rag-app/api/llm_integrations.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from langchain.chat_models import ChatOpenAI, ChatVertexAI, AzureChatOpenAI, BedrockChat
1+
from langchain_community.chat_models import (
2+
ChatOpenAI,
3+
ChatVertexAI,
4+
AzureChatOpenAI,
5+
BedrockChat,
6+
)
7+
from langchain_core.messages import HumanMessage
8+
from langchain_mistralai.chat_models import ChatMistralAI
29
import os
310
import vertexai
411
import boto3
@@ -54,11 +61,27 @@ def init_bedrock(temperature):
5461
)
5562

5663

64+
def init_mistral_chat(temperature):
65+
MISTRAL_API_ENDPOINT = os.getenv("MISTRAL_API_ENDPOINT")
66+
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
67+
MISTRAL_MODEL = os.getenv("MISTRAL_MODEL")
68+
kwargs = {
69+
"mistral_api_key": MISTRAL_API_KEY,
70+
"temperature": temperature,
71+
}
72+
if MISTRAL_API_ENDPOINT:
73+
kwargs["endpoint"] = MISTRAL_API_ENDPOINT
74+
if MISTRAL_MODEL:
75+
kwargs["model"] = MISTRAL_MODEL
76+
return ChatMistralAI(**kwargs)
77+
78+
5779
MAP_LLM_TYPE_TO_CHAT_MODEL = {
5880
"azure": init_azure_chat,
5981
"bedrock": init_bedrock,
6082
"openai": init_openai_chat,
6183
"vertex": init_vertex_chat,
84+
"mistral": init_mistral_chat,
6285
}
6386

6487

example-apps/chatbot-rag-app/env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ ES_INDEX_CHAT_HISTORY=workplace-app-docs-chat-history
3434
# VERTEX_PROJECT_ID=
3535
# VERTEX_REGION=
3636
# GOOGLE_APPLICATION_CREDENTIALS=
37+
38+
# Uncomment and complete if you want to use Mistral AI
39+
# LLM_TYPE=mistral
40+
# MISTRAL_API_KEY=
41+
# MISTRAL_API_ENDPOINT=
42+
# MISTRAL_MODEL=

example-apps/chatbot-rag-app/requirements.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ grpcio-status
2020
# BedRock dependencies
2121
boto3
2222

23+
# Mistral dependencies
24+
langchain-mistralai
25+
2326
# TBD if these are still needed
2427
exceptiongroup
2528
importlib-metadata

example-apps/chatbot-rag-app/requirements.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ jsonpatch==1.33
133133
# langchain-core
134134
jsonpointer==2.4
135135
# via jsonpatch
136-
langchain==0.0.333
136+
langchain==0.1.9
137137
# via -r requirements.in
138138
langchain-core==0.1.23
139139
# via langchain-elasticsearch
140140
langchain-elasticsearch==0.1.0
141141
# via -r requirements.in
142-
langsmith==0.0.87
142+
langsmith==0.1.10
143143
# via
144144
# langchain
145145
# langchain-core
@@ -195,12 +195,12 @@ pyasn1==0.5.0
195195
# rsa
196196
pyasn1-modules==0.3.0
197197
# via google-auth
198-
pydantic==2.3.0
198+
pydantic==2.5.2
199199
# via
200200
# langchain
201201
# langchain-core
202202
# langsmith
203-
pydantic-core==2.6.3
203+
pydantic-core==2.14.5
204204
# via pydantic
205205
pyproject-hooks==1.0.0
206206
# via build
@@ -268,6 +268,8 @@ yarl==1.9.2
268268
zipp==3.17.0
269269
# via importlib-metadata
270270

271+
langchain-mistralai==0.0.5
272+
# via -r requirements.in
271273
# The following packages are considered to be unsafe in a requirements file:
272274
# pip
273275
# setuptools

0 commit comments

Comments
 (0)