Skip to content

Conversation

@apascal07
Copy link
Collaborator

@apascal07 apascal07 commented May 30, 2024

Streamed responses need to be flushed otherwise they will all be returned at the same time at the end. Also, streaming relies on newline characters so response JSON cannot be pretty-printed.

ianlancetaylor and others added 2 commits May 29, 2024 17:53
Also rationalize the dotprompt package and make it easier to use.
@apascal07 apascal07 changed the title [Go] Fixed streaming. May 30, 2024
@apascal07 apascal07 changed the title [Go] [Draft] Fixed streaming. May 30, 2024
@apascal07 apascal07 requested a review from ianlancetaylor May 30, 2024 19:56
@apascal07 apascal07 marked this pull request as ready for review May 30, 2024 19:56
@apascal07 apascal07 enabled auto-merge (squash) May 30, 2024 20:01
stream.on('end', () => {
resolver(RunActionResponseSchema.parse(JSON.parse(buffer)));
});
stream.on('error', (err: Error) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this by any chance also fix #271?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No :( I didn't realize you filed an issue for this in JS but I've been running into the same issue with Go. Getting closer to fixing it but not quite there yet...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... you tried or guessing? I'm thinking it might...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't try with your case but the case I'm trying to fix similarly crashes the process due to schema validation and it didn't fix it. We're throwing an exception and it's not caught anywhere so it makes sense that it crashes it, no?

return err
}
if f, ok := w.(http.Flusher); ok {
f.Flush()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised Transfer-Encoding: chunked header is not required... but appears to be the case: https://stackoverflow.com/questions/26769626/send-a-chunked-http-response-from-a-go-server

@apascal07 apascal07 merged commit c16c17c into main May 30, 2024
@apascal07 apascal07 deleted the ap-go-stream branch May 30, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants