diff --git a/short_drama.db b/short_drama.db index ff1f5a6..ab7e2fb 100644 Binary files a/short_drama.db and b/short_drama.db differ diff --git a/shortdrama/service/episode_service.go b/shortdrama/service/episode_service.go index e4bd1a0..1ac01d1 100644 --- a/shortdrama/service/episode_service.go +++ b/shortdrama/service/episode_service.go @@ -198,22 +198,27 @@ func (s *dramaService) DeleteEpisode(ctx context.Context, dramaId, epId int64) e func (s *dramaService) GenerateScript(ctx context.Context, dramaId int64, episodeTitle, description string) (script string, err error) { d, err := dao.Drama.GetOne(ctx, dramaId) if err != nil { + g.Log().Errorf(ctx, "GenerateScript 查询短剧失败 dramaId=%d: %v", dramaId, err) return } if d == nil { + g.Log().Warningf(ctx, "GenerateScript 短剧不存在 dramaId=%d", dramaId) err = fmt.Errorf("短剧不存在") return } modelCfg := ConfigService.GetMergedConfig(ctx, d.UserId, "chat") if modelCfg.ApiKey == "" || modelCfg.ModelName == "" { + g.Log().Warningf(ctx, "GenerateScript 对话模型未配置 userId=%d ApiKey=%q ModelName=%q", d.UserId, modelCfg.ApiKey, modelCfg.ModelName) err = fmt.Errorf("模型未配置") return } + g.Log().Infof(ctx, "GenerateScript 开始生成 userId=%d dramaId=%d model=%s baseUrl=%s", d.UserId, dramaId, modelCfg.ModelName, modelCfg.BaseUrl) // 加载演员/场景/道具上下文 genCtx, err := BuildGenerationContext(ctx, d) if err != nil { + g.Log().Errorf(ctx, "GenerateScript 加载上下文失败 dramaId=%d: %v", dramaId, err) err = fmt.Errorf("加载短剧上下文失败: %w", err) return } @@ -235,20 +240,24 @@ func (s *dramaService) GenerateScript(ctx context.Context, dramaId int64, episod {Role: agent.RoleSystem, Content: systemPrompt}, {Role: agent.RoleUser, Content: userInput}, } + g.Log().Infof(ctx, "GenerateScript 调用AI模型 model=%s max_tokens=%d prompt_len=%d", chatCfg.ModelName, chatCfg.MaxTokens, len(systemPrompt)+len(userInput)) result, err := agent.CallChatModel(ctx, chatCfg, &agent.ChatRequest{ Messages: messages, MaxTokens: chatCfg.MaxTokens, }) if err != nil { + g.Log().Errorf(ctx, "GenerateScript AI调用失败: %v", err) err = fmt.Errorf("生成脚本失败: %w", err) return } raw := result.Content if raw == "" { + g.Log().Warningf(ctx, "GenerateScript AI返回内容为空") err = fmt.Errorf("生成的脚本为空") return } + g.Log().Infof(ctx, "GenerateScript AI返回成功 content_len=%d", len(raw)) // 尝试解析为JSON shots数组 var shots []domain.Shot