From 6ea12b94df6ee032a493d1b7f4bf6d4b4e8e08a0 Mon Sep 17 00:00:00 2001 From: greg pereira Date: Fri, 31 May 2024 10:54:12 -0700 Subject: [PATCH] revert + fix html render Signed-off-by: greg pereira --- worker/cmd/generate.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/worker/cmd/generate.go b/worker/cmd/generate.go index 489ea21..d0a1598 100644 --- a/worker/cmd/generate.go +++ b/worker/cmd/generate.go @@ -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() { @@ -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 { @@ -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 { @@ -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