summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2023-12-16 20:18:38 +0100
committerGitHub <noreply@github.com>2023-12-16 20:18:38 +0100
commit8bdcb4bc62164a08709dc0a9c7f24a2bbc460565 (patch)
treeb2d5b7ef8701082f2901a41b004950e006932d7f /g4f
parentMerge pull request #1357 from hlohaus/docker2 (diff)
parentHuggingChat: Strip leading whitespace from the first token in the stream (diff)
downloadgpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.tar
gpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.tar.gz
gpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.tar.bz2
gpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.tar.lz
gpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.tar.xz
gpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.tar.zst
gpt4free-8bdcb4bc62164a08709dc0a9c7f24a2bbc460565.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/needs_auth/HuggingChat.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/g4f/Provider/needs_auth/HuggingChat.py b/g4f/Provider/needs_auth/HuggingChat.py
index 530069c0..41c938b4 100644
--- a/g4f/Provider/needs_auth/HuggingChat.py
+++ b/g4f/Provider/needs_auth/HuggingChat.py
@@ -47,14 +47,19 @@ class HuggingChat(AsyncGeneratorProvider):
"web_search": web_search
}
async with session.post(f"{cls.url}/conversation/{conversation_id}", json=send, proxy=proxy) as response:
+ first_token = True
async for line in response.content:
line = json.loads(line[:-1])
if "type" not in line:
raise RuntimeError(f"Response: {line}")
elif line["type"] == "stream":
- yield line["token"]
+ token = line["token"]
+ if first_token:
+ token = token.lstrip()
+ first_token = False
+ yield token
elif line["type"] == "finalAnswer":
break
async with session.delete(f"{cls.url}/conversation/{conversation_id}", proxy=proxy) as response:
- response.raise_for_status() \ No newline at end of file
+ response.raise_for_status()