diff --git a/internal/ai/internal/domain/jd.go b/internal/ai/internal/domain/jd.go index b82bcf73..f77c4e0a 100644 --- a/internal/ai/internal/domain/jd.go +++ b/internal/ai/internal/domain/jd.go @@ -4,6 +4,7 @@ const ( AnalysisJDTech = "analysis_jd_tech" AnalysisJDBiz = "analysis_jd_biz" AnalysisJDPosition = "analysis_jd_position" + AnalysisJDSubtext = "analysis_jd_subtext" ) type JDEvaluation struct { @@ -16,4 +17,6 @@ type JD struct { TechScore *JDEvaluation BizScore *JDEvaluation PosScore *JDEvaluation + // 潜台词 + Subtext string } diff --git a/internal/ai/internal/integration/llm_service_test.go b/internal/ai/internal/integration/llm_service_test.go index d285f574..b7cb860c 100644 --- a/internal/ai/internal/integration/llm_service_test.go +++ b/internal/ai/internal/integration/llm_service_test.go @@ -59,6 +59,7 @@ func (s *LLMServiceSuite) SetupSuite() { err = s.db.Create(&dao.BizConfig{ Biz: domain.BizQuestionExamine, MaxInput: 100, + Price: 1, PromptTemplate: "这是问题 %s,这是问题内容 %s,这是用户输入 %s", KnowledgeId: knowledgeId, Ctime: now, @@ -68,6 +69,7 @@ func (s *LLMServiceSuite) SetupSuite() { err = s.db.Create(&dao.BizConfig{ Biz: domain.BizCaseExamine, MaxInput: 100, + Price: 1, PromptTemplate: "这是案例 %s,这是案例内容 %s,这是用户输入 %s", KnowledgeId: knowledgeId, Ctime: now, @@ -105,6 +107,15 @@ func (s *LLMServiceSuite) SetupSuite() { }).Error s.NoError(err) + err = s.db.Create(&dao.BizConfig{ + Biz: domain.AnalysisJDSubtext, + MaxInput: 100, + PromptTemplate: "这是岗位描述Subtext %s", + KnowledgeId: knowledgeId, + Ctime: now, + Utime: now, + }).Error + s.NoError(err) } func (s *LLMServiceSuite) TearDownSuite() { @@ -639,31 +650,37 @@ func (s *LLMServiceSuite) TestHandler_AnalysisJD() { llmHdl := hdlmocks.NewMockHandler(ctrl) llmHdl.EXPECT().Handle(gomock.Any(), gomock.Any()). DoAndReturn(func(ctx context.Context, request domain.LLMRequest) (domain.LLMResponse, error) { - if request.Biz == "analysis_jd_tech" { + switch request.Biz { + case domain.AnalysisJDTech: return domain.LLMResponse{ Tokens: 1000, Amount: 100, Answer: `score: 6 这是技术前景`, }, nil - } - if request.Biz == "analysis_jd_biz" { + case domain.AnalysisJDBiz: return domain.LLMResponse{ Tokens: 100, Amount: 200, Answer: `score: 7 这是业务前景`, }, nil - } - if request.Biz == "analysis_jd_position" { + case domain.AnalysisJDPosition: return domain.LLMResponse{ Tokens: 100, Amount: 100, Answer: `score: 8 这是公司地位`, }, nil + case domain.AnalysisJDSubtext: + return domain.LLMResponse{ + Tokens: 100, + Amount: 100, + Answer: `这是我的分析`, + }, nil + default: + return domain.LLMResponse{}, errors.New("unknown biz") } - return domain.LLMResponse{}, errors.New("unknown biz") }).AnyTimes() creditSvc := creditmocks.NewMockService(ctrl) creditSvc.EXPECT().GetCreditsByUID(gomock.Any(), gomock.Any()).Return(credit.Credit{ @@ -676,7 +693,7 @@ func (s *LLMServiceSuite) TestHandler_AnalysisJD() { after: func(t *testing.T, resp web.JDResponse) { // 校验response写入的内容是否正确 assert.Equal(t, web.JDResponse{ - Amount: 400, + Amount: 500, TechScore: &web.JDEvaluation{ Score: 6, Analysis: "这是技术前景", @@ -689,6 +706,7 @@ func (s *LLMServiceSuite) TestHandler_AnalysisJD() { Score: 8, Analysis: "这是公司地位", }, + Subtext: "这是我的分析", }, resp) }, diff --git a/internal/ai/internal/service/jd_service.go b/internal/ai/internal/service/jd_service.go index 093e947b..4d304088 100644 --- a/internal/ai/internal/service/jd_service.go +++ b/internal/ai/internal/service/jd_service.go @@ -3,6 +3,7 @@ package service import ( "context" "errors" + "fmt" "strconv" "strings" "sync/atomic" @@ -31,6 +32,7 @@ func NewJDService(aiSvc llm.Service) JDService { func (j *jdSvc) Evaluate(ctx context.Context, uid int64, jd string) (domain.JD, error) { var techJD, bizJD, positionJD *domain.JDEvaluation var amount int64 + var subtext string var eg errgroup.Group eg.Go(func() error { var err error @@ -62,6 +64,19 @@ func (j *jdSvc) Evaluate(ctx context.Context, uid int64, jd string) (domain.JD, atomic.AddInt64(&amount, positionAmount) return nil }) + + eg.Go(func() error { + tid := shortuuid.New() + resp, err := j.aiSvc.Invoke(ctx, domain.LLMRequest{ + Uid: uid, + Tid: tid, + Biz: domain.AnalysisJDSubtext, + Input: []string{jd}, + }) + subtext = resp.Answer + atomic.AddInt64(&amount, resp.Amount) + return err + }) if err := eg.Wait(); err != nil { return domain.JD{}, err } @@ -70,6 +85,7 @@ func (j *jdSvc) Evaluate(ctx context.Context, uid int64, jd string) (domain.JD, TechScore: techJD, BizScore: bizJD, PosScore: positionJD, + Subtext: subtext, }, nil } @@ -92,7 +108,7 @@ func (j *jdSvc) analysisJd(ctx context.Context, uid int64, biz string, jd string score := answer[0] scoreNum, err := strconv.ParseFloat(strings.TrimSpace(strings.TrimPrefix(score, "score:")), 64) if err != nil { - return 0, nil, errors.New("分数返回的数据不对") + return 0, nil, fmt.Errorf("分数返回的数据不对 %s", score) } return resp.Amount, &domain.JDEvaluation{ diff --git a/internal/ai/internal/service/llm/handler/log/builder.go b/internal/ai/internal/service/llm/handler/log/builder.go index c87629b7..df1cd81c 100644 --- a/internal/ai/internal/service/llm/handler/log/builder.go +++ b/internal/ai/internal/service/llm/handler/log/builder.go @@ -31,7 +31,7 @@ func (h *HandlerBuilder) Next(next handler.Handler) handler.Handler { elog.Int64("uid", req.Uid), elog.String("biz", req.Biz)) // 记录请求 - logger.Info("请求 LLM") + logger.Debug("请求 LLM") resp, err := next.Handle(ctx, req) if err != nil { // 记录错误 @@ -39,7 +39,7 @@ func (h *HandlerBuilder) Next(next handler.Handler) handler.Handler { return resp, err } // 记录响应 - logger.Info("请求 LLM 服务响应成功", elog.Int64("tokens", resp.Tokens)) + logger.Debug("请求 LLM 服务响应成功", elog.Int64("tokens", resp.Tokens)) return resp, err }) } diff --git a/internal/ai/internal/web/handler.go b/internal/ai/internal/web/handler.go index 40d0d403..dfdd55f3 100644 --- a/internal/ai/internal/web/handler.go +++ b/internal/ai/internal/web/handler.go @@ -65,6 +65,7 @@ func (h *Handler) AnalysisJd(ctx *ginx.Context, req JDRequest, sess session.Sess TechScore: h.newJD(resp.TechScore), BizScore: h.newJD(resp.BizScore), PosScore: h.newJD(resp.PosScore), + Subtext: resp.Subtext, }, }, nil default: diff --git a/internal/ai/internal/web/vo.go b/internal/ai/internal/web/vo.go index 4735c6b5..e47f07eb 100644 --- a/internal/ai/internal/web/vo.go +++ b/internal/ai/internal/web/vo.go @@ -19,6 +19,7 @@ type JDResponse struct { TechScore *JDEvaluation `json:"techScore"` BizScore *JDEvaluation `json:"bizScore"` PosScore *JDEvaluation `json:"posScore"` + Subtext string `json:"subtext"` } type JDEvaluation struct {