Create Langchain LLM converter to quickly supply it to Langchain's chain (#102)
* Create Langchain LLM converter to quickly supply it to Langchain's chain * Clean up
This commit is contained in:
committed by
GitHub
parent
da0ac1d69f
commit
0e30dcbb06
@@ -53,9 +53,7 @@ class LangchainAgent(BaseAgent):
|
||||
# reinit Langchain AgentExecutor
|
||||
self.agent = initialize_agent(
|
||||
langchain_plugins,
|
||||
# TODO: could cause bugs for non-langchain llms
|
||||
# related to https://github.com/Cinnamon/kotaemon/issues/73
|
||||
self.llm._obj, # type: ignore
|
||||
self.llm.to_langchain_format(),
|
||||
agent=self.AGENT_TYPE_MAP[self.agent_type],
|
||||
handle_parsing_errors=True,
|
||||
verbose=True,
|
||||
|
@@ -1,16 +1,12 @@
|
||||
from typing import Union
|
||||
|
||||
from kotaemon.base.schema import AIMessage, BaseMessage, HumanMessage, SystemMessage
|
||||
|
||||
from .base import BaseLLM
|
||||
from .branching import GatedBranchingPipeline, SimpleBranchingPipeline
|
||||
from .chats import AzureChatOpenAI, ChatLLM
|
||||
from .completions import LLM, AzureOpenAI, OpenAI
|
||||
from .linear import GatedLinearPipeline, SimpleLinearPipeline
|
||||
from .prompts import BasePromptComponent, PromptTemplate
|
||||
|
||||
BaseLLM = Union[ChatLLM, LLM]
|
||||
|
||||
|
||||
__all__ = [
|
||||
"BaseLLM",
|
||||
# chat-specific components
|
||||
|
8
knowledgehub/llms/base.py
Normal file
8
knowledgehub/llms/base.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from langchain_core.language_models.base import BaseLanguageModel
|
||||
|
||||
from kotaemon.base import BaseComponent
|
||||
|
||||
|
||||
class BaseLLM(BaseComponent):
|
||||
def to_langchain_format(self) -> BaseLanguageModel:
|
||||
raise NotImplementedError
|
@@ -3,11 +3,12 @@ from __future__ import annotations
|
||||
import logging
|
||||
|
||||
from kotaemon.base import BaseComponent
|
||||
from kotaemon.llms.base import BaseLLM
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ChatLLM(BaseComponent):
|
||||
class ChatLLM(BaseLLM):
|
||||
def flow(self):
|
||||
if self.inflow is None:
|
||||
raise ValueError("No inflow provided.")
|
||||
|
@@ -68,6 +68,9 @@ class LCChatMixin:
|
||||
logits=[],
|
||||
)
|
||||
|
||||
def to_langchain_format(self):
|
||||
return self._obj
|
||||
|
||||
def __repr__(self):
|
||||
kwargs = []
|
||||
for key, value_obj in self._kwargs.items():
|
||||
|
@@ -1,5 +1,5 @@
|
||||
from kotaemon.base import BaseComponent
|
||||
from kotaemon.llms.base import BaseLLM
|
||||
|
||||
|
||||
class LLM(BaseComponent):
|
||||
class LLM(BaseLLM):
|
||||
pass
|
||||
|
@@ -45,6 +45,9 @@ class LCCompletionMixin:
|
||||
logits=[],
|
||||
)
|
||||
|
||||
def to_langchain_format(self):
|
||||
return self._obj
|
||||
|
||||
def __repr__(self):
|
||||
kwargs = []
|
||||
for key, value_obj in self._kwargs.items():
|
||||
|
Reference in New Issue
Block a user