feat: add options for Mistral AI (#707) #none
* add Mistral AI emb AI embedding vendor, types * add mistral env setting to example * add mistral LLM option * chore: fix default embedding back to normal * fix: comfort CI --------- Co-authored-by: Tadashi <tadashi@cinnamon.is>
This commit is contained in:
parent
9b05693e4f
commit
c33bedca9e
|
@ -16,6 +16,9 @@ AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=text-embedding-ada-002
|
|||
# settings for Cohere
|
||||
COHERE_API_KEY=<COHERE_API_KEY>
|
||||
|
||||
# settings for Mistral
|
||||
# MISTRAL_API_KEY=placeholder
|
||||
|
||||
# settings for local models
|
||||
LOCAL_MODEL=qwen2.5:7b
|
||||
LOCAL_MODEL_EMBEDDINGS=nomic-embed-text
|
||||
|
|
|
@ -243,6 +243,15 @@ KH_LLMS["cohere"] = {
|
|||
},
|
||||
"default": False,
|
||||
}
|
||||
KH_LLMS["mistral"] = {
|
||||
"spec": {
|
||||
"__type__": "kotaemon.llms.ChatOpenAI",
|
||||
"base_url": "https://api.mistral.ai/v1",
|
||||
"model": "ministral-8b-latest",
|
||||
"api_key": config("MISTRAL_API_KEY", default="your-key"),
|
||||
},
|
||||
"default": False,
|
||||
}
|
||||
|
||||
# additional embeddings configurations
|
||||
KH_EMBEDDINGS["cohere"] = {
|
||||
|
@ -262,6 +271,14 @@ KH_EMBEDDINGS["google"] = {
|
|||
},
|
||||
"default": not IS_OPENAI_DEFAULT,
|
||||
}
|
||||
KH_EMBEDDINGS["mistral"] = {
|
||||
"spec": {
|
||||
"__type__": "kotaemon.embeddings.LCMistralEmbeddings",
|
||||
"model": "mistral-embed",
|
||||
"api_key": config("MISTRAL_API_KEY", default="your-key"),
|
||||
},
|
||||
"default": False,
|
||||
}
|
||||
# KH_EMBEDDINGS["huggingface"] = {
|
||||
# "spec": {
|
||||
# "__type__": "kotaemon.embeddings.LCHuggingFaceEmbeddings",
|
||||
|
|
|
@ -6,6 +6,7 @@ from .langchain_based import (
|
|||
LCCohereEmbeddings,
|
||||
LCGoogleEmbeddings,
|
||||
LCHuggingFaceEmbeddings,
|
||||
LCMistralEmbeddings,
|
||||
LCOpenAIEmbeddings,
|
||||
)
|
||||
from .openai import AzureOpenAIEmbeddings, OpenAIEmbeddings
|
||||
|
@ -20,6 +21,7 @@ __all__ = [
|
|||
"LCCohereEmbeddings",
|
||||
"LCHuggingFaceEmbeddings",
|
||||
"LCGoogleEmbeddings",
|
||||
"LCMistralEmbeddings",
|
||||
"OpenAIEmbeddings",
|
||||
"AzureOpenAIEmbeddings",
|
||||
"FastEmbedEmbeddings",
|
||||
|
|
|
@ -254,3 +254,40 @@ class LCGoogleEmbeddings(LCEmbeddingMixin, BaseEmbeddings):
|
|||
raise ImportError("Please install langchain-google-genai")
|
||||
|
||||
return GoogleGenerativeAIEmbeddings
|
||||
|
||||
|
||||
class LCMistralEmbeddings(LCEmbeddingMixin, BaseEmbeddings):
|
||||
"""Wrapper around LangChain's MistralAI embedding, focusing on key parameters"""
|
||||
|
||||
api_key: str = Param(
|
||||
help="API key (https://console.mistral.ai/api-keys)",
|
||||
default=None,
|
||||
required=True,
|
||||
)
|
||||
model: str = Param(
|
||||
help="Model name to use ('mistral-embed')",
|
||||
default="mistral-embed",
|
||||
required=True,
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
model: str = "mistral-embed",
|
||||
api_key: Optional[str] = None,
|
||||
**params,
|
||||
):
|
||||
super().__init__(
|
||||
model=model,
|
||||
api_key=api_key,
|
||||
**params,
|
||||
)
|
||||
|
||||
def _get_lc_class(self):
|
||||
try:
|
||||
from langchain_mistralai import MistralAIEmbeddings
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Please install langchain_mistralai: "
|
||||
"`pip install -U langchain_mistralai`"
|
||||
)
|
||||
return MistralAIEmbeddings
|
||||
|
|
|
@ -36,6 +36,7 @@ dependencies = [
|
|||
"langchain-google-genai>=1.0.3,<2.0.0",
|
||||
"langchain-anthropic",
|
||||
"langchain-ollama",
|
||||
"langchain-mistralai",
|
||||
"langchain-cohere>=0.2.4,<0.3.0",
|
||||
"llama-hub>=0.0.79,<0.1.0",
|
||||
"llama-index>=0.10.40,<0.11.0",
|
||||
|
|
|
@ -59,6 +59,7 @@ class EmbeddingManager:
|
|||
LCCohereEmbeddings,
|
||||
LCGoogleEmbeddings,
|
||||
LCHuggingFaceEmbeddings,
|
||||
LCMistralEmbeddings,
|
||||
OpenAIEmbeddings,
|
||||
TeiEndpointEmbeddings,
|
||||
)
|
||||
|
@ -70,6 +71,7 @@ class EmbeddingManager:
|
|||
LCCohereEmbeddings,
|
||||
LCHuggingFaceEmbeddings,
|
||||
LCGoogleEmbeddings,
|
||||
LCMistralEmbeddings,
|
||||
TeiEndpointEmbeddings,
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user