2026-07-25 12:04:06 +08:00
|
|
|
package runtime
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-08-21 00:41:07 +08:00
|
|
|
applicationruntime "code.tczkiot.com/wlw/ai-agent/internal/ai/application/runtime"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/request"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/response"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/errorsx"
|
|
|
|
|
svc "code.tczkiot.com/wlw/ai-agent/internal/services"
|
2026-07-25 12:04:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
svc.AgentEvaluationRunHook = RunAgentEvaluation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RunAgentEvaluation(ctx context.Context, req request.RunAgentEvaluationRequest) (*response.AgentEvaluationReportResponse, error) {
|
|
|
|
|
agent := svc.AIAgentService.Get(req.AIAgentID)
|
|
|
|
|
if agent == nil || agent.Status != enums.StatusOk {
|
|
|
|
|
return nil, errorsx.InvalidParamI18n("error.e0007")
|
|
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
config, err := applicationruntime.ResolveRuntimeAIConfig(ctx, agent.AIConfigID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2026-07-25 12:04:06 +08:00
|
|
|
}
|
|
|
|
|
cases := make([]applicationruntime.OfflineEvaluationCase, 0, len(req.Cases))
|
|
|
|
|
for _, item := range req.Cases {
|
|
|
|
|
cases = append(cases, applicationruntime.OfflineEvaluationCase{ID: item.ID, Category: item.Category, Message: item.Message, History: item.History, Expect: item.Expect})
|
|
|
|
|
}
|
2026-07-27 23:29:02 +08:00
|
|
|
report, err := applicationruntime.NewService().RunOfflineEvaluation(ctx, *agent, *config, cases)
|
2026-07-25 12:04:06 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
csv, err := report.CSV()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-07-27 23:29:02 +08:00
|
|
|
ret := &response.AgentEvaluationReportResponse{Total: report.Total, Passed: report.Passed, CSV: csv, Results: make([]response.AgentEvaluationResultResponse, 0, len(report.Results))}
|
2026-07-25 12:04:06 +08:00
|
|
|
for _, item := range report.Results {
|
2026-07-27 23:29:02 +08:00
|
|
|
ret.Results = append(ret.Results, response.AgentEvaluationResultResponse{CaseID: item.CaseID, Category: item.Category, Passed: item.Passed, ReplyText: item.ReplyText, Interrupted: item.Interrupted, Error: item.Error, Finding: item.Finding})
|
2026-07-25 12:04:06 +08:00
|
|
|
}
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|