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

Chat completions stream not working on flutter web #21

Closed
AlejandroArciniegas opened this issue Mar 20, 2023 · 2 comments
Closed

Chat completions stream not working on flutter web #21

AlejandroArciniegas opened this issue Mar 20, 2023 · 2 comments

Comments

@AlejandroArciniegas
Copy link
Contributor

Well I've been running circles around this issue all day. Perhaps someone here can help me. I'm trying to make a chatbot demo with the package. It works wonderfully until we test on flutter web. Instead of receiving the response word by word the browser seems to be buffering the data and then sending the whole response.

Is there a workaround? I've found that using dart:html could be a possible fix but I'm not sure.

The behavior I expect is to be able to get the ChatGPT response word by word.
image

@anasfik
Copy link
Owner

anasfik commented Mar 21, 2023

Hello, thank you for reaching out here!
can you update to 1.8.3 and confirm the issue if it still persist?

@AlejandroArciniegas
Copy link
Contributor Author

AlejandroArciniegas commented Mar 21, 2023

Hey thanks for answering so quickly. The behavior on 1.8.3 is the same. Testing on Chrome(web-javascript)

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.7.0, on Microsoft Windows [Version 10.0.22621.1265], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.1)
[√] VS Code (version 1.76.2)
[√] Connected device (4 available)
[√] HTTP Host Availability

! Doctor found issues in 1 category.

I was able to get the behavior I expected using a custom fetch client built around the fetch API.

There's a limitation on browsers with XHR, it won't support streams anytime soon and there's a forgotten debate on dart:http wether they will support fetch or not. Streamed responses are necessary for this type of apis.

Implementing it to be supported by this package would be awesome. Let me know If I can help with a PR. Would love to contribute.

It would probably just need to check if the platform is web then use custom FetchClient for postStream method in the client.dart file.

My team will most likely try to support this and fetch because our software has a heavy dependency on them. Let me know your toughts!

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

No branches or pull requests

2 participants