Doiiars
Committed by GitHub

Merge pull request #128 from DoiiarX/github-issue-helper

添加github报错快捷按钮
@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) @@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
29 29
30 from InsightEngine import DeepSearchAgent, Settings 30 from InsightEngine import DeepSearchAgent, Settings
31 from config import settings 31 from config import settings
  32 +from utils.github_issues import error_with_issue_link
32 33
33 34
34 def main(): 35 def main():
@@ -183,7 +184,12 @@ def execute_research(query: str, config: Settings): @@ -183,7 +184,12 @@ def execute_research(query: str, config: Settings):
183 except Exception as e: 184 except Exception as e:
184 import traceback 185 import traceback
185 error_traceback = traceback.format_exc() 186 error_traceback = traceback.format_exc()
186 - st.error(f"研究过程中发生错误: {str(e)} \n错误堆栈: {error_traceback}") 187 + error_display = error_with_issue_link(
  188 + f"研究过程中发生错误: {str(e)}",
  189 + error_traceback,
  190 + app_name="Insight Engine Streamlit App"
  191 + )
  192 + st.error(error_display)
187 logger.exception(f"研究过程中发生错误: {str(e)}") 193 logger.exception(f"研究过程中发生错误: {str(e)}")
188 194
189 195
@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) @@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
29 29
30 from MediaEngine import DeepSearchAgent, Settings 30 from MediaEngine import DeepSearchAgent, Settings
31 from config import settings 31 from config import settings
  32 +from utils.github_issues import error_with_issue_link
32 33
33 34
34 def main(): 35 def main():
@@ -180,7 +181,12 @@ def execute_research(query: str, config: Settings): @@ -180,7 +181,12 @@ def execute_research(query: str, config: Settings):
180 except Exception as e: 181 except Exception as e:
181 import traceback 182 import traceback
182 error_traceback = traceback.format_exc() 183 error_traceback = traceback.format_exc()
183 - st.error(f"研究过程中发生错误: {str(e)} \n错误堆栈: {error_traceback}") 184 + error_display = error_with_issue_link(
  185 + f"研究过程中发生错误: {str(e)}",
  186 + error_traceback,
  187 + app_name="Media Engine Streamlit App"
  188 + )
  189 + st.error(error_display)
184 logger.exception(f"研究过程中发生错误: {str(e)}") 190 logger.exception(f"研究过程中发生错误: {str(e)}")
185 191
186 192
@@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) @@ -29,6 +29,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
29 29
30 from QueryEngine import DeepSearchAgent, Settings 30 from QueryEngine import DeepSearchAgent, Settings
31 from config import settings 31 from config import settings
  32 +from utils.github_issues import error_with_issue_link
32 33
33 34
34 def main(): 35 def main():
@@ -174,7 +175,12 @@ def execute_research(query: str, config: Settings): @@ -174,7 +175,12 @@ def execute_research(query: str, config: Settings):
174 except Exception as e: 175 except Exception as e:
175 import traceback 176 import traceback
176 error_traceback = traceback.format_exc() 177 error_traceback = traceback.format_exc()
177 - st.error(f"研究过程中发生错误: {str(e)} \n错误堆栈: {error_traceback}") 178 + error_display = error_with_issue_link(
  179 + f"研究过程中发生错误: {str(e)}",
  180 + error_traceback,
  181 + app_name="Query Engine Streamlit App"
  182 + )
  183 + st.error(error_display)
178 logger.exception(f"研究过程中发生错误: {str(e)}") 184 logger.exception(f"研究过程中发生错误: {str(e)}")
179 185
180 186
  1 +"""
  2 +GitHub Issues 工具模块
  3 +
  4 +提供创建 GitHub Issues URL 和显示带链接的错误信息的功能
  5 +数据模型定义位置:
  6 +- 无数据模型
  7 +"""
  8 +
  9 +from datetime import datetime
  10 +from urllib.parse import quote
  11 +
  12 +# GitHub 仓库信息
  13 +GITHUB_REPO = "666ghj/BettaFish"
  14 +GITHUB_ISSUES_URL = f"https://github.com/{GITHUB_REPO}/issues/new"
  15 +
  16 +
  17 +def create_issue_url(title: str, body: str = "") -> str:
  18 + """
  19 + 创建 GitHub Issues URL,预填充标题和内容
  20 +
  21 + Args:
  22 + title: Issue 标题
  23 + body: Issue 内容(可选)
  24 +
  25 + Returns:
  26 + 完整的 GitHub Issues URL
  27 + """
  28 + encoded_title = quote(title)
  29 + encoded_body = quote(body) if body else ""
  30 +
  31 + if encoded_body:
  32 + return f"{GITHUB_ISSUES_URL}?title={encoded_title}&body={encoded_body}"
  33 + else:
  34 + return f"{GITHUB_ISSUES_URL}?title={encoded_title}"
  35 +
  36 +
  37 +def error_with_issue_link(
  38 + error_message: str,
  39 + error_details: str = "",
  40 + app_name: str = "Streamlit App"
  41 +) -> str:
  42 + """
  43 + 生成带 GitHub Issues 链接的错误信息字符串
  44 +
  45 + 仅在通用异常处理中使用,不用于用户配置错误
  46 +
  47 + Args:
  48 + error_message: 错误消息
  49 + error_details: 错误详情(可选,用于填充到 Issue body)
  50 + app_name: 应用名称,用于标识错误来源
  51 +
  52 + Returns:
  53 + 包含错误信息和 GitHub Issues 链接的 Markdown 格式字符串
  54 + """
  55 + issue_title = f"[{app_name}] {error_message[:50]}"
  56 + issue_body = f"## 错误信息\n\n{error_message}\n\n"
  57 +
  58 + if error_details:
  59 + issue_body += f"## 错误详情\n\n```\n{error_details}\n```\n\n"
  60 +
  61 + issue_body += f"## 环境信息\n\n- 应用: {app_name}\n- 时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
  62 +
  63 + issue_url = create_issue_url(issue_title, issue_body)
  64 +
  65 + # 使用 markdown 格式添加超链接
  66 + error_display = f"{error_message}\n\n[📝 提交错误报告]({issue_url})"
  67 +
  68 + if error_details:
  69 + error_display = f"{error_message}\n\n```\n{error_details}\n```\n\n[📝 提交错误报告]({issue_url})"
  70 +
  71 + return error_display
  72 +
  73 +
  74 +__all__ = [
  75 + "create_issue_url",
  76 + "error_with_issue_link",
  77 + "GITHUB_REPO",
  78 + "GITHUB_ISSUES_URL",
  79 +]
  80 +