@@ -323,8 +323,8 @@ func (h *generateCommandHandler) runSingleTestWithContext(input string, modelNam
323323
324324 // Build OpenAI messages from our messages format
325325 re := regexp .MustCompile (`\{\{\s*text\s*\}\}` )
326- openaiMessages := make ( []azuremodels.ChatMessage , 0 , len ( messages ))
327- for i , msg := range messages {
326+ openaiMessages := []azuremodels.ChatMessage {}
327+ for _ , msg := range messages {
328328 // Replace template variables in content
329329 content := msg .Content
330330 if content != "" {
@@ -344,10 +344,11 @@ func (h *generateCommandHandler) runSingleTestWithContext(input string, modelNam
344344 return "" , fmt .Errorf ("unknown role: %s" , msg .Role )
345345 }
346346
347- openaiMessages [i ] = azuremodels.ChatMessage {
347+ // Handle the openaiMessages array indexing properly
348+ openaiMessages = append (openaiMessages , azuremodels.ChatMessage {
348349 Role : role ,
349350 Content : & content ,
350- }
351+ })
351352 }
352353
353354 options := azuremodels.ChatCompletionOptions {
@@ -373,20 +374,22 @@ func (h *generateCommandHandler) generateGroundtruth(context *PromptPexContext)
373374 h .cfg .WriteToOut ("Groundtruth" )
374375
375376 for i := range context .Tests {
376- test := context .Tests [i ]
377-
378- // Generate groundtruth output
379- output , err := h .runSingleTestWithContext (test .TestInput , * groundtruthModel , context )
380- if err != nil {
381- h .cfg .WriteToOut (fmt .Sprintf ("Failed to generate groundtruth for test %d: %v" , i , err ))
382- continue
377+ test := & context .Tests [i ]
378+ h .WriteToLine (test .TestInput )
379+ if test .Groundtruth == nil || * test .Groundtruth == "" {
380+ // Generate groundtruth output
381+ output , err := h .runSingleTestWithContext (test .TestInput , * groundtruthModel , context )
382+ if err != nil {
383+ h .cfg .WriteToOut (fmt .Sprintf ("Failed to generate groundtruth for test %d: %v" , i , err ))
384+ continue
385+ }
386+ test .Groundtruth = & output
387+ test .GroundtruthModel = groundtruthModel
383388 }
384389
385- test .Groundtruth = & output
386- test .GroundtruthModel = groundtruthModel
387390 }
388391
389- h .WriteEndBox ("" )
392+ h .WriteEndBox (fmt . Sprintf ( "%d items" , len ( context . Tests )) )
390393
391394 return nil
392395}
0 commit comments