Skip to content

Add stream cmd#10

Merged
calvinmvrk merged 3 commits intomainfrom
add-stream-cmd
Nov 8, 2024
Merged

Add stream cmd#10
calvinmvrk merged 3 commits intomainfrom
add-stream-cmd

Conversation

@calvinmvrk
Copy link
Copy Markdown
Contributor

Add cli cmd "stream" to parse response data

Screenshot 2024-11-07 at 16 33 41

@calvinmvrk calvinmvrk requested a review from josebalius November 7, 2024 23:01
Copy link
Copy Markdown

@josebalius josebalius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left a couple of suggestions

Comment on lines +62 to +64
// Print the final concatenated result
result := contentBuilder.String()
fmt.Println(result)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need result 😉

Comment on lines +47 to +48
// Skip this line if JSON is incomplete or malformed
continue
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually not sure if we want to silently skip this. I'd want to know if the stream is invalid somehow. You will have to deal with two special case:

  1. data: [DONE]
  2. data line being empty

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note; I see you made the updates to check for 1 and 2, but we are still silently skipping everything else. If we fail to parse any other data line it should fail and not continue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misunderstood. Will make a new pr to address

// Remove the "data: " prefix
line = strings.TrimPrefix(line, "data: ")
} else {
continue // skip lines without "data: "
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now it's fine, we may want to think in the future of how to handle this for other SSE even types.

@calvinmvrk calvinmvrk merged commit 62c0c3c into main Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants