@@ -20,6 +20,7 @@ import {
20
20
POINTS_FOR_CATEGORIES ,
21
21
Rating ,
22
22
CATEGORY_NAMES ,
23
+ RatingsContext ,
23
24
} from './rating-types.js' ;
24
25
import { extractEmbeddedCodeFromTypeScript } from './embedded-languages.js' ;
25
26
import { Environment } from '../configuration/environment.js' ;
@@ -62,6 +63,7 @@ export async function rateGeneratedCode(
62
63
let categorizedFiles : CategorizedFiles | null = null ;
63
64
let totalPoints = 0 ;
64
65
let maxOverallPoints = 0 ;
66
+ const ratingsContext : RatingsContext = { } ;
65
67
66
68
// Rating may also invoke LLMs. Track the usage.
67
69
const tokenUsage = {
@@ -95,11 +97,16 @@ export async function rateGeneratedCode(
95
97
serveTestingResult ,
96
98
repairAttempts ,
97
99
outputFiles . length ,
98
- axeRepairAttempts
100
+ axeRepairAttempts ,
101
+ ratingsContext
99
102
) ;
100
103
} else if ( current . kind === RatingKind . PER_FILE ) {
101
104
categorizedFiles ??= splitFilesIntoCategories ( outputFiles ) ;
102
- result = await runPerFileRating ( current , categorizedFiles ) ;
105
+ result = await runPerFileRating (
106
+ current ,
107
+ categorizedFiles ,
108
+ ratingsContext
109
+ ) ;
103
110
} else if ( current . kind === RatingKind . LLM_BASED ) {
104
111
result = await runLlmBasedRating (
105
112
environment ,
@@ -113,7 +120,8 @@ export async function rateGeneratedCode(
113
120
repairAttempts ,
114
121
axeRepairAttempts ,
115
122
abortSignal ,
116
- autoraterModel
123
+ autoraterModel ,
124
+ ratingsContext
117
125
) ;
118
126
} else {
119
127
throw new UserFacingError ( `Unsupported rating type ${ current } ` ) ;
@@ -139,6 +147,7 @@ export async function rateGeneratedCode(
139
147
) ;
140
148
}
141
149
150
+ ratingsContext [ current . id ] = result ;
142
151
category . assessments . push ( result ) ;
143
152
}
144
153
@@ -178,14 +187,16 @@ function runPerBuildRating(
178
187
serveResult : ServeTestingResult | null ,
179
188
repairAttempts : number ,
180
189
generatedFileCount : number ,
181
- axeRepairAttempts : number
190
+ axeRepairAttempts : number ,
191
+ ratingsContext : RatingsContext
182
192
) : IndividualAssessment | SkippedIndividualAssessment {
183
193
const rateResult = rating . rate ( {
184
194
buildResult,
185
195
serveResult,
186
196
repairAttempts,
187
197
generatedFileCount,
188
198
axeRepairAttempts,
199
+ ratingsContext,
189
200
} ) ;
190
201
191
202
// If the rating was skipped (e.g., Axe test wasn't run), create a skipped assessment.
@@ -203,7 +214,8 @@ function runPerBuildRating(
203
214
204
215
async function runPerFileRating (
205
216
rating : PerFileRating ,
206
- categorizedFiles : CategorizedFiles
217
+ categorizedFiles : CategorizedFiles ,
218
+ ratingsContext : RatingsContext
207
219
) : Promise < IndividualAssessment | SkippedIndividualAssessment > {
208
220
const errorMessages : string [ ] = [ ] ;
209
221
let contentType : PerFileRatingContentType ;
@@ -234,7 +246,7 @@ async function runPerFileRating(
234
246
// Remove comments from the code to avoid false-detection of bad patterns.
235
247
// Some keywords like `NgModule` can be used in code comments.
236
248
const code = removeComments ( file . code , contentType ) ;
237
- const result = await rating . rate ( code , file . filePath ) ;
249
+ const result = await rating . rate ( code , file . filePath , ratingsContext ) ;
238
250
let coeff : number ;
239
251
240
252
if ( typeof result === 'number' ) {
@@ -279,7 +291,8 @@ async function runLlmBasedRating(
279
291
repairAttempts : number ,
280
292
axeRepairAttempts : number ,
281
293
abortSignal : AbortSignal ,
282
- autoraterModel : string
294
+ autoraterModel : string ,
295
+ ratingsContext : RatingsContext
283
296
) : Promise < IndividualAssessment | SkippedIndividualAssessment > {
284
297
const result = await rating . rate ( {
285
298
environment,
@@ -293,6 +306,7 @@ async function runLlmBasedRating(
293
306
repairAttempts,
294
307
axeRepairAttempts,
295
308
abortSignal,
309
+ ratingsContext,
296
310
} ) ;
297
311
298
312
if ( result . state === RatingState . SKIPPED ) {
0 commit comments