mirror of
https://github.com/arc53/DocsGPT
synced 2024-11-17 21:26:26 +00:00
commit
5883ce2685
@ -60,6 +60,7 @@ tiktoken==0.1.2
|
|||||||
tokenizers==0.13.2
|
tokenizers==0.13.2
|
||||||
tqdm==4.64.1
|
tqdm==4.64.1
|
||||||
transformers==4.26.0
|
transformers==4.26.0
|
||||||
|
typer==0.7.0
|
||||||
typing-inspect==0.8.0
|
typing-inspect==0.8.0
|
||||||
typing_extensions==4.4.0
|
typing_extensions==4.4.0
|
||||||
urllib3==1.26.14
|
urllib3==1.26.14
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import sys
|
import sys
|
||||||
import nltk
|
import nltk
|
||||||
import dotenv
|
import dotenv
|
||||||
|
import typer
|
||||||
|
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
||||||
|
|
||||||
@ -10,15 +13,36 @@ from parser.open_ai_func import call_openai_api, get_user_permission
|
|||||||
|
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
#Specify your folder HERE
|
app = typer.Typer(add_completion=False)
|
||||||
directory_to_ingest = 'inputs'
|
|
||||||
|
|
||||||
nltk.download('punkt')
|
nltk.download('punkt', quiet=True)
|
||||||
nltk.download('averaged_perceptron_tagger')
|
nltk.download('averaged_perceptron_tagger', quiet=True)
|
||||||
|
|
||||||
#Splits all files in specified folder to documents
|
#Splits all files in specified folder to documents
|
||||||
raw_docs = SimpleDirectoryReader(input_dir=directory_to_ingest).load_data()
|
@app.command()
|
||||||
|
def ingest(directory: Optional[str] = typer.Option("inputs",
|
||||||
|
help="Path to the directory for index creation."),
|
||||||
|
files: Optional[List[str]] = typer.Option(None,
|
||||||
|
help="""File paths to use (Optional; overrides directory).
|
||||||
|
E.g. --files inputs/1.md --files inputs/2.md"""),
|
||||||
|
recursive: Optional[bool] = typer.Option(True,
|
||||||
|
help="Whether to recursively search in subdirectories."),
|
||||||
|
limit: Optional[int] = typer.Option(None,
|
||||||
|
help="Maximum number of files to read."),
|
||||||
|
formats: Optional[List[str]] = typer.Option([".rst", ".md"],
|
||||||
|
help="""List of required extensions (list with .)
|
||||||
|
Currently supported: .rst, .md, .pdf, .docx, .csv, .epub"""),
|
||||||
|
exclude: Optional[bool] = typer.Option(True, help="Whether to exclude hidden files (dotfiles).")):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Creates index from specified location or files.
|
||||||
|
By default /inputs folder is used, .rst and .md are parsed.
|
||||||
|
"""
|
||||||
|
raw_docs = SimpleDirectoryReader(input_dir=directory, input_files=files, recursive=recursive,
|
||||||
|
required_exts=formats, num_files_limit=limit,
|
||||||
|
exclude_hidden=exclude).load_data()
|
||||||
raw_docs = [Document.to_langchain_format(raw_doc) for raw_doc in raw_docs]
|
raw_docs = [Document.to_langchain_format(raw_doc) for raw_doc in raw_docs]
|
||||||
|
print(raw_docs)
|
||||||
# Here we split the documents, as needed, into smaller chunks.
|
# Here we split the documents, as needed, into smaller chunks.
|
||||||
# We do this due to the context limits of the LLMs.
|
# We do this due to the context limits of the LLMs.
|
||||||
text_splitter = RecursiveCharacterTextSplitter()
|
text_splitter = RecursiveCharacterTextSplitter()
|
||||||
@ -35,3 +59,6 @@ if len(sys.argv) > 1:
|
|||||||
get_user_permission(docs)
|
get_user_permission(docs)
|
||||||
else:
|
else:
|
||||||
get_user_permission(docs)
|
get_user_permission(docs)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app()
|
||||||
|
Loading…
Reference in New Issue
Block a user