Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly set Accept header to text/event-stream for completion streaming #94

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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...)
mathetake marked this conversation as resolved.
Show resolved Hide resolved
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