From 9140541179e1c2fe855acf1c2743e1800fd5052e Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 20 Nov 2023 18:40:55 +0000 Subject: ~ | improve compatibility --- etc/tool/vercel.py | 4 +++- g4f/Provider/Chatgpt4Online.py | 4 +++- g4f/Provider/ChatgptAi.py | 4 +++- g4f/Provider/ChatgptDemo.py | 11 ++++++++--- g4f/Provider/ChatgptFree.py | 3 ++- g4f/Provider/ChatgptLogin.py | 13 ++++++++----- g4f/Provider/ChatgptX.py | 16 +++++++++++----- g4f/Provider/GptGod.py | 7 +++++-- g4f/Provider/Vercel.py | 3 +-- g4f/Provider/deprecated/CodeLinkAva.py | 4 +++- g4f/Provider/deprecated/Equing.py | 4 +++- g4f/Provider/deprecated/FastGpt.py | 6 ++++-- g4f/Provider/deprecated/Lockchat.py | 5 ++++- g4f/Provider/deprecated/Vitalentum.py | 4 +++- g4f/Provider/unfinished/ChatAiGpt.py | 7 +++++-- g4f/Provider/unfinished/MikuChat.py | 3 ++- setup.py | 2 +- 17 files changed, 69 insertions(+), 31 deletions(-) diff --git a/etc/tool/vercel.py b/etc/tool/vercel.py index 29856bb3..c5ce964c 100644 --- a/etc/tool/vercel.py +++ b/etc/tool/vercel.py @@ -24,7 +24,9 @@ def get_model_info() -> dict[str, Any]: models_regex = r'let .="\\n\\nHuman:\",r=(.+?),.=' for script in scripts: - if matches := re.findall(models_regex, script): + + matches = re.findall(models_regex, script) + if matches: models_str = matches[0] stop_sequences_regex = r"(?<=stopSequences:{value:\[)\D(?(.*?)<\/div>', response, - ): + ) + + if result: user_id = result.group(1) else: raise RuntimeError("No user id found") @@ -59,5 +62,7 @@ class ChatgptDemo(AsyncGeneratorProvider): async for line in response.content: if line.startswith(b"data: "): line = json.loads(line[6:-1]) - if chunk := line["choices"][0]["delta"].get("content"): + + chunk = line["choices"][0]["delta"].get("content") + if chunk: yield chunk \ No newline at end of file diff --git a/g4f/Provider/ChatgptFree.py b/g4f/Provider/ChatgptFree.py index 48d6c396..b9b25447 100644 --- a/g4f/Provider/ChatgptFree.py +++ b/g4f/Provider/ChatgptFree.py @@ -65,7 +65,8 @@ class ChatgptFree(AsyncProvider): raise RuntimeError("No post id found") cls._post_id = result.group(1) - if result := re.search(r'data-nonce="(.*?)"', response): + result = re.search(r'data-nonce="(.*?)"', response) + if result: cls._nonce = result.group(1) else: diff --git a/g4f/Provider/ChatgptLogin.py b/g4f/Provider/ChatgptLogin.py index 206e4a89..037e0a6e 100644 --- a/g4f/Provider/ChatgptLogin.py +++ b/g4f/Provider/ChatgptLogin.py @@ -45,10 +45,12 @@ class ChatgptLogin(AsyncGeneratorProvider): async with session.get(f"{cls.url}/chat/", proxy=proxy) as response: response.raise_for_status() response = await response.text() - if result := re.search( + result = re.search( r'