summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/MyShell.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2023-11-16 18:54:59 +0100
committerGitHub <noreply@github.com>2023-11-16 18:54:59 +0100
commitaa12716974f9ff4eeaed2c012e39e9a06c2f311c (patch)
tree99ae8d31b855792124403fadce9b19cf8ac1f5f9 /g4f/Provider/MyShell.py
parentUpdate MyShell.py (diff)
downloadgpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.tar
gpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.tar.gz
gpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.tar.bz2
gpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.tar.lz
gpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.tar.xz
gpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.tar.zst
gpt4free-aa12716974f9ff4eeaed2c012e39e9a06c2f311c.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/MyShell.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/g4f/Provider/MyShell.py b/g4f/Provider/MyShell.py
index dc3934fb..ac3290b5 100644
--- a/g4f/Provider/MyShell.py
+++ b/g4f/Provider/MyShell.py
@@ -65,6 +65,7 @@ window.reader = response.body.getReader();
driver.execute_script(script.replace("{body}", json.dumps(data)))
script = """
chunk = await window.reader.read();
+if (chunk['done']) return null;
text = await (new Response(chunk['value']).text());
content = '';
text.split('\\n').forEach((line, index) => {
@@ -79,8 +80,12 @@ text.split('\\n').forEach((line, index) => {
});
return content;
"""
- while chunk := driver.execute_script(script):
- yield chunk
+ while True:
+ chunk = driver.execute_script(script):
+ if chunk:
+ yield chunk
+ elif chunk != "":
+ break
finally:
driver.close()
if not browser: