feat: add support for Gemini, Claude through Langchain (#225) (bump:patch)

This commit is contained in:
Tuan Anh Nguyen Dang (Tadashi_Cin)
2024-09-05 21:58:20 +07:00
committed by GitHub
parent 8be8a4a9d0
commit 05245f501c
6 changed files with 71 additions and 2 deletions

View File

@@ -10,6 +10,7 @@ from .chats import (
LCAnthropicChat,
LCAzureChatOpenAI,
LCChatOpenAI,
LCGeminiChat,
LlamaCppChat,
)
from .completions import LLM, AzureOpenAI, LlamaCpp, OpenAI
@@ -29,6 +30,7 @@ __all__ = [
"AzureChatOpenAI",
"ChatOpenAI",
"LCAnthropicChat",
"LCGeminiChat",
"LCAzureChatOpenAI",
"LCChatOpenAI",
"LlamaCppChat",

View File

@@ -5,6 +5,7 @@ from .langchain_based import (
LCAzureChatOpenAI,
LCChatMixin,
LCChatOpenAI,
LCGeminiChat,
)
from .llamacpp import LlamaCppChat
from .openai import AzureChatOpenAI, ChatOpenAI
@@ -16,6 +17,7 @@ __all__ = [
"EndpointChatLLM",
"ChatOpenAI",
"LCAnthropicChat",
"LCGeminiChat",
"LCChatOpenAI",
"LCAzureChatOpenAI",
"LCChatMixin",

View File

@@ -245,3 +245,27 @@ class LCAnthropicChat(LCChatMixin, ChatLLM): # type: ignore
raise ImportError("Please install langchain-anthropic")
return ChatAnthropic
class LCGeminiChat(LCChatMixin, ChatLLM): # type: ignore
def __init__(
self,
api_key: str | None = None,
model_name: str | None = None,
temperature: float = 0.7,
**params,
):
super().__init__(
google_api_key=api_key,
model=model_name,
temperature=temperature,
**params,
)
def _get_lc_class(self):
try:
from langchain_google_genai import ChatGoogleGenerativeAI
except ImportError:
raise ImportError("Please install langchain-google-genai")
return ChatGoogleGenerativeAI

View File

@@ -30,6 +30,8 @@ dependencies = [
"langchain>=0.1.16,<0.2.0",
"langchain-community>=0.0.34,<0.1.0",
"langchain-openai>=0.1.4,<0.2.0",
"langchain-anthropic",
"langchain-google-genai",
"llama-hub>=0.0.79,<0.1.0",
"llama-index>=0.10.40,<0.11.0",
"llama-index-vector-stores-chroma>=0.1.9",

View File

@@ -54,9 +54,21 @@ class LLMManager:
self._default = item.name
def load_vendors(self):
from kotaemon.llms import AzureChatOpenAI, ChatOpenAI, LlamaCppChat
from kotaemon.llms import (
AzureChatOpenAI,
ChatOpenAI,
LCAnthropicChat,
LCGeminiChat,
LlamaCppChat,
)
self._vendors = [ChatOpenAI, AzureChatOpenAI, LlamaCppChat]
self._vendors = [
ChatOpenAI,
AzureChatOpenAI,
LCAnthropicChat,
LCGeminiChat,
LlamaCppChat,
]
for extra_vendor in getattr(flowsettings, "KH_LLM_EXTRA_VENDORS", []):
self._vendors.append(import_dotted_string(extra_vendor, safe=False))