diff options
author | AndPim4912 <52836885+AndPim4912@users.noreply.github.com> | 2023-10-23 14:10:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-23 14:10:28 +0200 |
commit | 8d7ad98fcb314453c01f6dcd4bfe59016efd78ce (patch) | |
tree | 4d39804e1aa1724560e1688f0b6d4c124b9771c7 /g4f/Provider/deprecated/EasyChat.py | |
parent | Refactor API initialization to accept a list of ignored providers. (diff) | |
parent | Debug config in api (diff) | |
download | gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.gz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.bz2 gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.lz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.xz gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.tar.zst gpt4free-8d7ad98fcb314453c01f6dcd4bfe59016efd78ce.zip |
Diffstat (limited to 'g4f/Provider/deprecated/EasyChat.py')
-rw-r--r-- | g4f/Provider/deprecated/EasyChat.py | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/g4f/Provider/deprecated/EasyChat.py b/g4f/Provider/deprecated/EasyChat.py index ffe9a785..bd49c09c 100644 --- a/g4f/Provider/deprecated/EasyChat.py +++ b/g4f/Provider/deprecated/EasyChat.py @@ -30,7 +30,7 @@ class EasyChat(BaseProvider): "https://chat4.fastgpt.me", "https://gxos1h1ddt.fastgpt.me" ] - + server = active_servers[kwargs.get("active_server", random.randint(0, 5))] headers = { "authority" : f"{server}".replace("https://", ""), @@ -68,30 +68,26 @@ class EasyChat(BaseProvider): response = session.post(f"{server}/api/openai/v1/chat/completions", headers=headers, json=json_data, stream=stream) - - if response.status_code == 200: - - if stream == False: - json_data = response.json() - - if "choices" in json_data: - yield json_data["choices"][0]["message"]["content"] - else: - raise Exception("No response from server") - + + if response.status_code != 200: + raise Exception(f"Error {response.status_code} from server : {response.reason}") + if not stream: + json_data = response.json() + + if "choices" in json_data: + yield json_data["choices"][0]["message"]["content"] else: + raise Exception("No response from server") + + else: - for chunk in response.iter_lines(): + for chunk in response.iter_lines(): - if b"content" in chunk: - splitData = chunk.decode().split("data:") - - if len(splitData) > 1: - yield json.loads(splitData[1])["choices"][0]["delta"]["content"] - else: - continue - else: - raise Exception(f"Error {response.status_code} from server : {response.reason}") + if b"content" in chunk: + splitData = chunk.decode().split("data:") + + if len(splitData) > 1: + yield json.loads(splitData[1])["choices"][0]["delta"]["content"] @classmethod |