Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: enables hasty-coder to read an existing project and contribu… #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion hasty_coder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion hasty_coder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
81 changes: 81 additions & 0 deletions hasty_coder/tasklib/generate_existing_project_description.py
Original file line number Diff line number Diff line change
@@ -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