Merge pull request #1352 from nullstreak/main

HuggingChat: Strip leading whitespace from the first token in the stream
pull/1359/head
H Lohaus 10 months ago committed by GitHub
commit 8bdcb4bc62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()
response.raise_for_status()

Loading…
Cancel
Save