Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

问题测试拆分为 3 步 #274

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/question/internal/domain/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ type Answer struct {

func (a Answer) String() string {
var sb strings.Builder
sb.WriteString("15K: ")
sb.WriteString("#### 15K: ")
sb.WriteString(a.Basic.Content)
sb.WriteString("\n")
sb.WriteString("25K: ")
sb.WriteString("#### 25K ")
sb.WriteString(a.Intermediate.Content)
sb.WriteString("\n")
sb.WriteString("35K: ")
Expand Down
20 changes: 10 additions & 10 deletions internal/question/internal/integration/examine_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ func (s *ExamineHandlerTest) TestExamine() {
Uid: uid,
Qid: 1,
Result: domain.ResultBasic.ToUint8(),
RawResult: "最终评分 \n 1",
Tokens: uid * 2,
Amount: uid * 2,
RawResult: "最终评分 \n 1\n\n最终评分 \n 1",
Tokens: 369,
Amount: 369,
}, record)

var queRes dao.QuestionResult
Expand Down Expand Up @@ -168,8 +168,8 @@ func (s *ExamineHandlerTest) TestExamine() {
wantResp: test.Result[web.ExamineResult]{
Data: web.ExamineResult{
Result: domain.ResultBasic.ToUint8(),
RawResult: "最终评分 \n 1",
Amount: 246,
RawResult: "最终评分 \n 1\n\n最终评分 \n 1",
Amount: 369,
},
},
},
Expand Down Expand Up @@ -206,9 +206,9 @@ func (s *ExamineHandlerTest) TestExamine() {
Uid: uid,
Qid: 2,
Result: domain.ResultBasic.ToUint8(),
RawResult: "最终评分 \n 1",
Tokens: 246,
Amount: 246,
RawResult: "最终评分 \n 1\n\n最终评分 \n 1",
Tokens: 369,
Amount: 369,
}, record)

var queRes dao.QuestionResult
Expand Down Expand Up @@ -236,8 +236,8 @@ func (s *ExamineHandlerTest) TestExamine() {
wantResp: test.Result[web.ExamineResult]{
Data: web.ExamineResult{
Result: domain.ResultBasic.ToUint8(),
RawResult: "最终评分 \n 1",
Amount: 246,
RawResult: "最终评分 \n 1\n\n最终评分 \n 1",
Amount: 369,
},
},
},
Expand Down
44 changes: 36 additions & 8 deletions internal/question/internal/service/examine.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,37 @@ func (svc *LLMExamineService) QuestionResult(ctx context.Context, uid, qid int64

// Examine 的执行步骤:
// - 先抽取关键点
// - 比较候选人遗漏的关键点
// - 根据关键点评分
// 因此总体上要调用 AI 两次
func (svc *LLMExamineService) Examine(ctx context.Context,
uid int64,
qid int64, input string) (domain.ExamineResult, error) {
// 1. 提取关键点
// 提取关键点
tid := shortuuid.New()
keypoints, err := svc.getKeyPoints(ctx, uid, qid, input, tid+"_keypoints")
keyPoints, err := svc.getKeyPoints(ctx, uid, qid, input, tid+"_key_points")
if err != nil {
return domain.ExamineResult{}, err
}
// 2. 根据关键点来评分
aiResp, err := svc.score(ctx, uid, keypoints.Answer, tid+"_score")

// 比较遗漏的关键点
cmpRes, err := svc.comparePoints(ctx, uid, tid+"_key_points_compare", keyPoints.Answer)
if err != nil {
return domain.ExamineResult{}, err
}

// 根据关键点、遗漏关键点来评分
aiResp, err := svc.score(ctx, uid, keyPoints.Answer+"\n\n"+cmpRes.Answer, tid+"_score")
if err != nil {
return domain.ExamineResult{}, err
}
// 解析结果
parsedRes := svc.parseExamineResult(aiResp.Answer)
result := domain.ExamineResult{
Result: parsedRes,
RawResult: keypoints.Answer,
Tokens: keypoints.Tokens + aiResp.Tokens,
Amount: keypoints.Amount + aiResp.Amount,
RawResult: keyPoints.Answer + "\n\n" + cmpRes.Answer,
Tokens: keyPoints.Tokens + cmpRes.Tokens + aiResp.Tokens,
Amount: keyPoints.Amount + cmpRes.Amount + aiResp.Amount,
Tid: tid,
}
// 开始记录结果
Expand All @@ -106,7 +114,27 @@ func (svc *LLMExamineService) getKeyPoints(
Tid: tid,
Biz: biz,
// 标题,标准答案,输入
Input: []string{que.Title, que.Answer.String(), input},
Input: []string{que.Title,
que.Answer.Basic.Content,
que.Answer.Intermediate.Content,
que.Answer.Advanced.Content,
input},
}
return svc.aiSvc.Invoke(ctx, aiReq)
}

func (svc *LLMExamineService) comparePoints(
ctx context.Context,
uid int64,
tid, keyPoints string) (ai.LLMResponse, error) {
// 首先提取关键字
const biz = "question_examine_key_points_compare"
aiReq := ai.LLMRequest{
Uid: uid,
Tid: tid,
Biz: biz,
// 标题,标准答案,输入
Input: []string{keyPoints},
}
return svc.aiSvc.Invoke(ctx, aiReq)
}
Expand Down
Loading