I am now using a forked version with this PR change,
but if it's not a problem, please put this fix in.
Thanks
Masaya
Issue
When retrieving data from openai on streaming, an error occurred when decoding JsonString to Map,
final decoded = jsonDecode(data) as Map<String, dynamic>; causing an unhandled exception.
It's weird because openai guarantees to return json, but if there are problems with the network environment, etc., it may not be json when it is received. I guess.
Version
dart_openai: ^4.0.0 # Actually happened when using it
dart_openai: ^5.0.0. # Reproducible by debugging
Modifications
What we actually want to do is to try-catch the process of decoding,
but since synchronous and asynchronous error handling is described in a complex way, I made the following modifications
Add async* to this function and replaced steram.listen with await for
Delete StreamController() and close()
When the Stream of OPenAI's API response is closed, this function ends, and when this function ends, the Stream returned by the function is closed, so Close processing is deleted
Replece onDone, onError with try-catch
Return yield* Stream.error() when error occurs
Test Results
Ensured that errors are handled without causing an unhandled exception
when an error occurs during decoding.
Hi,
I am now using a forked version with this PR change, but if it's not a problem, please put this fix in.
Thanks Masaya
Issue
When retrieving data from openai on streaming, an error occurred when decoding JsonString to Map, final decoded = jsonDecode(data) as Map<String, dynamic>; causing an unhandled exception.
It's weird because openai guarantees to return json, but if there are problems with the network environment, etc., it may not be json when it is received. I guess.
Version
dart_openai: ^4.0.0 # Actually happened when using it dart_openai: ^5.0.0. # Reproducible by debugging
Modifications
What we actually want to do is to try-catch the process of decoding, but since synchronous and asynchronous error handling is described in a complex way, I made the following modifications
Test Results
Ensured that errors are handled without causing an unhandled exception when an error occurs during decoding.