Skip to content
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

sync: sync College application branch #122

Merged
merged 6 commits into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions agentuniverse/agent/action/knowledge/reader/file/txt_reader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

from pathlib import Path
from typing import List, Optional, Dict

from agentuniverse.agent.action.knowledge.reader.reader import Reader
from agentuniverse.agent.action.knowledge.store.document import Document


class LineTxtReader(Reader):

def load_data(self, fpath: Path, ext_info: Optional[Dict] = None) -> List[Document]:
dlist = []

with open(fpath, 'r', encoding='utf-8') as file:

metadata = {"file_name": file.name}
if ext_info is not None:
metadata.update(ext_info)

for line in file:
dlist.append(Document(text=line, metadata=metadata or {}))

return dlist


class TxtReader(Reader):
"""Txt reader."""

def load_data(self, fpath: Path, ext_info: Optional[Dict] = None) -> List[Document]:

with open(fpath, 'r', encoding='utf-8') as file:

metadata = {"file_name": file.name}
if ext_info is not None:
metadata.update(ext_info)

txt = file.read()

return [Document(text=txt, metadata=metadata or {})]