Skip to content

Specify a "Content-Type" header in response streams so that Cloudflar…#305

Open
ShaunMaher wants to merge 1 commit intomicrosoft:mainfrom
ShaunMaher:stream_responses_behind_cloudflared
Open

Specify a "Content-Type" header in response streams so that Cloudflar…#305
ShaunMaher wants to merge 1 commit intomicrosoft:mainfrom
ShaunMaher:stream_responses_behind_cloudflared

Conversation

@ShaunMaher
Copy link

By default, the upstream "ai" module (https://github.com/vercel/ai/) is returning the response from the Azure OpenAI API with a "text/plain" Content-Type. If your azurechat instance is hosted behind a cloudflared tunnel (maybe just Cloudflare in general, I haven't tested this), the response will be buffered by cloudflare(d) and returned all at once.

Other than not being the expected experience, this can lead to timeouts (cloudflare default = 100s) if the response is long or slow to generate. If the response is streamed, there should be enough data flowing to avoid this timeout.

Cloudflared looks for the Content-Type response header and if it is "text/event-stream" it will know not to buffer the response but to send it immediately to the requestor. Reference.

…e / cloudflared (tunnel) know to stream the responses rather than buffer them.
@ShaunMaher
Copy link
Author

@microsoft-github-policy-service agree [company="Orro"]

@ShaunMaher
Copy link
Author

@microsoft-github-policy-service agree company="Orro"

Copy link

@keith-oak keith-oak left a comment

Choose a reason for hiding this comment

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

Can confirm this works well even with default Infra.

@davidxw davidxw added the enhancement New feature or request label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants