feat(skill): refactor candidateLoader and update loadCandidateSkills to use getSkillByID
This commit is contained in:
@@ -9,11 +9,12 @@ import (
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
)
|
||||
|
||||
func newCandidateLoader() *candidateLoader {
|
||||
var newCandidateLoader = func() *candidateLoader {
|
||||
return &candidateLoader{}
|
||||
}
|
||||
|
||||
type candidateLoader struct{}
|
||||
type candidateLoader struct {
|
||||
}
|
||||
|
||||
func (l *candidateLoader) findManualSkillDefinition(skillCode string) *models.SkillDefinition {
|
||||
return repositories.SkillDefinitionRepository.GetByCode(sqls.DB(), skillCode)
|
||||
@@ -30,7 +31,7 @@ func (l *candidateLoader) loadCandidateSkills(aiAgent *models.AIAgent) []models.
|
||||
ret := make([]models.SkillDefinition, 0, len(skillIDs))
|
||||
for _, id := range skillIDs {
|
||||
// TODO 这里批量查询一下,批量查询返回数据的顺序需要保证和skillIDs一致
|
||||
skill := repositories.SkillDefinitionRepository.Get(sqls.DB(), id)
|
||||
skill := l.getSkillByID(id)
|
||||
if skill == nil || skill.Status != enums.StatusOk {
|
||||
continue
|
||||
}
|
||||
@@ -38,3 +39,7 @@ func (l *candidateLoader) loadCandidateSkills(aiAgent *models.AIAgent) []models.
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (l *candidateLoader) getSkillByID(id int64) *models.SkillDefinition {
|
||||
return repositories.SkillDefinitionRepository.Get(sqls.DB(), id)
|
||||
}
|
||||
|
||||
@@ -53,12 +53,6 @@ func MatchSkill(execCtx context.Context, ctx RuntimeContext, aiAgent *models.AIA
|
||||
}
|
||||
}
|
||||
|
||||
if len(candidates) == 1 {
|
||||
trace.Status = "single_candidate"
|
||||
trace.SelectedSkillCode = candidates[0].Code
|
||||
return &candidates[0], "single_candidate", trace, nil
|
||||
}
|
||||
|
||||
selected, routeTrace, err := routeSkillWithLLM(execCtx, aiConfig, ctx.UserMessage, candidates)
|
||||
if routeTrace != nil {
|
||||
trace.Status = routeTrace.Status
|
||||
|
||||
@@ -28,6 +28,7 @@ func routeSkillWithLLM(ctx context.Context, aiConfig *models.AIConfig, userMessa
|
||||
trace.Status = "empty_user_message"
|
||||
return nil, trace, nil
|
||||
}
|
||||
// TODO 系统体是指为什么不是配置在AIAgent中的?
|
||||
systemPrompt := "你是客服技能路由器。你只能在候选 Skill 中选择一个最合适的 skillCode,或者返回 NONE。只有当用户问题与 Skill 的职责边界明确匹配时才选择;如果不明确、信息不足、多个 Skill 都不够确定,就返回 NONE。输出只能是 skillCode 或 NONE,不能输出其他内容。"
|
||||
userPrompt := buildSkillRoutePrompt(userMessage, candidates)
|
||||
startedAt := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user