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

Expo: Streamed response buffers first 512 characters #3946

Closed
matthiasbayer opened this issue Dec 2, 2024 · 4 comments · Fixed by #3950
Closed

Expo: Streamed response buffers first 512 characters #3946

matthiasbayer opened this issue Dec 2, 2024 · 4 comments · Fixed by #3950
Labels
docs Improvements or additions to documentation

Comments

@matthiasbayer
Copy link

matthiasbayer commented Dec 2, 2024

Description

Problem
The streamed response on iOS feels delayed and choppy.

Context
When streaming the LLM response from the API endpoint back to the iOS app, the first 512 characters will be buffered by the iOS native layer. This behavior apparently can't be configured, leaving it up to the callsite to work around this issue by supplying a content-type header that causes iOS to skip the buffering.

More technical context can be found this issue: expo/expo#32950

I'm not sure if a fix should be included in the code examples in the docs, or if a warning/note somewhere in the docs is enough. The header isn't strictly necessary to get the examples working, but greatly improves the UX and this behavior is really hard to debug. Another possibility to address this is to make a change to the toDataStreamResponse function and always set that Content-Type header, but I have not enough context to judge the impact and possible side-effects of such a change.

Solution
Explicitly add an HTTP header that doesn't trigger content buffering, e.g. Content-Type: application/octet-stream

Pull Request
Happy to create a pull request with either documentation or code changes depending on if and how this should be fixed (see additional context above).

Code example

https://github.com/matthiasbayer/expo-ai-sdk

return result.toDataStreamResponse({
  headers: {
    'Content-Type': 'application/octet-stream',
  }
});

AI provider

4.0.9

Additional context

No response

@matthiasbayer matthiasbayer added the bug Something isn't working label Dec 2, 2024
@lgrammel lgrammel added docs Improvements or additions to documentation and removed bug Something isn't working labels Dec 2, 2024
@lgrammel
Copy link
Collaborator

lgrammel commented Dec 2, 2024

CC @nicoalbanese wdyt about adding this to the expo guide?

@nicoalbanese
Copy link
Contributor

Thanks @matthiasbayer! Will test and add to the guide.

@matthiasbayer
Copy link
Author

Awesome! Let me know if I can help with anything regarding the reproduction.

@nicoalbanese
Copy link
Contributor

@lgrammel updated the guide here: #3950

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants