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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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