Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt fixes #3722

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions sweepai/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions sweepai/core/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<errors>
{error_message}
Expand All @@ -203,7 +203,7 @@
You must resolve these errors before proceeding. Respond in the following format:

<error_resolutions>
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 <original_code> block with the actual code from the file, and then provide the necessary changes in the <new_code> 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 <original_code> block with the actual code from the file, and then provide the necessary changes in the <new_code> block. Follow the format:

<error_resolution>
Error #0: Description of the error
Expand Down
59 changes: 49 additions & 10 deletions sweepai/logn/trace_util.py
Original file line number Diff line number Diff line change
@@ -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))
7 changes: 5 additions & 2 deletions sweepai/utils/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading