Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

bug: notify developer of invalid API key on the web #39

Closed
csells opened this issue Sep 14, 2024 · 3 comments
Closed

bug: notify developer of invalid API key on the web #39

csells opened this issue Sep 14, 2024 · 3 comments
Labels
blocked blocked on something outside this repo bug Something isn't working
Milestone

Comments

@csells
Copy link
Owner

csells commented Sep 14, 2024

On the web, it just hangs (bad).
<img width="200" src="https://github.com/user-attachments/assets/e3ea273e-4a10-4c75-9c2c-2ea51326d914"

On desktop, there's an error message (good):

On iOS, there's an error message (good):

On Android, there's an error message (good):

Combine this bug with this bug and it looks like a problem with error handle on the web.

@csells csells changed the title bug: notify developer of invalid API key bug: notify developer of invalid API key on the web Sep 14, 2024
@csells csells modified the milestones: beta, stable Oct 15, 2024
@csells csells added the bug Something isn't working label Oct 22, 2024
@csells
Copy link
Owner Author

csells commented Nov 23, 2024

OK. I've tracked this down to typical usage in the Flutter AI Toolkit implementation of the LLM providers, e.g. in the GeminiProvider:

    final response = contentStreamGenerator(content);
    await for (final chunk in response) {
      final text = chunk.text;
      if (text != null) yield text;
    }
  }

On not web, if there's an exception in contentStreamGenerator, then the exception propagates to the listen call upstream and it's reported to the user. On the web, however, things just hang, which is a known Dart bug: flutter/flutter#108866 (which is a closed dupe of still very open dart-lang/sdk#47764, but I don't know what DDC is and I do know what Web is, so...).

I can't use listen, since this is a single-subscriber stream and upstream needs to call listen (which can only be called once on a single-subscriber stream).

I can't use stream.forEach(processEach) because I can't call yield instead the processEach function (even if it's a closure) and the upstream needs the responses as they come in (so give that cool LLM streaming response effect).

So I'm happy to rewrite all my await for calls to work around this bug, but I have no idea how to rewrite them. And since the samples are going to be run in Debug and not Release mode, having the code correctly report errors in Debug mode is pretty important.

@munificent @kevmoo @khanhnwin thoughts?

@csells csells added the blocked blocked on something outside this repo label Nov 23, 2024
@kevmoo
Copy link

kevmoo commented Nov 23, 2024

DDC is the dev compiler. It's what runs when you do flutter run web -d chrome.

@csells
Copy link
Owner Author

csells commented Nov 24, 2024

@kevmoo was nice enough to grab a quick GVC with me and help me rewrite the code w/o await for as a work-around, which cleared up this bug and helped clear up another one (it turns out that exceptions are a pretty handy wait to help track down bugs -- who knew??).

I dropped the work around details into the original bug, which will hopefully be fixed one day but is no longer blocking the AI Toolkit: dart-lang/sdk#47764 (comment)

Thanks, Kev!

@csells csells closed this as completed in 0b1f3cc Nov 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked blocked on something outside this repo bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants