Refactor HNLoaderComponent to use HNLoader instead of BaseLoader

This commit refactors the HNLoaderComponent in the langflow backend to use the HNLoader class instead of the BaseLoader class. The HNLoader class is imported from the langchain_community.document_loaders.hn module. The commit also updates the return type annotation of the `load` method in HNLoaderComponent to HNLoader. Additionally, the metadata field in the component's configuration schema is updated to have a field_type of "dict". This change improves the specificity and functionality of the HNLoaderComponent.
This commit is contained in:
anovazzi1 2024-01-10 15:37:47 -03:00
commit 1f1a1fc009

View file

@ -1,7 +1,8 @@
from langchain import CustomComponent
from langchain.document_loaders import BaseLoader
from langflow import CustomComponent
from typing import Optional, Dict
from langchain_community.document_loaders.hn import HNLoader
class HNLoaderComponent(CustomComponent):
display_name = "HNLoader"
@ -11,8 +12,9 @@ class HNLoaderComponent(CustomComponent):
return {
"metadata": {
"display_name": "Metadata",
"default": {},
"required": False
"value": {},
"required": False,
"field_type": "dict"
},
"web_path": {
"display_name": "Web Page",
@ -24,8 +26,8 @@ class HNLoaderComponent(CustomComponent):
self,
web_path: str,
metadata: Optional[Dict] = None,
) -> BaseLoader:
) -> HNLoader:
# Assuming that there's a specific loader for Hacker News
# as BaseLoader does not take a web_path argument
# as HNloader does not take a web_path argument
# The HackerNewsLoader needs to be defined somewhere in the actual implementation
return HackerNewsLoader(metadata=metadata, web_path=web_path)
return HNLoader(metadata=metadata, web_path=web_path)