From 1f711f11caa00517e79fafc43cab1d74b35c7f64 Mon Sep 17 00:00:00 2001 From: "redev.rx" Date: Thu, 18 Jan 2024 14:28:09 +0700 Subject: [PATCH] fix sse --- lib/src/client/openai_client.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/src/client/openai_client.dart b/lib/src/client/openai_client.dart index 5894b6c..4b5c26b 100644 --- a/lib/src/client/openai_client.dart +++ b/lib/src/client/openai_client.dart @@ -299,16 +299,20 @@ class OpenAIClient extends OpenAIWrapper { // to be truncated, and at this time it needs to be concatenated // together with 'tmpData'. try { - final decodeData = json.decode('$tmpData$line'); + //add this + tmpData = tmpData + line; + + final decodeData = json.decode(tmpData); controller ..sink ..add(complete(decodeData)); + //when success + tmpData = ''; } catch (e) { // skip - log.log('unexpected exception: $e'); - log.log('tmpData=$tmpData\nline=$line'); + log.log('$e'); } - tmpData = ''; + // tmpData = ''; } } },