-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_gen.py
More file actions
35 lines (28 loc) · 1.07 KB
/
code_gen.py
File metadata and controls
35 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from gemini import modify_code
def install_packages(packages,language,folder_name,prerequisite_commands=''):
try:
for package in packages:
if language == "javascript":
os.system(f"cd {folder_name} && npm install {package}")
elif language == "python":
os.system(f"cd {folder_name} && pip install {package}")
for command in prerequisite_commands:
os.system(f"cd {folder_name} && {command}")
return True
except Exception as e:
print(e)
return False
class ModifyCode:
def __init__(self,language,instruction):
self.language = language
self.instruction = instruction
def modify_code_gen(self,code):
try:
res = modify_code(code,self.language,self.instruction)
if res['additional_tasks']:
res = modify_code(res['code'],self.language,res['additional_tasks'])
return res['code']
except Exception as e:
print(e)
return False