INNER CODE UNIT · Go
printResponse
teilomillet/gollm · cmd/gollm/main.go:130
func printResponse(verbose bool, promptType, fullPrompt, rawPrompt, response, outputFormat string) {
if verbose {
if fullPrompt == "" {
fullPrompt = rawPrompt // For qa, cot, and summarize, we don't have access to the full prompt
}
fmt.Printf("Prompt Type: %s\nFull Prompt:\n%s\n\nResponse:\n---------\n", promptType, fullPrompt)
}
if outputFormat == "json" {
var jsonResponse interface{}
err := json.Unmarshal([]byte(response), &jsonResponse)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing JSON response: %v\n", err)
fmt.Println(response) // Print raw response if JSON parsing fails
} else {
jsonPretty, _ := json.MarshalIndent(jsonResponse, "", " ")
fmt.Println(string(jsonPretty))
}