Spaces:
Sleeping
Sleeping
Commit ·
450bb0a
1
Parent(s): 501e2ad
Add dynamic detailed error messages in the UI
Browse files- app.py +16 -8
- tools/github_tools.py +3 -3
- tools/utils.py +4 -4
app.py
CHANGED
|
@@ -3,17 +3,25 @@ from agent.core import run_agent
|
|
| 3 |
|
| 4 |
async def respond_to_issue(issue_url, branch_name):
|
| 5 |
logs = []
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
return [{"role": "assistant", "content": final_message}]
|
| 17 |
|
| 18 |
theme = gr.themes.Soft(
|
| 19 |
primary_hue="orange",
|
|
|
|
| 3 |
|
| 4 |
async def respond_to_issue(issue_url, branch_name):
|
| 5 |
logs = []
|
| 6 |
+
try:
|
| 7 |
+
async for log_msg in run_agent(issue_url, branch_name):
|
| 8 |
+
logs.append(str(log_msg))
|
| 9 |
|
| 10 |
+
collapsible_logs = "<details><summary>Click to view agent's used tool logs</summary>\n\n"
|
| 11 |
+
for log in logs:
|
| 12 |
+
collapsible_logs += f"- {log}\n"
|
| 13 |
+
collapsible_logs += "</details>\n\n"
|
| 14 |
|
| 15 |
+
final_message = f"{collapsible_logs} Agent has successfully processed the issue and posted an update in the comments. Check the GitHub issue for updates."
|
| 16 |
+
|
| 17 |
+
return [{"role": "assistant", "content": final_message}]
|
| 18 |
+
except Exception as e:
|
| 19 |
+
error_message = str(e).lower()
|
| 20 |
+
if "429" in error_message:
|
| 21 |
+
return [{"role": "assistant", "content": f"🚫 Too many requests at the moment. Please try again after some time."}]
|
| 22 |
+
else:
|
| 23 |
+
return [{"role": "assistant", "content": f"🚫 Error: {str(e)}"}]
|
| 24 |
|
|
|
|
| 25 |
|
| 26 |
theme = gr.themes.Soft(
|
| 27 |
primary_hue="orange",
|
tools/github_tools.py
CHANGED
|
@@ -10,7 +10,7 @@ def fetch_github_issue(issue_url):
|
|
| 10 |
issue_num = path_parts[3]
|
| 11 |
return owner, repo, issue_num
|
| 12 |
else:
|
| 13 |
-
raise ValueError("Invalid GitHub Issue URL")
|
| 14 |
|
| 15 |
|
| 16 |
def get_issue_details(owner, repo, issue_num):
|
|
@@ -25,7 +25,7 @@ def get_issue_details(owner, repo, issue_num):
|
|
| 25 |
if response.status_code == 200:
|
| 26 |
return response.json().get("body")
|
| 27 |
else:
|
| 28 |
-
raise Exception(f"Failed to fetch issue: {response.status_code}
|
| 29 |
|
| 30 |
|
| 31 |
def post_comment(owner, repo, issue_num, comment_body):
|
|
@@ -41,4 +41,4 @@ def post_comment(owner, repo, issue_num, comment_body):
|
|
| 41 |
if response.status_code == 201:
|
| 42 |
return response.json()
|
| 43 |
else:
|
| 44 |
-
raise Exception(f"Failed to post comment: {response.status_code}
|
|
|
|
| 10 |
issue_num = path_parts[3]
|
| 11 |
return owner, repo, issue_num
|
| 12 |
else:
|
| 13 |
+
raise ValueError("Invalid GitHub Issue URL. Please provide a valid URL and try again.")
|
| 14 |
|
| 15 |
|
| 16 |
def get_issue_details(owner, repo, issue_num):
|
|
|
|
| 25 |
if response.status_code == 200:
|
| 26 |
return response.json().get("body")
|
| 27 |
else:
|
| 28 |
+
raise Exception(f"Failed to fetch issue: {response.status_code}. The issue either doesn't exist or the URL is incorrect.")
|
| 29 |
|
| 30 |
|
| 31 |
def post_comment(owner, repo, issue_num, comment_body):
|
|
|
|
| 41 |
if response.status_code == 201:
|
| 42 |
return response.json()
|
| 43 |
else:
|
| 44 |
+
raise Exception(f"Failed to post comment: {response.status_code}. The issue either doesn't exist or the URL is incorrect.")
|
tools/utils.py
CHANGED
|
@@ -68,8 +68,8 @@ def get_installation_id(owner, repo):
|
|
| 68 |
data = response.json()
|
| 69 |
return data["id"]
|
| 70 |
else:
|
| 71 |
-
raise Exception(f"Failed to get installation ID for {owner}/{repo}: {response.status_code}
|
| 72 |
-
|
| 73 |
|
| 74 |
def get_installation_token(installation_id):
|
| 75 |
"""Return a valid installation token, fetch new if expired or missing."""
|
|
@@ -81,7 +81,7 @@ def get_installation_token(installation_id):
|
|
| 81 |
url = f"https://api.github.com/app/installations/{installation_id}/access_tokens"
|
| 82 |
response = github_request("POST", url)
|
| 83 |
if response.status_code != 201:
|
| 84 |
-
raise Exception(f"Failed to fetch installation token: {response.status_code}
|
| 85 |
|
| 86 |
token_data = response.json()
|
| 87 |
token = token_data["token"]
|
|
@@ -106,7 +106,7 @@ async def fetch_repo_files(owner: str, repo: str, ref: str = "main") -> List[str
|
|
| 106 |
|
| 107 |
response = await asyncio.to_thread(github_request, "GET", url, headers=headers)
|
| 108 |
if response.status_code != 200:
|
| 109 |
-
raise Exception(f"Failed to
|
| 110 |
|
| 111 |
tree = response.json().get("tree", [])
|
| 112 |
file_paths = [item["path"] for item in tree if item["type"] == "blob"]
|
|
|
|
| 68 |
data = response.json()
|
| 69 |
return data["id"]
|
| 70 |
else:
|
| 71 |
+
raise Exception(f"Failed to get installation ID for {owner}/{repo}: {response.status_code}. Please [install the GitHub App](https://github.com/apps/opensorus) on this repository before using the agent.")
|
| 72 |
+
|
| 73 |
|
| 74 |
def get_installation_token(installation_id):
|
| 75 |
"""Return a valid installation token, fetch new if expired or missing."""
|
|
|
|
| 81 |
url = f"https://api.github.com/app/installations/{installation_id}/access_tokens"
|
| 82 |
response = github_request("POST", url)
|
| 83 |
if response.status_code != 201:
|
| 84 |
+
raise Exception(f"Failed to fetch installation token: {response.status_code}. Please [install the GitHub App](https://github.com/apps/opensorus) on this repository before using the agent.")
|
| 85 |
|
| 86 |
token_data = response.json()
|
| 87 |
token = token_data["token"]
|
|
|
|
| 106 |
|
| 107 |
response = await asyncio.to_thread(github_request, "GET", url, headers=headers)
|
| 108 |
if response.status_code != 200:
|
| 109 |
+
raise Exception(f"Failed to fetch repository files: {response.status_code}. Please ensure the branch name is correct and files exist in this branch.")
|
| 110 |
|
| 111 |
tree = response.json().get("tree", [])
|
| 112 |
file_paths = [item["path"] for item in tree if item["type"] == "blob"]
|