🐛 fix(utils.py): add import_retriever function to import retriever module

 feat(utils.py): add support for importing retriever module based on retriever name
The `import_retriever` function is added to the `utils.py` module to allow importing the retriever module based on the retriever name. This function uses the `import_module` function from the `importlib` module to dynamically import the retriever module from the `langchain.retrievers` package. This enhances the modularity and extensibility of the codebase by providing a convenient way to import retrievers based on their names.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-29 11:17:30 -03:00
commit 6b893237d0

View file

@ -44,6 +44,7 @@ def import_by_type(_type: str, name: str) -> Any:
"documentloaders": import_documentloader,
"textsplitters": import_textsplitter,
"utilities": import_utility,
"retrievers": import_retriever,
}
if _type == "llms":
key = "chat" if "chat" in name.lower() else "llm"
@ -59,6 +60,11 @@ def import_chat_llm(llm: str) -> BaseChatModel:
return import_class(f"langchain.chat_models.{llm}")
def import_retriever(retriever: str) -> Any:
"""Import retriever from retriever name"""
return import_module(f"from langchain.retrievers import {retriever}")
def import_memory(memory: str) -> Any:
"""Import memory from memory name"""
return import_module(f"from langchain.memory import {memory}")