代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/Auto-GPT 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import argparse
import logging
from autogpt.commands.file_operations import ingest_file, search_files
from autogpt.config import Config
from autogpt.memory import get_memory
cfg = Config()
def configure_logging():
logging.basicConfig(
filename="log-ingestion.txt",
filemode="a",
format="%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s",
datefmt="%H:%M:%S",
level=logging.DEBUG,
)
return logging.getLogger("AutoGPT-Ingestion")
def ingest_directory(directory, memory, args):
"""
Ingest all files in a directory by calling the ingest_file function for each file.
:param directory: The directory containing the files to ingest
:param memory: An object with an add() method to store the chunks in memory
"""
try:
files = search_files(directory)
for file in files:
ingest_file(file, memory, args.max_length, args.overlap)
except Exception as e:
print(f"Error while ingesting directory '{directory}': {str(e)}")
def main() -> None:
logger = configure_logging()
parser = argparse.ArgumentParser(
description="Ingest a file or a directory with multiple files into memory. "
"Make sure to set your .env before running this script."
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--file", type=str, help="The file to ingest.")
group.add_argument(
"--dir", type=str, help="The directory containing the files to ingest."
)
parser.add_argument(
"--init",
action="store_true",
help="Init the memory and wipe its content (default: False)",
default=False,
)
parser.add_argument(
"--overlap",
type=int,
help="The overlap size between chunks when ingesting files (default: 200)",
default=200,
)
parser.add_argument(
"--max_length",
type=int,
help="The max_length of each chunk when ingesting files (default: 4000)",
default=4000,
)
args = parser.parse_args()
# Initialize memory
memory = get_memory(cfg, init=args.init)
print("Using memory of type: " + memory.__class__.__name__)
if args.file:
try:
ingest_file(args.file, memory, args.max_length, args.overlap)
print(f"File '{args.file}' ingested successfully.")
except Exception as e:
logger.error(f"Error while ingesting file '{args.file}': {str(e)}")
print(f"Error while ingesting file '{args.file}': {str(e)}")
elif args.dir:
try:
ingest_directory(args.dir, memory, args)
print(f"Directory '{args.dir}' ingested successfully.")
except Exception as e:
logger.error(f"Error while ingesting directory '{args.dir}': {str(e)}")
print(f"Error while ingesting directory '{args.dir}': {str(e)}")
else:
print(
"Please provide either a file path (--file) or a directory name (--dir)"
" inside the auto_gpt_workspace directory as input."
)
if __name__ == "__main__":
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。