Skip to content

Default ResponseHandler for Server Sent Event (SSE) #120

Answered by earthboundkid
galileilei asked this question in Ideas
Discussion options

You must be logged in to vote

The go-sse client already does a lot of the validation and backoff stuff you might want to use requests for. I think the solution might be to just use it with requests as a simple request builder. From their example:

client := sse.Client{
    Backoff: sse.Backoff{
        MaxRetries: -1,
    },
    // other settings...
}

body := whatever()
req, err := requests.URL("https://api.openai.com/...").BodyJSON(&body).Request(ctx)
if err != nil { /**/ }
conn := client.NewConnection(req)

conn.SubscribeMessages(/* callback */)

if err := conn.Connect(); !errors.Is(err, io.EOF) {
    // handle error
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@galileilei
Comment options

@earthboundkid
Comment options

@earthboundkid
Comment options

Answer selected by galileilei
@galileilei
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants