Skip to content

Commit

Permalink
base error resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh0 committed Aug 15, 2024
1 parent f57f8af commit 81f42a7
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
15 changes: 5 additions & 10 deletions src/drd/cli/monitor/error_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ...utils.utils import print_error, print_success, print_info, print_prompt
from ...utils.loader import run_with_loader
from ...prompts.monitor_error_resolution import get_error_resolution_prompt
from ..query.file_operations import get_files_to_modify
from ..query.file_operations import get_error_files_to_modify
from ...utils.file_utils import get_file_content
import logging

Expand All @@ -21,17 +21,12 @@ def monitoring_handle_error_with_dravid(error, error_trace, monitor):
project_context = monitor.metadata_manager.get_project_context()

print_info("Identifying relevant files for error context...")
error_details = f"""
There is an error in the project. Identify ony the files related to it
error_trace: {error}
"""

files_to_check = run_with_loader(
lambda: get_files_to_modify(error_details, project_context),
explanation, files_to_check = run_with_loader(
lambda: get_error_files_to_modify(error_trace, project_context),
"Analyzing project files"
)

print_info(f"Found {len(files_to_check)} potentially relevant files.")
print_info(explanation)

file_contents = {}
for file in files_to_check:
Expand All @@ -46,7 +41,7 @@ def monitoring_handle_error_with_dravid(error, error_trace, monitor):
)

error_query = get_error_resolution_prompt(
error_trace, project_context, file_context
explanation, project_context, file_context
)

print_info("🔍 Sending error information to Dravid for analysis...")
Expand Down
19 changes: 14 additions & 5 deletions src/drd/cli/query/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@
from ...utils import print_error, print_info
from ...metadata.project_metadata import ProjectMetadataManager
from ...prompts.file_operations import get_files_to_modify_prompt, find_file_prompt
from ...utils.parser import parse_file_list_response, parse_find_file_response
from ...prompts.error_related_files_prompt import get_error_related_files
from ...utils.parser import parse_file_list_response, parse_find_file_response, parse_file_list_with_exp_response


def get_files_to_modify(query, project_context):
print("The query")
print(query)
print("======")
file_query = get_files_to_modify_prompt(query, project_context)
response = call_dravid_api_with_pagination(
file_query, include_context=True)
print(response, "response from files thing")
try:
return parse_file_list_response(response)

finally:
return []


def get_error_files_to_modify(query, project_context):
file_query = get_error_related_files(query, project_context)
response = call_dravid_api_with_pagination(
file_query, include_context=True)
try:
resp = parse_file_list_with_exp_response(response)
return resp
except Exception as e:
print_error(f"Error in get_error_files_to_modify: {str(e)}")
return ("Error occurred while processing", [])


def find_file_with_dravid(filename, project_context, max_retries=2, current_retry=0):
if os.path.exists(filename):
return filename
Expand Down
32 changes: 32 additions & 0 deletions src/drd/prompts/error_related_files_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def get_error_related_files(error_trace, project_context):
return f"""
Project Context: {project_context}
Erro Trace: {error_trace}
You're an error context identifier assistant. Your response will be sent to a final error
resolution assistant to give the code fix.
You are given a project detail and the
associated error trace. You have to guess the reason for the error and the
files which needs to be loaded for context.
Once you list the file path, the contents of those along with your explanation will be sent
to the next assistant so it can give proper code fix.
Follow these guidelines for explanation:
0. Provide brief summary of error
1. Analyze the error trace and guess the root cause.
2. Speculate possible issues that could be causing this
3. Also remember the code can be malformed at times, so include that it could be any other possibility
as well.
Note: Strictly only include files that is relevant to the error. Only the exact files.
Please respond with a list of filenames in the following XML format:
<response>
<explanation>
Summary of error: ...
</explanation>
<files>
<file>path/to/file1.ext</file>
<file>path/to/file2.ext</file>
</files>
</response>
"""
9 changes: 6 additions & 3 deletions src/drd/prompts/monitor_error_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ def get_error_resolution_prompt(error_trace, project_context, file_context=None)
return f"""
# Error Context
An error occurred while running the server:
Error trace:
Error summary:
{error_trace}
Project context:
{project_context}
File context: {file_context}
# Instructions for dravid: Error Resolution Assistant
Analyze the error above and provide steps to fix it.
Analyze the file contents and also the error above and provide steps to fix it.
Note: The error summary is just an overview.
Evaluate the actual file for any syntax error as well apart from trying to fix the actual error.
This is being run in a monitoring thread, so don't suggest server starting commands like npm run dev.
Make sure you dont try for drastic changes, just the needed and precise fix.
Your response should be in strictly XML format with no other extra messages. Use the following format:
<response>
<explanation>A brief explanation of the steps, if necessary</explanation>
Expand Down
11 changes: 11 additions & 0 deletions src/drd/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ def parse_file_list_response(response: str):
return None


def parse_file_list_with_exp_response(response: str):
try:
root = extract_and_parse_xml(response)
exp = root.find('explanation').text.strip()
files = root.findall('.//file')
return exp, [file.text.strip() for file in files if file.text]
except Exception as e:
print_error(f"Error parsing file list response: {e}")
return None


def parse_find_file_response(response: str):
try:
root = extract_and_parse_xml(response)
Expand Down

0 comments on commit 81f42a7

Please sign in to comment.