Skip to content

Commit e115436

Browse files
committed
modified the developer function sothat it can be utilized in python script
1 parent ec66ed5 commit e115436

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

lazydev/develop.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ def run(args):
2828
directory= args.directory
2929
load_dotenv()
3030
api_key = os.environ.get('OPENAI_API_KEY')
31-
developer =Developer(requirement=requirement,root_dir=directory,openai_api_key=api_key)
31+
model=args.model
32+
developer =Developer(requirement=requirement,root_dir=directory,openai_api_key=api_key,model=model)
3233
developer.develop()

lazydev/modules/developer.py

+28-11
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
from .utils import Utilities
2323

2424
class Developer():
25-
def __init__(self, requirement:str,root_dir:str, openai_api_key:str):
25+
def __init__(self, requirement:str,root_dir:str, openai_api_key:str,model:str):
2626
self.requirement=requirement
2727
self.root_dir=root_dir
2828
self.api_key=openai_api_key
2929
self.files_written=[]
3030
self.brain = ChatOpenAI(
31-
model="gpt-3.5-turbo",
31+
model=model,
3232
openai_api_key=self.api_key,
3333
temperature=0.1,
3434
streaming=False
@@ -48,11 +48,23 @@ def brain_storm(self,prompt:str,step_name="prompt")->str:
4848
Utilities.write_to_file(f"{prompt}\n\n{aiMessage.content}",f"./thoughts/{step_name}.md")
4949
return aiMessage.content
5050

51-
def clear_doubts(self):
51+
def get_doubts(self):
5252
prompt=PromptBook.expand_requirements(self.requirement)
5353
doubts=self.brain_storm(prompt,'clear-doubts')
5454
doubt_list:List[str]=doubts.split("\n")
5555
doubt_list=[doubt.strip() for doubt in doubt_list if doubt.strip()!=""]
56+
return doubt_list
57+
58+
def get_clarifications(self,doubts:List[str],answers:List[str]):
59+
clarifications=""
60+
for i in range(len(doubts)):
61+
clarifications=f"{clarifications}\n\n{i+1}. {doubts[i]}\n Ans: {answers[i]}"
62+
self.clarifications=clarifications
63+
return clarifications
64+
65+
66+
def clear_doubts(self):
67+
doubt_list=self.get_doubts()
5668
print("""
5769
Hey there! 😄 It's Lazy Dev, your friendly neighborhood programmer, here to make your awesome project's dreams come true! 🎉
5870
But before I dive into coding magic, I have a few fun and important questions for you.
@@ -73,10 +85,11 @@ def clear_doubts(self):
7385
Cheers! 👨‍💻
7486
""")
7587
return doubt_list,answer_list
76-
88+
7789
def plan_project(self):
7890
prompt=PromptBook.plan_project(self.requirement,self.clarifications)
7991
plannings:str=self.brain_storm(prompt,'plan-project')
92+
self.plannings=plannings
8093
return plannings
8194

8295
def generate_folder_structure(self):
@@ -90,7 +103,7 @@ def generate_folder_structure(self):
90103
try:
91104

92105
folder_tree_str:str=self.brain_storm(prompt,"generate-filders")
93-
folder_tree:dict=json.loads(folder_tree_str)
106+
folder_tree:dict=json.loads(folder_tree_str.strip().strip("`"))
94107
break
95108
except:
96109
print("Opps messed up the json format, let me try again")
@@ -100,6 +113,7 @@ def generate_folder_structure(self):
100113
print("Sorry I was not able to create the folder structure in json correct format, check my instructions and try to refine it sothat i can understan the task better")
101114
sys.exit()
102115
self.root_folder_name, self.file_paths = Utilities.generate_files_and_folders(structure=folder_tree,root_dir=self.root_dir)
116+
return self.root_folder_name, self.file_paths
103117

104118

105119
def prioratize_files(self):
@@ -116,14 +130,16 @@ def prioratize_files(self):
116130
print("Sorry I was not able to create the file list in correct format, check my instructions and try to refine it sothat i can understan the task better")
117131
sys.exit()
118132
self.file_paths=file_paths_str.split("\n")
133+
return self.file_paths
119134

120135
def write_file_content(self,file_path):
121136
prompt=PromptBook.write_file(
122137
question=self.requirement,
123138
clarifications=self.clarifications,
124139
plan=self.plannings,
125140
files_written=self.files_written,
126-
file_path_to_write=file_path
141+
file_path_to_write=file_path,
142+
file_paths=self.file_paths
127143
)
128144
code=self.brain_storm(prompt,f'code-{file_path.split("/")[-1]}')
129145
Utilities.write_to_file(code,file_path=file_path)
@@ -135,20 +151,21 @@ def write_file_content(self,file_path):
135151
def develop(self):
136152
# clearing all doubts
137153
doubts,answers=self.clear_doubts()
138-
self.clarifications:str=""
139-
for i in range(len(doubts)):
140-
self.clarifications=f"{self.clarifications}\n\n{i+1}. {doubts[i]}\n Ans: {answers[i]}"
141-
154+
self.clarifications=self.get_clarifications(doubts=doubts,answers=answers)
142155
# planning the project
143156
print("Planning...")
144-
self.plannings=self.plan_project()
157+
self.plan_project()
158+
print(self.plannings)
159+
print("\n\n")
145160
# creating files and folders for the project
146161
print("Creating files...")
147162
self.generate_folder_structure()
148163
self.prioratize_files()
149164
self.files_written=[]
150165
for file_path in self.file_paths:
151166
file_name=file_path.split("/")[-1]
167+
if(file_name.split(".")[-1] in ["png","jpg","jpeg","bimp"]):
168+
continue
152169
print(f"\nWriting Code for :{file_name}")
153170
self.write_file_content(file_path)
154171

lazydev/modules/prompts.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ def write_file(question,clarifications:str,plan:str,files_written:List[List[str]
127127
As your response will go to an automated parser, things to keep in mind all the time:
128128
* follow the exact format provided above without fail
129129
* only write the file content, no expiation, no pretext.
130-
* always add comments at the begening, which expains what you are about to do
130+
* if the language support, add comments at steps, which expains what you are about to do, dont add comment if comment is not supported by the file type example json file
131131
* keep in mind there wont be any additional files other then the full files list given above, only use files that are mentioned in that list
132132
Begin!
133+
134+
File:{file_path_to_write}
135+
Content:
133136
"""
134137

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="lazydev",
8-
version='0.0.3',
8+
version='0.0.6',
99
packages=find_packages(),
1010
install_requires=[
1111
"langchain>=0.0.188",

0 commit comments

Comments
 (0)