feat: ai生成一个数据分析正文
This commit is contained in:
parent
b6fd35b2ec
commit
ece9a964f9
@ -10,9 +10,11 @@ import (
|
||||
"fonchain-fiee/api/bundle"
|
||||
"fonchain-fiee/api/cast"
|
||||
"fonchain-fiee/pkg/cache"
|
||||
"fonchain-fiee/pkg/common/qwen"
|
||||
"fonchain-fiee/pkg/e"
|
||||
modelCast "fonchain-fiee/pkg/model/cast"
|
||||
"fonchain-fiee/pkg/model/login"
|
||||
modelQwen "fonchain-fiee/pkg/model/qwen"
|
||||
"fonchain-fiee/pkg/service"
|
||||
"fonchain-fiee/pkg/service/bundle/common"
|
||||
"fonchain-fiee/pkg/utils"
|
||||
@ -607,10 +609,101 @@ func ArtistMetricsSeries(ctx *gin.Context) {
|
||||
respMap["videoCount"] = videoCount
|
||||
respMap["imageCount"] = imageCount
|
||||
|
||||
// 调用 AI 分析数据
|
||||
analysis, err := generateArtistMetricsAnalysis(resp)
|
||||
if err != nil {
|
||||
zap.L().Error("生成艺人指标分析失败", zap.Error(err))
|
||||
// AI 分析失败不影响主业务,返回空字符串
|
||||
respMap["analysis"] = ""
|
||||
} else {
|
||||
respMap["analysis"] = analysis
|
||||
}
|
||||
|
||||
service.Success(ctx, respMap)
|
||||
return
|
||||
}
|
||||
|
||||
// generateArtistMetricsAnalysis 调用 AI 分析艺人指标数据
|
||||
func generateArtistMetricsAnalysis(resp *cast.ArtistMetricsSeriesResp) (string, error) {
|
||||
if resp == nil {
|
||||
return "", errors.New("数据为空")
|
||||
}
|
||||
|
||||
// 构建分析用的数据摘要
|
||||
var dataSummary strings.Builder
|
||||
dataSummary.WriteString("艺人各平台数据表现如下:\n")
|
||||
|
||||
// 粉丝数
|
||||
if resp.FansSeries != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("粉丝数总数: %d (周期类型: %d, 开始日期: %d, 结束日期: %d)\n",
|
||||
resp.FansSeries.FansCount, resp.FansSeries.PeriodType, resp.FansSeries.StartDate, resp.FansSeries.EndDate))
|
||||
}
|
||||
|
||||
// 播放量
|
||||
if resp.ViewsSeries != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("播放量总数: %d (周期类型: %d, 开始日期: %d, 结束日期: %d)\n",
|
||||
resp.ViewsSeries.ViewsCount, resp.ViewsSeries.PeriodType, resp.ViewsSeries.StartDate, resp.ViewsSeries.EndDate))
|
||||
}
|
||||
|
||||
// 点赞数
|
||||
if resp.LikesSeries != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("点赞数总数: %d (周期类型: %d, 开始日期: %d, 结束日期: %d)\n",
|
||||
resp.LikesSeries.LikesCount, resp.LikesSeries.PeriodType, resp.LikesSeries.StartDate, resp.LikesSeries.EndDate))
|
||||
}
|
||||
|
||||
// 评论数
|
||||
if resp.CommentsSeries != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("评论数总数: %d (周期类型: %d, 开始日期: %d, 结束日期: %d)\n",
|
||||
resp.CommentsSeries.CommentsCount, resp.CommentsSeries.PeriodType, resp.CommentsSeries.StartDate, resp.CommentsSeries.EndDate))
|
||||
}
|
||||
|
||||
// 分享数
|
||||
if resp.SharesSeries != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("分享数总数: %d (周期类型: %d, 开始日期: %d, 结束日期: %d)\n",
|
||||
resp.SharesSeries.SharesCount, resp.SharesSeries.PeriodType, resp.SharesSeries.StartDate, resp.SharesSeries.EndDate))
|
||||
}
|
||||
|
||||
// 最佳发布时间
|
||||
if resp.BestPostTime != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("最佳发布时间: %s\n", resp.BestPostTime.DetailJSON))
|
||||
}
|
||||
|
||||
// 最活跃日期
|
||||
if resp.MostActiveDay != nil {
|
||||
dataSummary.WriteString(fmt.Sprintf("最活跃日期: %s\n", resp.MostActiveDay.DetailJSON))
|
||||
}
|
||||
|
||||
// 构建 prompt
|
||||
prompt := fmt.Sprintf(`根据以下艺人各平台运营数据分析运营的各平台数据表现,结合相关数据简要表述优点,字数在200字内:\n%s`, dataSummary.String())
|
||||
|
||||
// 调用 AI
|
||||
req := modelQwen.ChatRequest{
|
||||
Model: "qwen-plus",
|
||||
Messages: []modelQwen.Message{
|
||||
{
|
||||
Role: "user",
|
||||
Content: []modelQwen.Content{
|
||||
{
|
||||
Type: "text",
|
||||
Text: prompt,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
respAI, err := qwen.Chat(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if respAI == nil || len(respAI.Choices) == 0 {
|
||||
return "", errors.New("AI 返回结果为空")
|
||||
}
|
||||
|
||||
return respAI.Choices[0].Message.Content, nil
|
||||
}
|
||||
|
||||
// ArtistMetricsDailyWindow 艺人指标日窗口
|
||||
func ArtistMetricsDailyWindow(ctx *gin.Context) {
|
||||
var req *cast.ArtistMetricsDailyWindowReq
|
||||
|
||||
Loading…
Reference in New Issue
Block a user