-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error building node TextLoader #2136
Comments
To resolve the error encountered while building the node
Here is an example of how you might use these functions: from fastapi import UploadFile
from pathlib import Path
from langflow.base.data.utils import TEXT_FILE_TYPES, parse_text_file_to_record
from langflow.custom import CustomComponent
from langflow.schema import Record
# Example usage of save_uploaded_file
def handle_file_upload(file: UploadFile, folder_name: str):
try:
file_path = save_uploaded_file(file, folder_name)
print(f"File saved to {file_path}")
except Exception as e:
print(f"Error saving file: {e}")
# Example usage of save_binary_file
def handle_binary_file(content: str, file_name: str, accepted_types: list[str]):
try:
file_path = save_binary_file(content, file_name, accepted_types)
print(f"Binary file saved to {file_path}")
except Exception as e:
print(f"Error saving binary file: {e}")
# Ensure the cache directory is created
create_cache_folder(lambda: None)()
# Example call to handle file upload
# handle_file_upload(uploaded_file, "my_folder")
# Example call to handle binary file
# handle_binary_file("base64_content", "example.dill", [".dill"])
# Example usage of FileComponent to load a file
class FileComponent(CustomComponent):
display_name = "File"
description = "A generic file loader."
icon = "file-text"
def build_config(self) -> Dict[str, Any]:
return {
"path": {
"display_name": "Path",
"field_type": "file",
"file_types": TEXT_FILE_TYPES,
"info": f"Supported file types: {', '.join(TEXT_FILE_TYPES)}",
},
"silent_errors": {
"display_name": "Silent Errors",
"advanced": True,
"info": "If true, errors will not raise an exception.",
},
}
def load_file(self, path: str, silent_errors: bool = False) -> Record:
resolved_path = self.resolve_path(path)
path_obj = Path(resolved_path)
extension = path_obj.suffix[1:].lower()
if extension == "doc":
raise ValueError("doc files are not supported. Please save as .docx")
if extension not in TEXT_FILE_TYPES:
raise ValueError(f"Unsupported file type: {extension}")
record = parse_text_file_to_record(resolved_path, silent_errors)
self.status = record if record else "No data"
return record or Record()
def build(
self,
path: str,
silent_errors: bool = False,
) -> Record:
record = self.load_file(path, silent_errors)
self.status = record
return record By following these steps and using the provided functions, you should be able to resolve the error related to loading the specific file from the cache directory [1][2]. |
Duration: 306 ms
Error building node TextLoader(ID:TextLoader-UilLV): Error loading C:\Users\施建樺\AppData\Local\langflow\langflow\Cache\54b89cd5-fbea-4ed8-9a5a-b3074bb276f0\c424c4864d77c6e969d1c6969a58f5efc38071c1b73626c7f4e8d615d4e93fc5.txt
The text was updated successfully, but these errors were encountered: