diff --git a/hasty_coder/cli.py b/hasty_coder/cli.py index 033cde5..5b81ae6 100644 --- a/hasty_coder/cli.py +++ b/hasty_coder/cli.py @@ -4,7 +4,7 @@ import click from hasty_coder.log_utils import configure_logging -from hasty_coder.main import write_code +from hasty_coder.main import write_code, add_to_repo from hasty_coder.tasklib.generate_software_project_description import ( flesh_out_project_description, ) @@ -28,6 +28,14 @@ def make_repo_plan(description): print(project_description.as_markdown()) +@cli.command("existing-repo") +@click.argument("description") +@click.argument("repo_path") +@click.argument("file") +def make_repo(description, repo_path, file): + add_to_repo(description, repo_path, file, show_work=True) + # write_code(Path("."), description, show_work=True) + def route_cmd(): configure_logging() if len(sys.argv) == 2: diff --git a/hasty_coder/main.py b/hasty_coder/main.py index 3207b00..933e408 100644 --- a/hasty_coder/main.py +++ b/hasty_coder/main.py @@ -3,7 +3,7 @@ generate_project_description, ) from hasty_coder.tasklib.implement_software_project import implement_project_plan - +from hasty_coder.tasklib.generate_existing_project_description import generate_existing_project_description def write_code(parent_folder, description="", show_work=True): description = description.strip() @@ -16,6 +16,11 @@ def write_code(parent_folder, description="", show_work=True): project_path = implement_project_plan(program_description, parent_folder) print(f"Project '{program_description.software_name}' created at {project_path}") +def add_to_repo(description, repo_path, file): + description = description.strip() + + project_description = generate_existing_project_description(description, repo_path, file) + # if __name__ == "__main__": # import os.path diff --git a/hasty_coder/tasklib/generate_existing_project_description.py b/hasty_coder/tasklib/generate_existing_project_description.py new file mode 100644 index 0000000..2610e13 --- /dev/null +++ b/hasty_coder/tasklib/generate_existing_project_description.py @@ -0,0 +1,81 @@ +import logging +from hasty_coder.utils import LoggedOpenAI +from hasty_coder.models import SoftwareProjectDescription, SoftwareStack +import os + +logger = logging.getLogger(__name__) + +def generate_existing_project_description(description, repo_path, file): + project_description = SoftwareProjectDescription() + project_description.software_name = os.path.dirname(repo_path) + project_description.project_files = generate_project_file_structure(repo_path) + project_description.short_description = generate_project_short_description(project_description.project_files) + project_description.long_description = generate_project_long_description(project_description.project_files) + +def generate_project_file_structure(project_path): + + file_structure = {} + unorganzied_primary_programming_languages = [] + unorganzied_secondary_programming_languages = [] + for root, dirs, filenames in os.walk(project_path): + if root.startswith("./."): + continue + for filename in filenames: + if filename.startswith("."): + continue + filepath = os.path.join(root, filename) + print(filepath) + with open(filepath) as f: + file_contents = f.read() + + file_structure = file_structure | generate_file_description(filepath, file_contents) + +def generate_project_short_description(project_files): + llm = LoggedOpenAI(temperature=0.02) + + prompt = f""" + PROJECT CONTENT: + {project_files} + + + [Based on the the descriptions given in this json, where the key is the file path and the value is the description of the file's content, + let's create a short description of the whole project. The description should start with a verb in the "present simple" tense. + Write the description as paragraph that starts and ends with 3 double quotation marks.] + """ + project_description = llm(prompt, as_json=True) + +def generate_project_long_description(project_files): + llm = LoggedOpenAI(temperature=0.02) + + prompt = f""" + PROJECT CONTENT: + {project_files} + + + [Based on the the descriptions given in this json, where the key is the file path and the value is the description of the file's content, + let's create a long description of the whole project. The description should start with a verb in the "present simple" tense. + Write the description in several paragraphs that starts and ends with 3 double quotation marks.] + """ + project_description = llm(prompt, as_json=True) + +def generate_file_description(file_path, file_content): + llm = LoggedOpenAI(temperature=0.02) + + prompt = f""" +FILE PATH: +{file_path} + +FILES CONTENT: +{file_content} + + + +[Based on the file content and file path above, let's create a short description of the content of the file. The description should start with a verb in the "present simple" tense. +Write the description as a json dictionary where the key is the filepath and the value is the description.] + +FILE DESCRIPTION (json dictionary): + """ + file_description = llm(prompt, as_json=True) + structure = {file_path: file_description.get(file_path, "")} + logger.info("File Structure: %s", structure) + return structure \ No newline at end of file