返回提交历史
Modified
g4f/Provider/needs_auth/HuggingChat.py
+7
-2
XFEstudio/gpt4free
HuggingChat: Strip leading whitespace from the first token in the stream
For some reason first token from the stream on HuggingChat always starts with a whitespace. This commit strips the leading whitespace from the first token in the stream to fix this issue.
f554018d
代码差异
1 个文件
+7
-2
@@ -47,14 +47,19 @@ class HuggingChat(AsyncGeneratorProvider):
47
47
"web_search": web_search
48
48
}
49
49
async with session.post(f"{cls.url}/conversation/{conversation_id}", json=send, proxy=proxy) as response:
50
first_token = True
50
51
async for line in response.content:
51
52
line = json.loads(line[:-1])
52
53
if "type" not in line:
53
54
raise RuntimeError(f"Response: {line}")
54
55
elif line["type"] == "stream":
55
yield line["token"]
56
token = line["token"]
57
if first_token:
58
token = token.lstrip()
59
first_token = False
60
yield token
56
61
elif line["type"] == "finalAnswer":
57
62
break
58
63
59
64
async with session.delete(f"{cls.url}/conversation/{conversation_id}", proxy=proxy) as response:
60
response.raise_for_status()
65
response.raise_for_status()