-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: enables hasty-coder to read an existing project and contribu…
…te a single file based of given description.
- Loading branch information
jaydrennan
authored and
jaydrennan
committed
Dec 13, 2022
1 parent
2f600ed
commit 4a5f625
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
hasty_coder/tasklib/generate_existing_project_description.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import logging | ||
from hasty_coder.utils import LoggedOpenAI | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
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 short descriptions of the content of the file. The descriptions should start with a verb in the "present simple" tense. | ||
Write the descriptions 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 | ||
|
||
|
||
def generate_project_file_structure(project_path): | ||
llm = LoggedOpenAI(temperature=0.02) | ||
|
||
file_structure = {} | ||
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) |