summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/deprecated/EasyChat.py
diff options
context:
space:
mode:
authorⲘrṨhส∂ow <71973368+MrShadowDev@users.noreply.github.com>2023-10-23 09:46:25 +0200
committerGitHub <noreply@github.com>2023-10-23 09:46:25 +0200
commit3982f39424ea037aca1086d45c6f657b4bfc457c (patch)
tree987290c5dc5822cb0197e789df68488536b1637c /g4f/Provider/deprecated/EasyChat.py
parent~ | g4f `v-0.1.7.5` (diff)
downloadgpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.gz
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.bz2
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.lz
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.xz
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.tar.zst
gpt4free-3982f39424ea037aca1086d45c6f657b4bfc457c.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/deprecated/EasyChat.py40
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