runSingleTestCase 运行单个测试用例的所有评分器
(ctx context.Context, testCase *BatchTestCase, scorers []Scorer)
| 152 | |
| 153 | // runSingleTestCase 运行单个测试用例的所有评分器 |
| 154 | func runSingleTestCase(ctx context.Context, testCase *BatchTestCase, scorers []Scorer) *BatchResult { |
| 155 | startTime := time.Now() |
| 156 | |
| 157 | result := &BatchResult{ |
| 158 | TestCaseID: testCase.ID, |
| 159 | Scores: make([]*ScoreResult, 0, len(scorers)), |
| 160 | Metadata: testCase.Metadata, |
| 161 | } |
| 162 | |
| 163 | for _, scorer := range scorers { |
| 164 | score, err := scorer.Score(ctx, testCase.Input) |
| 165 | if err != nil { |
| 166 | result.Error = fmt.Sprintf("scorer error: %v", err) |
| 167 | break |
| 168 | } |
| 169 | result.Scores = append(result.Scores, score) |
| 170 | } |
| 171 | |
| 172 | result.Duration = time.Since(startTime) |
| 173 | return result |
| 174 | } |
| 175 | |
| 176 | // calculateSummary 计算汇总统计 |
| 177 | func calculateSummary(results []*BatchResult) *BatchSummary { |