Skip to content

Commit

Permalink
Correctly set Accept header to text/event-stream for streaming
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Oct 23, 2024
1 parent 8d58dfa commit 8f16d03
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ func (r *CompletionService) NewStreaming(ctx context.Context, body CompletionNew
err error
)
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
opts = append(opts,
option.WithJSONSet("stream", true),
// Streaming response returns a text/event-stream content type. To comply with
// the SSE spec, we need to set the Accept header to text/event-stream explicitly.
option.WithHeader("Accept", "text/event-stream"),
)
path := "completions"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
return ssestream.NewStream[Completion](ssestream.NewDecoder(raw), err)
Expand Down

0 comments on commit 8f16d03

Please sign in to comment.