Skip to content

add NewClientFromReq method to allow streaming any kind of requests#164

Open
radiantspace wants to merge 1 commit intor3labs:masterfrom
radiantspace:patch-1
Open

add NewClientFromReq method to allow streaming any kind of requests#164
radiantspace wants to merge 1 commit intor3labs:masterfrom
radiantspace:patch-1

Conversation

@radiantspace
Copy link

@radiantspace radiantspace commented Jun 3, 2023

Allows making sse clients from any kind of requests, not just GET.

I needed that for streaming responses from OpenAI like this:

req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.openai.com/v1/chat/completions", bytes.NewBuffer(body))
if err != nil {
    return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+a.authToken)

client := sse.NewClientFromReq(req)

...

Closes #153

Allows making sse clients from any kind of requests, not just GET
Comment on lines +309 to +310
if c.Request != nil {
} else {

Choose a reason for hiding this comment

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

Suggested change
if c.Request != nil {
} else {
if c.Request == nil {

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.

Feature Request: Support non-GET method and request body in the sse client

2 participants