From a626b84b96c7b40904960e039f72ff042148a240 Mon Sep 17 00:00:00 2001 From: joelsprunger <43421397+joelsprunger@users.noreply.github.com> Date: Tue, 22 Aug 2023 03:05:31 -0700 Subject: [PATCH] feat(backend): adds python code parsing (#1003) Adds a python code parser and invokes it in processors.py --- backend/parsers/code_python.py | 14 ++++++++++++++ backend/utils/processors.py | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 backend/parsers/code_python.py diff --git a/backend/parsers/code_python.py b/backend/parsers/code_python.py new file mode 100644 index 000000000..360601b8b --- /dev/null +++ b/backend/parsers/code_python.py @@ -0,0 +1,14 @@ +from langchain.document_loaders import PythonLoader +from models import File + +from .common import process_file + + +async def process_python(file: File, enable_summarization, brain_id, user_openai_api_key): + return await process_file( + file=file, + loader_class=PythonLoader, + enable_summarization=enable_summarization, + brain_id=brain_id, + user_openai_api_key=user_openai_api_key, + ) diff --git a/backend/utils/processors.py b/backend/utils/processors.py index cae09c105..ab3b51a5d 100644 --- a/backend/utils/processors.py +++ b/backend/utils/processors.py @@ -12,6 +12,7 @@ from parsers.pdf import process_pdf from parsers.powerpoint import process_powerpoint from parsers.txt import process_txt from parsers.xlsx import process_xlsx +from parsers.code_python import process_python file_processors = { ".txt": process_txt, @@ -34,6 +35,7 @@ file_processors = { ".xls": process_xlsx, ".epub": process_epub, ".ipynb": process_ipnyb, + ".py": process_python, }