remove whitspace from data: and raise exception

This commit is contained in:
Bagus Indrayana 2023-08-24 18:13:20 +08:00
parent 847843d120
commit e56f9b7c0d

View File

@ -75,16 +75,18 @@ class EasyChat(BaseProvider):
if "choices" in json_data:
yield json_data["choices"][0]["message"]["content"]
else:
yield Exception("No response from server")
raise Exception("No response from server")
else:
for chunk in response.iter_lines():
if b"content" in chunk:
splitData = chunk.decode().split("data: ")
splitData = chunk.decode().split("data:")
if len(splitData) > 1:
yield json.loads(splitData[1])["choices"][0]["delta"]["content"]
else:
yield Exception(f"Error {response.status_code} from server")
continue
else:
raise Exception(f"Error {response.status_code} from server : {response.reason}")
@classmethod