-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_code.py
More file actions
70 lines (64 loc) · 2.39 KB
/
debug_code.py
File metadata and controls
70 lines (64 loc) · 2.39 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from google import genai
from google.genai import types
from dotenv import load_dotenv
from gemini import suggest_modification_to_resolve_error
load_dotenv()
gemini = genai.Client()
class Debug:
def __init__(self,error):
self.error = error
self.model = 'gemini-3-flash-preview'
def extract_file(self):
res = gemini.models.generate_content(
model=self.model,
contents=[
f"""
You have been given with an error messages: {self.error}, your job is to return the name of the files due to which the error has been caused.
You will not return filenames of files part of libraries, you can only return the files which were written by the agent or the user.
"""
],
config=types.GenerateContentConfig(
response_mime_type='application/json',
response_schema={
"type":"object",
"properties":{
"filenames":{
"type":"ARRAY",
"items":{
"type":"STRING"
}
},
"error":{
"type":"STRING"
}
},
"required": ["filenames","error"]
}
)
)
return eval(res.text)['filenames']
def reveal_code(self,path):
code = ''
with open(path,'r') as f:
code = f.read()
return code
def suggest_changes(self,paths):
for path in paths:
code = self.reveal_code(path)
res = suggest_modification_to_resolve_error(self.error,code)
print("Here is the change suggested: Press Y or N")
print(res['code'])
inp = input("Y/N: ")
if(inp == 'Y'):
with open(path,'w') as f:
f.write(res['code'])
else:
print("Change Skipped")
return "Changes were updated as per your wish"
obj = Debug(r"""
Traceback (most recent call last):
File "C:\Anish\Computer_Science\AI\Agentic AI\Projects\dev_agent\test.py", line 1, in <module>
foiwjfoerfhorefh
NameError: name 'foiwjfoerfhorefh' is not defined
""")
#print(obj.suggest_changes(obj.extract_file()))