Skip to content

Commit 6365904

Browse files
committed
added code and text compression.
1 parent 990c219 commit 6365904

File tree

3 files changed

+57
-18
lines changed

3 files changed

+57
-18
lines changed

lazydev/modules/developer.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ def get_clarifications(self, doubts: List[str], answers: List[str]):
6161
clarifications = ""
6262
for i in range(len(doubts)):
6363
clarifications = f"{clarifications}\n\n{i+1}. {doubts[i]}\n Ans: {answers[i]}"
64-
self.clarifications = clarifications
65-
return clarifications
64+
65+
compressed_clarrifications = self.brain_storm(
66+
PromptBook.get_compressed_text(clarifications), "compressed_clarrifications")
67+
self.clarifications = compressed_clarrifications
68+
69+
return compressed_clarrifications
6670

6771
def clear_doubts(self):
6872
doubt_list = self.get_doubts()
@@ -90,8 +94,10 @@ def clear_doubts(self):
9094
def plan_project(self):
9195
prompt = PromptBook.plan_project(self.requirement, self.clarifications)
9296
plannings: str = self.brain_storm(prompt, 'plan-project')
93-
self.plannings = plannings
94-
return plannings
97+
compressed_plan = self.brain_storm(
98+
PromptBook.get_compressed_text(plannings), "compressed_plan")
99+
self.plannings = compressed_plan
100+
return compressed_plan
95101

96102
def generate_folder_structure(self):
97103
prompt = PromptBook.design_folder_structure(
@@ -166,9 +172,12 @@ def write_file_content(self, file_path, review_iteration: int = 1):
166172
code = response
167173

168174
Utilities.write_to_file(code, file_path=file_path)
175+
# compress the code
176+
compressed_code = self.brain_storm(PromptBook.get_compressed_code(
177+
code), f'code-compressed-{file_path.split("/")[-1]}')
169178
self.files_written.append((
170179
file_path,
171-
code
180+
compressed_code
172181
))
173182

174183
def develop(self):

lazydev/modules/prompts.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class PromptBook:
66
@staticmethod
7-
def expand_requirements(question:str)->str:
7+
def expand_requirements(question: str) -> str:
88
return f"""
99
you are a senior programmer below is what your client have asked you to do:
1010
---
@@ -22,8 +22,9 @@ def expand_requirements(question:str)->str:
2222
2323
Begin!
2424
"""
25+
2526
@staticmethod
26-
def plan_project(question:str, clarification:str)->str:
27+
def plan_project(question: str, clarification: str) -> str:
2728
return f"""
2829
you are a senior programmer below is what your client have asked you to do:
2930
---
@@ -43,8 +44,9 @@ def plan_project(question:str, clarification:str)->str:
4344
* be detailed so junior developer can understand very easily
4445
Begin!
4546
"""
47+
4648
@staticmethod
47-
def design_folder_structure(question:str,plan:str,clarifications:str)->str:
49+
def design_folder_structure(question: str, plan: str, clarifications: str) -> str:
4850
return f"""
4951
you are a senior programmer below is what your client have asked you to do:
5052
---
@@ -78,9 +80,10 @@ def design_folder_structure(question:str,plan:str,clarifications:str)->str:
7880
* do not write the contents of the files that will be done by the next developer
7981
Begin!
8082
"""
83+
8184
@staticmethod
82-
def prioritise_file_list(filelist:List[str])->List[str]:
83-
list_string='\n'.join(filelist)
85+
def prioritise_file_list(filelist: List[str]) -> List[str]:
86+
list_string = '\n'.join(filelist)
8487
return f"""
8588
you are a senior programmer. you going to write a api service.
8689
below are the file list that you are going to complete in future.
@@ -94,10 +97,12 @@ def prioritise_file_list(filelist:List[str])->List[str]:
9497
* do not write any explanation
9598
Begin!
9699
"""
100+
97101
@staticmethod
98-
def write_file(question,clarifications:str,plan:str,files_written:List[List[str]], file_path_to_write:str,file_paths:List[str])->str:
99-
file_with_conent="\n\n".join([f"File:{file_path}\nContent:\n{content}" for file_path,content in files_written])
100-
all_files_list="\n".join(file_paths)
102+
def write_file(question, clarifications: str, plan: str, files_written: List[List[str]], file_path_to_write: str, file_paths: List[str]) -> str:
103+
file_with_conent = "\n\n".join(
104+
[f"File:{file_path}\nContent:\n{content}" for file_path, content in files_written])
105+
all_files_list = "\n".join(file_paths)
101106
return f"""
102107
you are a senior programmer below is what your client have asked you to do:
103108
---
@@ -127,6 +132,7 @@ def write_file(question,clarifications:str,plan:str,files_written:List[List[str]
127132
As your response will go to an automated parser, things to keep in mind all the time:
128133
* follow the exact format provided above without fail
129134
* only write the file content, no expiation, no pretext.
135+
* code should be readable.
130136
* 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
131137
* 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
132138
Begin!
@@ -135,9 +141,10 @@ def write_file(question,clarifications:str,plan:str,files_written:List[List[str]
135141
Content:
136142
"""
137143

138-
def get_code_feedback(draft:str,question,clarifications:str,plan:str,files_written:List[List[str]], file_path_to_write:str,file_paths:List[str])->str:
139-
file_with_conent="\n\n".join([f"File:{file_path}\nContent:\n{content}" for file_path,content in files_written])
140-
all_files_list="\n".join(file_paths)
144+
def get_code_feedback(draft: str, question, clarifications: str, plan: str, files_written: List[List[str]], file_path_to_write: str, file_paths: List[str]) -> str:
145+
file_with_conent = "\n\n".join(
146+
[f"File:{file_path}\nContent:\n{content}" for file_path, content in files_written])
147+
all_files_list = "\n".join(file_paths)
141148
return f"""
142149
you are a senior programmer below is what your client have asked you to do:
143150
---
@@ -177,4 +184,27 @@ def get_code_feedback(draft:str,question,clarifications:str,plan:str,files_writt
177184
* 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
178185
* 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
179186
Begin!
180-
"""
187+
"""
188+
189+
def get_compressed_code(code: str):
190+
return f"""
191+
compress the code below as best as you can, dont rename any data:
192+
```
193+
{code}
194+
```
195+
As your response will go to an automated parser, things to keep in mind all the time:
196+
* only output code and nothing else
197+
* do not rename and content of the code suck as variable names and public function names
198+
Begin!
199+
"""
200+
201+
def get_compressed_text(text: str):
202+
return f"""
203+
compress the content of the text below as best as you can:
204+
```
205+
{text}
206+
```
207+
As your response will go to an automated parser, things to keep in mind all the time:
208+
* only respond with the compressed text and nothing else
209+
Begin!
210+
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

0 commit comments

Comments
 (0)