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

Web environment cannot obtain real-time data stream #1795

Closed
do-nothing opened this issue Apr 21, 2023 · 1 comment
Closed

Web environment cannot obtain real-time data stream #1795

do-nothing opened this issue Apr 21, 2023 · 1 comment
Labels
i: duplicate This issue or pull request already exists

Comments

@do-nothing
Copy link

Package

dio

Version

v5.1.1

Output of flutter doctor -v

[√] Flutter (Channel master, 3.10.0-10.0.pre.39, on Microsoft Windows [版本 10.0.18363.592], locale zh-CN)
    • Flutter version 3.10.0-10.0.pre.39 on channel master at C:\tools\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d186792c00 (2 hours ago), 2023-04-20 20:50:59 -0700
    • Engine revision 122c3b3820
    • Dart version 3.1.0 (build 3.1.0-26.0.dev)
    • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at C:\Users\John\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[√] Chrome - develop for the web
    • Chrome at C:\Users\John\AppData\Local\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.5.33530.505
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)

[√] IntelliJ IDEA Ultimate Edition (version 2023.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2023.1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart

[√] VS Code (version 1.77.3)
    • VS Code at C:\Users\John\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.62.0

[!] Proxy Configuration
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[√] Connected device (4 available)
    • sdk gphone x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
    • Windows (desktop)          • windows       • windows-x64    • Microsoft Windows [版本 10.0.18363.592]
    • Chrome (web)               • chrome        • web-javascript • Google Chrome 112.0.5615.50
    • Edge (web)                 • edge          • web-javascript • Microsoft Edge 112.0.1722.39

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Dart Version

Dart SDK version: 3.1.0-26.0.dev (dev) (Thu Apr 20 12:25:58 2023 -0700) on "windows_x64"

Steps to Reproduce

Future askAi(String text) async {
Response response = await dio.post(
'https://api.openai.com/v1/completions',
data: {
"model": "text-davinci-003",
"prompt": text,
"temperature": 0.6,
"max_tokens": 1024,
"stream": true,
},
options: Options(headers: {
'Authorization': 'Bearer ${Env.apiKey}',
'Content-Type': 'application/json'
}, responseType: ResponseType.stream),
);
response.data?.stream.listen((List data) {
String str = String.fromCharCodes(data);
print(str);
});
}

Expected Result

Use the "ResponseType. stream" method to call the OpenAI interface, hoping to obtain real-time responses from the OpenAI interface.

Using dio: ^ 5.1.1, it works normally in both Android and Windows environments, “response.data?.stream.listen((List data)” -- Multiple data can be received per second.

But not work in a web environment(Chrome 112.0.5615.50). It should not be a browser caching issue, as using the same interface, JS can receive stream data in real-time.

Actual Result

response.data?.stream.listen((List data)

only one data

It takes about a few tens of seconds to receive stream data, and only a large data packet can be get when completion, and the process cannot be get in real-time.

@do-nothing do-nothing added h: need triage This issue needs to be categorized s: bug Something isn't working labels Apr 21, 2023
@ueman ueman added s: feature This issue indicates a feature request and removed h: need triage This issue needs to be categorized s: bug Something isn't working labels Apr 22, 2023
@ueman
Copy link
Contributor

ueman commented Apr 22, 2023

Closing this as duplicate of #1740

@ueman ueman closed this as completed Apr 22, 2023
@AlexV525 AlexV525 added i: duplicate This issue or pull request already exists and removed s: feature This issue indicates a feature request labels Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants