-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (61 loc) · 1.8 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
73
74
75
76
import argparse
import logging
import pathlib
from datetime import datetime
from file_utils import read_file
from llm_utils import create_chains, get_retriever
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def parse_args() -> argparse.Namespace:
"""
Parse command line arguments.
"""
parser = argparse.ArgumentParser(
description="Automate Django app creation with task description from a text file."
)
parser.add_argument(
"-t",
"--task",
dest="task_file_path",
type=str,
help="Path to the text file containing the task description.",
)
parser.add_argument(
"-p",
"--path",
action="append",
dest="paths",
type=str,
help="Path to the reference projects.",
)
parser.add_argument(
"-o",
"--output",
dest="output_path",
type=str,
help="Path to the output directory.",
default="result",
required=False,
)
return parser.parse_args()
def generate_django_project() -> None:
"""
Generate a Django project based on the task description and reference projects.
"""
args = parse_args()
description = read_file(args.task_file_path)
if description is None:
logger.error("Task file not found.")
return None
inputs = {"user_story": description}
project_paths = [pathlib.Path(path) for path in args.paths]
retriever = get_retriever(project_paths)
root_output = pathlib.Path(args.output_path)
#
execution_output_path = (
root_output / f"{datetime.now().strftime('%Y/%m/%d/%H/%M/')}"
)
final_chain = create_chains(retriever, execution_output_path)
final_chain.invoke(inputs)
if __name__ == "__main__":
generate_django_project()