添加github报错快捷按钮

This commit is contained in:
Doiiars
2025-11-05 15:51:53 +08:00
parent 9b055c6b4e
commit d0d36b1120
4 changed files with 101 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from InsightEngine import DeepSearchAgent, Settings
from config import settings
from utils.github_issues import error_with_issue_link
def main():
@@ -183,7 +184,12 @@ def execute_research(query: str, config: Settings):
except Exception as e:
import traceback
error_traceback = traceback.format_exc()
st.error(f"研究过程中发生错误: {str(e)} \n错误堆栈: {error_traceback}")
error_display = error_with_issue_link(
f"研究过程中发生错误: {str(e)}",
error_traceback,
app_name="Insight Engine Streamlit App"
)
st.error(error_display)
logger.exception(f"研究过程中发生错误: {str(e)}")

View File

@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from MediaEngine import DeepSearchAgent, Settings
from config import settings
from utils.github_issues import error_with_issue_link
def main():
@@ -180,7 +181,12 @@ def execute_research(query: str, config: Settings):
except Exception as e:
import traceback
error_traceback = traceback.format_exc()
st.error(f"研究过程中发生错误: {str(e)} \n错误堆栈: {error_traceback}")
error_display = error_with_issue_link(
f"研究过程中发生错误: {str(e)}",
error_traceback,
app_name="Media Engine Streamlit App"
)
st.error(error_display)
logger.exception(f"研究过程中发生错误: {str(e)}")

View File

@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from QueryEngine import DeepSearchAgent, Settings
from config import settings
from utils.github_issues import error_with_issue_link
def main():
@@ -174,7 +175,12 @@ def execute_research(query: str, config: Settings):
except Exception as e:
import traceback
error_traceback = traceback.format_exc()
st.error(f"研究过程中发生错误: {str(e)} \n错误堆栈: {error_traceback}")
error_display = error_with_issue_link(
f"研究过程中发生错误: {str(e)}",
error_traceback,
app_name="Query Engine Streamlit App"
)
st.error(error_display)
logger.exception(f"研究过程中发生错误: {str(e)}")

80
utils/github_issues.py Normal file
View File

@@ -0,0 +1,80 @@
"""
GitHub Issues 工具模块
提供创建 GitHub Issues URL 和显示带链接的错误信息的功能
数据模型定义位置:
- 无数据模型
"""
from datetime import datetime
from urllib.parse import quote
# GitHub 仓库信息
GITHUB_REPO = "666ghj/BettaFish"
GITHUB_ISSUES_URL = f"https://github.com/{GITHUB_REPO}/issues/new"
def create_issue_url(title: str, body: str = "") -> str:
"""
创建 GitHub Issues URL预填充标题和内容
Args:
title: Issue 标题
body: Issue 内容(可选)
Returns:
完整的 GitHub Issues URL
"""
encoded_title = quote(title)
encoded_body = quote(body) if body else ""
if encoded_body:
return f"{GITHUB_ISSUES_URL}?title={encoded_title}&body={encoded_body}"
else:
return f"{GITHUB_ISSUES_URL}?title={encoded_title}"
def error_with_issue_link(
error_message: str,
error_details: str = "",
app_name: str = "Streamlit App"
) -> str:
"""
生成带 GitHub Issues 链接的错误信息字符串
仅在通用异常处理中使用,不用于用户配置错误
Args:
error_message: 错误消息
error_details: 错误详情(可选,用于填充到 Issue body
app_name: 应用名称,用于标识错误来源
Returns:
包含错误信息和 GitHub Issues 链接的 Markdown 格式字符串
"""
issue_title = f"[{app_name}] {error_message[:50]}"
issue_body = f"## 错误信息\n\n{error_message}\n\n"
if error_details:
issue_body += f"## 错误详情\n\n```\n{error_details}\n```\n\n"
issue_body += f"## 环境信息\n\n- 应用: {app_name}\n- 时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
issue_url = create_issue_url(issue_title, issue_body)
# 使用 markdown 格式添加超链接
error_display = f"{error_message}\n\n[📝 提交错误报告]({issue_url})"
if error_details:
error_display = f"{error_message}\n\n```\n{error_details}\n```\n\n[📝 提交错误报告]({issue_url})"
return error_display
__all__ = [
"create_issue_url",
"error_with_issue_link",
"GITHUB_REPO",
"GITHUB_ISSUES_URL",
]