From 303d8034cccd71a60a6fb81f44a9e066c8253743 Mon Sep 17 00:00:00 2001 From: wwzeng1 Date: Fri, 10 May 2024 22:10:09 +0000 Subject: [PATCH 1/2] . --- sweepai/core/prompts.py | 4 +-- sweepai/logn/trace_util.py | 59 +++++++++++++++++++++++++++++------ sweepai/utils/github_utils.py | 7 +++-- 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/sweepai/core/prompts.py b/sweepai/core/prompts.py index 766b0f9a2b..13127073e9 100644 --- a/sweepai/core/prompts.py +++ b/sweepai/core/prompts.py @@ -194,7 +194,7 @@ 3. List all of the relevant files to reference while making changes, one per line.""" -fix_files_to_change_prompt = """You proposed plan a plan. However, your proposed plan has the following errors: +fix_files_to_change_prompt = """Your proposed plan has the following errors: {error_message} @@ -203,7 +203,7 @@ You must resolve these errors before proceeding. Respond in the following format: -For each error, identify what went wrong and what the fix is. Analyze the contents of the provided file path to find the correct code block that needs to be modified. Update the block with the actual code from the file, and then provide the necessary changes in the block. Follow the format: +For each error, identify what went wrong. Then identify a fix to the issue. Analyze the contents of the provided file path to find the correct code block that needs to be modified. Update the block with the actual code from the file, and then provide the necessary changes in the block. Follow the format: Error #0: Description of the error diff --git a/sweepai/logn/trace_util.py b/sweepai/logn/trace_util.py index 7eb0482a7d..2946874213 100644 --- a/sweepai/logn/trace_util.py +++ b/sweepai/logn/trace_util.py @@ -1,15 +1,54 @@ -import linecache import sys +import time +import inspect +from loguru import logger +def trace_function(func): + def wrapper(*args, **kwargs): + def trace_calls(frame, event, arg): + if event != 'call': + return None -def trace_lines(frame, event, arg): - if event == "line": - filename = frame.f_code.co_filename - if "" in filename: - lineno = frame.f_lineno - line = linecache.getline(filename, lineno) - print(f"Executing {filename}:line {lineno}:{line.rstrip()}") - return trace_lines + stack = inspect.stack() + indent = ' ' * (len(stack) - 2) + stack_info = ' -> '.join(frame.function for frame in stack[1:]) + start_time = time.time() -sys.settrace(trace_lines) + def trace_returns(frame, event, arg): + if event == 'return': + duration = time.time() - start_time + logger.info(f"{indent}Exiting function: {frame.f_code.co_name} (Stack: {stack_info}) (Duration: {duration:.4f} seconds)") + + return None + + logger.info(f"{indent}Entering function: {frame.f_code.co_name} (Stack: {stack_info})") + + return trace_returns + + sys.settrace(trace_calls) + result = func(*args, **kwargs) + sys.settrace(None) + + return result + + return wrapper + +if __name__ == '__main__': + @trace_function + def main(): + result = foo(3, 4) + print(f"Result: {result}") + + def foo(x, y): + time.sleep(0.1) # Simulating some work + return bar(x) + bar(y) + + def bar(x): + time.sleep(0.2) # Simulating some work + return x * 2 + + main() + print("Done tracing") + # shouldn't print anything + print(foo(5, 6)) \ No newline at end of file diff --git a/sweepai/utils/github_utils.py b/sweepai/utils/github_utils.py index 676b4602d9..f5066971bb 100644 --- a/sweepai/utils/github_utils.py +++ b/sweepai/utils/github_utils.py @@ -706,8 +706,11 @@ def sanitize_string_for_github(message: str): try: - g = Github(os.environ.get("GITHUB_PAT")) - CURRENT_USERNAME = g.get_user().login + if not GITHUB_BOT_USERNAME: + g = Github(os.environ.get("GITHUB_PAT")) + CURRENT_USERNAME = g.get_user().login + else: + CURRENT_USERNAME = GITHUB_BOT_USERNAME except Exception: try: slug = get_app()["slug"] From d42ea110faccdb7aeaff9394e1f17eecf95c74fe Mon Sep 17 00:00:00 2001 From: wwzeng1 Date: Sun, 12 May 2024 22:12:04 +0000 Subject: [PATCH 2/2] fix --- sweepai/config/server.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sweepai/config/server.py b/sweepai/config/server.py index 5141c20992..e2861aadae 100644 --- a/sweepai/config/server.py +++ b/sweepai/config/server.py @@ -45,15 +45,7 @@ GITHUB_APP_ID = "327588" GITHUB_BOT_USERNAME = os.environ.get("GITHUB_BOT_USERNAME") -# deprecated: left to support old logic -if not GITHUB_BOT_USERNAME: - if ENV == "prod": - GITHUB_BOT_USERNAME = "sweep-ai[bot]" - elif ENV == "dev": - GITHUB_BOT_USERNAME = "sweep-nightly[bot]" - elif ENV == "staging": - GITHUB_BOT_USERNAME = "sweep-canary[bot]" -elif not GITHUB_BOT_USERNAME.endswith("[bot]"): +if GITHUB_BOT_USERNAME and not GITHUB_BOT_USERNAME.endswith("[bot]"): GITHUB_BOT_USERNAME = GITHUB_BOT_USERNAME + "[bot]" GITHUB_LABEL_NAME = os.environ.get("GITHUB_LABEL_NAME", "sweep")