From 1f1a1fc009bf835b17ef2088a6ded5e9b2855c30 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 10 Jan 2024 15:37:47 -0300 Subject: [PATCH] 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. --- .../components/documentloaders/HNLoader.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/backend/langflow/components/documentloaders/HNLoader.py b/src/backend/langflow/components/documentloaders/HNLoader.py index eed9bb957..5d3cb768e 100644 --- a/src/backend/langflow/components/documentloaders/HNLoader.py +++ b/src/backend/langflow/components/documentloaders/HNLoader.py @@ -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)