mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-19 03:25:32 +00:00
~ | Merge pull request #838
fix easychat stream : remove whitspace from data: and raise exception
This commit is contained in:
commit
19a13c240a
@ -75,16 +75,18 @@ class EasyChat(BaseProvider):
|
|||||||
if "choices" in json_data:
|
if "choices" in json_data:
|
||||||
yield json_data["choices"][0]["message"]["content"]
|
yield json_data["choices"][0]["message"]["content"]
|
||||||
else:
|
else:
|
||||||
yield Exception("No response from server")
|
raise Exception("No response from server")
|
||||||
else:
|
else:
|
||||||
|
|
||||||
for chunk in response.iter_lines():
|
for chunk in response.iter_lines():
|
||||||
if b"content" in chunk:
|
if b"content" in chunk:
|
||||||
splitData = chunk.decode().split("data: ")
|
splitData = chunk.decode().split("data:")
|
||||||
if len(splitData) > 1:
|
if len(splitData) > 1:
|
||||||
yield json.loads(splitData[1])["choices"][0]["delta"]["content"]
|
yield json.loads(splitData[1])["choices"][0]["delta"]["content"]
|
||||||
|
else:
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
yield Exception(f"Error {response.status_code} from server")
|
raise Exception(f"Error {response.status_code} from server : {response.reason}")
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user