From 356206bccd28fcad0b4f1a707c67f1700bae9093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90inh=20Va=CC=86n=20Nam?= Date: Tue, 21 Nov 2023 23:59:58 +0700 Subject: [PATCH] Fix sse bad state close --- lib/src/client/openai_client.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/client/openai_client.dart b/lib/src/client/openai_client.dart index 1131409..f692441 100644 --- a/lib/src/client/openai_client.dart +++ b/lib/src/client/openai_client.dart @@ -273,6 +273,8 @@ class OpenAIClient extends OpenAIWrapper { final mData = data.substring(6); if (mData.startsWith("[DONE]")) { log.log("stream response is done"); + controller.done; + controller.close(); return; } @@ -283,8 +285,6 @@ class OpenAIClient extends OpenAIWrapper { controller ..sink ..add(complete(jsonMap[jsonMap.keys.last])); - - controller.close(); } else { log.log("stream response invalid try regenerate"); log.log("last json error :$mData");