summaryrefslogtreecommitdiffstats
path: root/g4f/Provider
diff options
context:
space:
mode:
authorCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-09 20:53:31 +0200
committerCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-09 20:53:31 +0200
commit58c45522ea4f94f90c3ebbf350eba0b5715848ae (patch)
tree4d4a94c33fd41da0f2ab9c325df0f0274aa53c98 /g4f/Provider
parentMerge remote-tracking branch 'origin/main' (diff)
downloadgpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.tar
gpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.tar.gz
gpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.tar.bz2
gpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.tar.lz
gpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.tar.xz
gpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.tar.zst
gpt4free-58c45522ea4f94f90c3ebbf350eba0b5715848ae.zip
Diffstat (limited to 'g4f/Provider')
-rw-r--r--g4f/Provider/Aivvm.py42
-rw-r--r--g4f/Provider/DeepAi.py5
2 files changed, 27 insertions, 20 deletions
diff --git a/g4f/Provider/Aivvm.py b/g4f/Provider/Aivvm.py
index 1ba6d6f1..ac15ac16 100644
--- a/g4f/Provider/Aivvm.py
+++ b/g4f/Provider/Aivvm.py
@@ -3,6 +3,7 @@ import requests
from .base_provider import BaseProvider
from ..typing import CreateResult
+from json import dumps
# to recreate this easily, send a post request to https://chat.aivvm.com/api/models
models = {
@@ -35,20 +36,6 @@ class Aivvm(BaseProvider):
elif model not in models:
raise ValueError(f"Model is not supported: {model}")
- headers = {
- "accept" : "*/*",
- "accept-language" : "hu-HU,hu;q=0.9,en-US;q=0.8,en;q=0.7",
- "content-type" : "application/json",
- "sec-ch-ua" : "\"Kuki\";v=\"116\", \"Not)A;Brand\";v=\"24\", \"Pici Pocoro\";v=\"102\"",
- "sec-ch-ua-mobile" : "?0",
- "sec-ch-ua-platform": "\"Bandóz\"",
- "sec-fetch-dest" : "empty",
- "sec-fetch-mode" : "cors",
- "sec-fetch-site" : "same-origin",
- "Referer" : "https://chat.aivvm.com/",
- "Referrer-Policy" : "same-origin",
- }
-
json_data = {
"model" : models[model],
"messages" : messages,
@@ -57,12 +44,29 @@ class Aivvm(BaseProvider):
"temperature" : kwargs.get("temperature", 0.7)
}
- response = requests.post(
- "https://chat.aivvm.com/api/chat", headers=headers, json=json_data, stream=True)
+ headers = {
+ "accept" : "text/event-stream",
+ "accept-language" : "en-US,en;q=0.9",
+ "content-type" : "application/json",
+ "content-length" : str(len(dumps(json_data))),
+ "sec-ch-ua" : "\"Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"",
+ "sec-ch-ua-mobile" : "?0",
+ "sec-ch-ua-platform": "\"Windows\"",
+ "sec-fetch-dest" : "empty",
+ "sec-fetch-mode" : "cors",
+ "sec-fetch-site" : "same-origin",
+ "sec-gpc" : "1",
+ "referrer" : "https://chat.aivvm.com/"
+ }
+
+ response = requests.post("https://chat.aivvm.com/api/chat", headers=headers, json=json_data, stream=True)
response.raise_for_status()
- for chunk in response.iter_content(chunk_size=None):
- yield chunk.decode('utf-8')
+ for chunk in response.iter_content():
+ try:
+ yield chunk.decode("utf-8")
+ except UnicodeDecodeError:
+ yield chunk.decode("unicode-escape")
@classmethod
@property
@@ -74,4 +78,4 @@ class Aivvm(BaseProvider):
('temperature', 'float'),
]
param = ', '.join([': '.join(p) for p in params])
- return f'g4f.provider.{cls.__name__} supports: ({param})' \ No newline at end of file
+ return f'g4f.provider.{cls.__name__} supports: ({param})'
diff --git a/g4f/Provider/DeepAi.py b/g4f/Provider/DeepAi.py
index bac3e3fe..9a4f922c 100644
--- a/g4f/Provider/DeepAi.py
+++ b/g4f/Provider/DeepAi.py
@@ -65,7 +65,10 @@ f = function () {
response.raise_for_status()
async for stream in response.content.iter_any():
if stream:
- yield stream.decode()
+ try:
+ yield stream.decode("utf-8")
+ except UnicodeDecodeError:
+ yield stream.decode("unicode-escape")
def get_api_key(user_agent: str):