增加一些日志打印
This commit is contained in:
parent
ce9edf513c
commit
016f2c2459
@ -319,7 +319,13 @@ func AICompetitorReport(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
textChan <- textResult{text: chatResp.Choices[0].Message.Content}
|
// 打印 AI 返回的原始内容(用于调试)
|
||||||
|
aiText := chatResp.Choices[0].Message.Content
|
||||||
|
fmt.Println("========== AI 返回的原始内容 ==========")
|
||||||
|
fmt.Println(aiText)
|
||||||
|
fmt.Println("=========================================")
|
||||||
|
|
||||||
|
textChan <- textResult{text: aiText}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,11 +432,21 @@ func AICompetitorReport(ctx *gin.Context) {
|
|||||||
result.JSON = textRes.text // JSON 字段直接返回 AI 生成的 JSON
|
result.JSON = textRes.text // JSON 字段直接返回 AI 生成的 JSON
|
||||||
|
|
||||||
// 将 JSON 解析并转换为纯文本
|
// 将 JSON 解析并转换为纯文本
|
||||||
|
fmt.Println("========== 开始解析 JSON ==========")
|
||||||
|
fmt.Println("原始内容是否以 { 开头:", strings.HasPrefix(strings.TrimSpace(textRes.text), "{"))
|
||||||
|
fmt.Println("原始内容前100字符:", strings.TrimSpace(textRes.text)[:min(100, len(strings.TrimSpace(textRes.text)))])
|
||||||
|
|
||||||
var jsonData CompetitorReportJSON
|
var jsonData CompetitorReportJSON
|
||||||
if err := json.Unmarshal([]byte(textRes.text), &jsonData); err != nil {
|
if err := json.Unmarshal([]byte(textRes.text), &jsonData); err != nil {
|
||||||
// 如果解析失败,回退使用原始文本
|
// 如果解析失败,回退使用原始文本
|
||||||
|
fmt.Println("========== JSON 解析失败 ==========")
|
||||||
|
fmt.Println("解析错误:", err)
|
||||||
|
fmt.Println("===================================")
|
||||||
result.Text = textRes.text
|
result.Text = textRes.text
|
||||||
} else {
|
} else {
|
||||||
|
fmt.Println("========== JSON 解析成功 ==========")
|
||||||
|
fmt.Println("Summary:", jsonData.HighlightAnalysis.Summary)
|
||||||
|
fmt.Println("==================================")
|
||||||
result.Text = convertJSONToText(jsonData, len(req.Videos) > 0)
|
result.Text = convertJSONToText(jsonData, len(req.Videos) > 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user