Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 5 additions & 8 deletions pkg/stream/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
}