diff --git a/cmd/stream.go b/cmd/stream.go index 24bf21b..b0585dc 100644 --- a/cmd/stream.go +++ b/cmd/stream.go @@ -30,9 +30,10 @@ func agentStream(cmd *cobra.Command, args []string) { file := args[0] - err := stream.ParseFile(file) + result, err := stream.ParseFile(file) if err != nil { fmt.Fprintf(os.Stderr, "Error parsing file: %v\n", err) os.Exit(1) } + fmt.Println(result) } diff --git a/pkg/stream/parse.go b/pkg/stream/parse.go index e1929ae..01ba78f 100644 --- a/pkg/stream/parse.go +++ b/pkg/stream/parse.go @@ -18,11 +18,11 @@ type Data struct { Choices []Choice `json:"choices"` } -func ParseFile(filename string) error { +func ParseFile(filename string) (string, error) { // Open the file file, err := os.Open(filename) if err != nil { - return fmt.Errorf("could not open file: %w", err) + return "", fmt.Errorf("could not open file: %w", err) } defer file.Close() @@ -52,8 +52,7 @@ func ParseFile(filename string) error { var data Data err := json.Unmarshal([]byte(line), &data) if err != nil { - // Skip this line if JSON is incomplete or malformed - continue + return "", fmt.Errorf("error parsing JSON: %w", err) } // Extract delta.content and concatenate it @@ -64,12 +63,10 @@ func ParseFile(filename string) error { // Check for scanner errors if err := scanner.Err(); err != nil { - return fmt.Errorf("error reading file: %w", err) + return "", fmt.Errorf("error reading file: %w", err) } // Print the final concatenated result result := contentBuilder.String() - fmt.Println(result) - - return nil + return result, nil }