From ebb72b82495e4cd43d936175081c54ccca81877c Mon Sep 17 00:00:00 2001 From: Hugo Aguirre Date: Fri, 15 Nov 2024 16:26:16 -0600 Subject: [PATCH] [Go] Update flow streaming protocol to SSE --- go/genkit/servers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/genkit/servers.go b/go/genkit/servers.go index 4453c25ab..e57872eb5 100644 --- a/go/genkit/servers.go +++ b/go/genkit/servers.go @@ -380,12 +380,12 @@ func nonDurableFlowHandler(f flow) func(http.ResponseWriter, *http.Request) erro return err } var callback streamingCallback[json.RawMessage] - if stream { + if r.Header.Get("Accept") == "text/event-stream" || stream { w.Header().Set("Content-Type", "text/plain") w.Header().Set("Transfer-Encoding", "chunked") // Stream results are newline-separated JSON. callback = func(ctx context.Context, msg json.RawMessage) error { - _, err := fmt.Fprintf(w, "%s\n", msg) + _, err := fmt.Fprintf(w, "data: %s\n\n", msg) if err != nil { return err } @@ -402,7 +402,7 @@ func nonDurableFlowHandler(f flow) func(http.ResponseWriter, *http.Request) erro } // Responses for non-streaming, non-durable flows are passed back // with the flow result stored in a field called "result." - _, err = fmt.Fprintf(w, `{"result": %s}\n`, out) + _, err = fmt.Fprintf(w, `data: {"result": %s}\n`, out) return err } }