Skip to content

Commit

Permalink
revert + fix html render
Browse files Browse the repository at this point in the history
Signed-off-by: greg pereira <[email protected]>
  • Loading branch information
Gregory-Pereira committed May 31, 2024
1 parent b5ac4a5 commit 6ea12b9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions worker/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (w *Worker) runPrecheck(lab, outputDir, modelName string) error {
}
chatlogDir := path.Join(workDir, "data", "chatlogs")
combinedYAMLPath := path.Join(outputDir, "combined_chatlogs.yaml")
combinedLogPath := path.Join(outputDir, "combined_chatlogs.log")
combinedYAMLHTMLPath := path.Join(outputDir, "combined_chatlogs.html")

defer func() {
Expand All @@ -240,6 +241,7 @@ func (w *Worker) runPrecheck(lab, outputDir, modelName string) error {
}

var combinedLogs []map[string]interface{}
var combinedLogsText strings.Builder
var fileNames []string

for _, file := range chatlogFiles {
Expand All @@ -258,6 +260,16 @@ func (w *Worker) runPrecheck(lab, outputDir, modelName string) error {
}
combinedLogs = append(combinedLogs, logData)

} else if strings.HasSuffix(file.Name(), ".log") {
// Read individual log files
content, err := os.ReadFile(path.Join(chatlogDir, file.Name()))
if err != nil {
w.logger.Errorf("Could not read log file %s: %v", file.Name(), err)
continue
}
// Add delimiter before each log
combinedLogsText.WriteString(fmt.Sprintf("\n\n----- %s -----\n\n\n", file.Name()))
combinedLogsText.Write(content)
}
// Move individual file to outputDir
if err := os.Rename(path.Join(chatlogDir, file.Name()), path.Join(outputDir, file.Name())); err != nil {
Expand All @@ -267,6 +279,14 @@ func (w *Worker) runPrecheck(lab, outputDir, modelName string) error {
fileNames = append(fileNames, file.Name())
}

if combinedLogsText.Len() > 0 {
if err := os.WriteFile(combinedLogPath, []byte(combinedLogsText.String()), 0644); err != nil {
w.logger.Errorf("Could not write combined log file: %v", err)
return
}
w.logger.Infof("Combined log file written to %s", combinedLogPath)
}

// Write the combined YAML file
if len(combinedLogs) > 0 {
// standard combined yaml file
Expand Down

0 comments on commit 6ea12b9

Please sign in to comment.