-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (39 loc) · 1.45 KB
/
utils.py
File metadata and controls
53 lines (39 loc) · 1.45 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
from google.genai import Client
from keys import GEMINI_API_KEY
import os
client = Client(api_key = GEMINI_API_KEY)
def get_project_code_from_path(project_path):
project_code_list = []
skip_dirs = [".venv", "__pycache__"]
for root, directories, files in os.walk(project_path):
directories[:] = [name for name in directories if name not in skip_dirs]
for f in files:
if not f.endswith((".py",".js",".ts",".go",".java",".txt")):
continue
path = os.path.join(root, f)
with open(path, "r") as file:
project_code_list.append({
"file": path,
"content": file.read()
})
return project_code_list
def save_project_code_list(project_code_list):
try:
with open('./project_code/project_code_list.json', 'w') as file:
json.dump(project_code_list, file, indent = 4)
except Exception as e:
print(f"Error saving project code list: {e}")
def load_project_code_list():
try:
with open('./project_code/project_code_list.json', 'r') as file:
return json.load(file)
except Exception as e:
print(f"Error loading project code list: {e}")
return []
def invoke_gemini(gemini_model, model_prompt):
response = client.models.generate_content(
model = gemini_model,
contents = f'{model_prompt}'
).text
return response