refactor: LLM 直接输出 Markdown,移除 JSON 解析层
Deploy PR-Helper / deploy (push) Successful in 30s

服务端:
- prompt 改为要求直接输出 Markdown,不再输出 JSON
- GeneratePR 返回 string 而非 PRDescription 结构体
- 移除 JSON 解析、extractJSON、fixInlineCode 等逻辑
- ChatStream 的 content 事件直接携带 Markdown 片段流式传输

前端:
- generate() 仅处理 content + done + error 三个事件
- content 事件累积 Markdown 文本,实时渲染到两栏
- 移除 parsePartialJSON、buildMarkdown 等中间层
- 代码量从 ~100 行减至 ~50 行
This commit is contained in:
2026-06-21 16:02:05 +08:00
parent 779bd9e332
commit 496e3ba71e
3 changed files with 39 additions and 152 deletions
+4 -8
View File
@@ -75,19 +75,15 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
// Update last_used
h.db.Exec(`UPDATE repositories SET last_used = NOW() WHERE id = ?`, id)
// Generate PR description (pass user ID for per-user LLM config)
pr, err := services.GeneratePR(h.db, localPath, req.Base, req.Head, user.ID, sendEvent)
// Generate PR description (streams markdown via content events)
markdown, err := services.GeneratePR(h.db, localPath, req.Base, req.Head, user.ID, sendEvent)
if err != nil {
sendEvent("error", map[string]interface{}{"message": err.Error()})
return
}
// Save analysis to DB with user_id
resultJSON, err := json.Marshal(pr)
if err != nil {
sendEvent("error", map[string]interface{}{"message": "序列化结果失败: " + err.Error()})
return
}
// Save analysis to DB
resultJSON, _ := json.Marshal(map[string]string{"markdown": markdown})
if _, err := h.db.Exec(`INSERT INTO analyses (user_id, repo_id, type, base_ref, head_ref, result) VALUES (?, ?, 'pr_description', ?, ?, ?)`,
user.ID, id, req.Base, req.Head, string(resultJSON)); err != nil {
sendEvent("error", map[string]interface{}{"message": "保存分析结果失败: " + err.Error()})