Add code snippets
for filename in os.listdir(data_dir):
if filename.endswith('.txt'):
file_path = os.path.join(data_dir, filename)
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read().strip()
if content: # Only add non-empty files
results.append({
"content": content,
"metadata": {"source": filename, "type": "text_file"}
})
except Exception as e:
print(f"Error reading file {filename}: {e}")
print(f"Loaded {len(results)} documents from {data_dir}")
return results
images
