forked from iyaja/llama-fs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
72 lines (57 loc) · 2.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import json
import argparse
import pathlib
from groq import Groq
from llama_index.core import SimpleDirectoryReader
import colorama
import pathlib
from pathlib import Path
from termcolor import colored
from asciitree import LeftAligned
from asciitree.drawing import BoxStyle, BOX_LIGHT
from src.loader import get_dir_summaries
from src.tree_generator import create_file_tree
import asyncio
import click
colorama.init() # Initializes colorama to make it work on Windows as well
@click.command()
@click.argument("src_path", type=click.Path(exists=True))
@click.argument("dst_path", type=click.Path())
@click.option("--auto-yes", is_flag=True, help="Automatically say yes to all prompts")
def main(src_path, dst_path, auto_yes=False):
os.environ["GROQ_API_KEY"] = (
"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"
)
summaries = asyncio.run(get_dir_summaries(src_path))
# Get file tree
files = create_file_tree(summaries)
BASE_DIR = pathlib.Path(dst_path)
BASE_DIR.mkdir(exist_ok=True)
# Recursively create dictionary from file paths
tree = {}
for file in files:
parts = Path(file["dst_path"]).parts
current = tree
for part in parts:
current = current.setdefault(part, {})
tree = {dst_path: tree}
tr = LeftAligned(draw=BoxStyle(gfx=BOX_LIGHT, horiz_len=1))
print(tr(tree))
# Prepend base path to dst_path
for file in files:
file["dst_path"] = os.path.join(src_path, file["dst_path"])
file["summary"] = summaries[files.index(file)]["summary"]
if not auto_yes and not click.confirm(
"Proceed with directory structure?", default=True
):
click.echo("Operation cancelled.")
return
for file in files:
file["path"] = pathlib.Path(file["dst_path"])
# Create file in specified base directory
(BASE_DIR / file["path"]).parent.mkdir(parents=True, exist_ok=True)
with open(BASE_DIR / file["path"], "w") as f:
f.write("")
if __name__ == "__main__":
main()