Skip to content

Commit

Permalink
分析岗位的潜台词
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Dec 3, 2024
1 parent 60da318 commit 23e9ec6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
3 changes: 3 additions & 0 deletions internal/ai/internal/domain/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const (
AnalysisJDTech = "analysis_jd_tech"
AnalysisJDBiz = "analysis_jd_biz"
AnalysisJDPosition = "analysis_jd_position"
AnalysisJDSubtext = "analysis_jd_subtext"
)

type JDEvaluation struct {
Expand All @@ -16,4 +17,6 @@ type JD struct {
TechScore *JDEvaluation
BizScore *JDEvaluation
PosScore *JDEvaluation
// 潜台词
Subtext string
}
30 changes: 23 additions & 7 deletions internal/ai/internal/integration/llm_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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() {
Expand Down Expand Up @@ -639,31 +648,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{
Expand All @@ -676,7 +691,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: "这是技术前景",
Expand All @@ -689,6 +704,7 @@ func (s *LLMServiceSuite) TestHandler_AnalysisJD() {
Score: 8,
Analysis: "这是公司地位",
},
Subtext: "这是我的分析",
}, resp)

},
Expand Down
15 changes: 15 additions & 0 deletions internal/ai/internal/service/jd_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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
Expand Down Expand Up @@ -62,6 +63,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
}
Expand All @@ -70,6 +84,7 @@ func (j *jdSvc) Evaluate(ctx context.Context, uid int64, jd string) (domain.JD,
TechScore: techJD,
BizScore: bizJD,
PosScore: positionJD,
Subtext: subtext,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions internal/ai/internal/service/llm/handler/log/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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 {
// 记录错误
logger.Error("请求 LLM 服务失败", elog.FieldErr(err))
return resp, err
}
// 记录响应
logger.Info("请求 LLM 服务响应成功", elog.Int64("tokens", resp.Tokens))
logger.Debug("请求 LLM 服务响应成功", elog.Int64("tokens", resp.Tokens))
return resp, err
})
}
1 change: 1 addition & 0 deletions internal/ai/internal/web/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions internal/ai/internal/web/vo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 23e9ec6

Please sign in to comment.