Add FileComponent to load a file
This commit is contained in:
parent
81f0bdd50b
commit
56af9280b5
1 changed files with 28 additions and 0 deletions
28
src/backend/langflow/components/data/File.py
Normal file
28
src/backend/langflow/components/data/File.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from typing import Any, Dict, Optional
|
||||
|
||||
from langflow import CustomComponent
|
||||
from langflow.base.data.utils import parse_file_to_record
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class FileComponent(CustomComponent):
|
||||
display_name = "File"
|
||||
description = "Load a file."
|
||||
|
||||
def build_config(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"path": {"display_name": "Path"},
|
||||
"silent_errors": {
|
||||
"display_name": "Silent Errors",
|
||||
"advanced": True,
|
||||
"info": "If true, errors will not raise an exception.",
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
path: str,
|
||||
silent_errors: bool = False,
|
||||
) -> Optional[Record]:
|
||||
resolved_path = self.resolve_path(path)
|
||||
return parse_file_to_record(resolved_path, silent_errors)
|
||||
Loading…
Add table
Add a link
Reference in a new issue