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 Jun 2, 2024
1 parent b5ac4a5 commit 5636753
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 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 Expand Up @@ -1121,6 +1141,8 @@ func (w *Worker) handleOutputFiles(outputDir, prNumber, outDirName string) strin
var contentType string
if strings.HasSuffix(filename, ".json") || strings.Contains(filename, "json-viewer.html") {
contentType = "application/json-lines+json"
} else if strings.HasSuffix(filename, ".html") {
contentType = "text/html"
} else {
contentType = "text/plain"
}
Expand Down
2 changes: 1 addition & 1 deletion worker/cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func generateAllHTML(allFile *os.File, logEntries []string, fileNames []string)
</body>
</html>`

tmpl, err := template.New("index").Parse(INDEX_HTML)
tmpl, err := template.New("combined_chatlogs.html").Parse(INDEX_HTML)
if err != nil {
return fmt.Errorf("template parsing error: %w", err)
}
Expand Down

0 comments on commit 5636753

Please sign in to comment.