diff --git a/README.md b/README.md index d78470e1..76c46ce5 100644 --- a/README.md +++ b/README.md @@ -185,30 +185,33 @@ if __name__ == "__main__": | Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth | | ------ | ------- | ------- | ----- | --------- | ------ | ---- | -| [www.aitianhu.com](https://www.aitianhu.com/api/chat-process) | g4f.Provider.AItianhu | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [chat.acytoo.com](https://chat.acytoo.com/api/completions) | g4f.Provider.Acytoo | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [aiservice.vercel.app](https://aiservice.vercel.app/api/chat/answer) | g4f.Provider.AiService | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [chat-gpt.org](https://chat-gpt.org/chat) | g4f.Provider.Aichat | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [ai.ls](https://ai.ls) | g4f.Provider.Ails | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [bard.google.com](https://bard.google.com) | g4f.Provider.Bard | ❌ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ | -| [bing.com](https://bing.com/chat) | g4f.Provider.Bing | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.Provider.ChatgptAi | ❌ | ✔️ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [chatgptlogin.ac](https://chatgptlogin.ac) | g4f.Provider.ChatgptLogin | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [deepai.org](https://deepai.org) | g4f.Provider.DeepAi | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [chat.dfehub.com](https://chat.dfehub.com/api/chat) | g4f.Provider.DfeHub | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [free.easychat.work](https://free.easychat.work) | g4f.Provider.EasyChat | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [forefront.com](https://forefront.com) | g4f.Provider.Forefront | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [chat.getgpt.world](https://chat.getgpt.world/) | g4f.Provider.GetGpt | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [gpt-gm.h2o.ai](https://gpt-gm.h2o.ai) | g4f.Provider.H2o | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [liaobots.com](https://liaobots.com) | g4f.Provider.Liaobots | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ✔️ | -| [supertest.lockchat.app](http://supertest.lockchat.app) | g4f.Provider.Lockchat | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [opchatgpts.net](https://opchatgpts.net) | g4f.Provider.Opchatgpts | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [backend.raycast.com](https://backend.raycast.com/api/v1/ai/chat_completions) | g4f.Provider.Raycast | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ | -| [theb.ai](https://theb.ai) | g4f.Provider.Theb | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | -| [play.vercel.ai](https://play.vercel.ai) | g4f.Provider.Vercel | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [wewordle.org](https://wewordle.org/gptapi/v1/android/turbo) | g4f.Provider.Wewordle | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [you.com](https://you.com) | g4f.Provider.You | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | -| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | g4f.Provider.Yqcloud | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [chat.acytoo.com](https://chat.acytoo.com/) | g4f.provider.Acytoo | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ | +| [chat-gpt.org](https://chat-gpt.org/chat) | g4f.provider.Aichat | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ | +| [ai.ls](https://ai.ls) | g4f.provider.Ails | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [bard.google.com](https://bard.google.com) | g4f.provider.Bard | ❌ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ | +| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.provider.ChatgptAi | ❌ | ✔️ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [deepai.org](https://deepai.org) | g4f.provider.DeepAi | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [free.easychat.work](https://free.easychat.work) | g4f.provider.EasyChat | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ | +| [next.eqing.tech](https://next.eqing.tech/) | g4f.provider.Equing | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ | +| [chat.getgpt.world](https://chat.getgpt.world/) | g4f.provider.GetGpt | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [gpt-gm.h2o.ai](https://gpt-gm.h2o.ai) | g4f.provider.H2o | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [raycast.com](https://raycast.com) | g4f.provider.Raycast | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ | +| [theb.ai](https://theb.ai) | g4f.provider.Theb | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ | +| [play.vercel.ai](https://play.vercel.ai) | g4f.provider.Vercel | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ | +| [wewordle.org](https://wewordle.org/) | g4f.provider.Wewordle | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [you.com](https://you.com) | g4f.provider.You | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | g4f.provider.Yqcloud | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ | +| [www.aitianhu.com](https://www.aitianhu.com/) | g4f.provider.AItianhu | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [aiservice.vercel.app](https://aiservice.vercel.app/) | g4f.provider.AiService | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [bing.com](https://bing.com/chat) | g4f.provider.Bing | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [chat.dfehub.com](https://chat.dfehub.com/) | g4f.provider.DfeHub | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [chat9.fastgpt.me](https://chat9.fastgpt.me/) | g4f.provider.FastGpt | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [forefront.com](https://forefront.com) | g4f.provider.Forefront | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [liaobots.com](https://liaobots.com) | g4f.provider.Liaobots | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ✔️ | +| [supertest.lockchat.app](http://supertest.lockchat.app) | g4f.provider.Lockchat | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | +| [p5.v50.ltd](https://p5.v50.ltd) | g4f.provider.V50 | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ | ### Other Models diff --git a/g4f/Provider/AItianhu.py b/g4f/Provider/AItianhu.py index e8e5714a..9f5440bc 100644 --- a/g4f/Provider/AItianhu.py +++ b/g4f/Provider/AItianhu.py @@ -7,7 +7,7 @@ from .base_provider import BaseProvider class AItianhu(BaseProvider): - url = "https://www.aitianhu.com/api/chat-process" + url = "https://www.aitianhu.com/" working = False supports_gpt_35_turbo = True diff --git a/g4f/Provider/Acytoo.py b/g4f/Provider/Acytoo.py index 2edd9efd..975e914b 100644 --- a/g4f/Provider/Acytoo.py +++ b/g4f/Provider/Acytoo.py @@ -7,12 +7,13 @@ from .base_provider import BaseProvider class Acytoo(BaseProvider): - url = "https://chat.acytoo.com/api/completions" + url = "https://chat.acytoo.com/" working = True supports_gpt_35_turbo = True - @staticmethod + @classmethod def create_completion( + cls, model: str, messages: list[dict[str, str]], stream: bool, @@ -21,8 +22,7 @@ class Acytoo(BaseProvider): headers = _create_header() payload = _create_payload(messages, kwargs.get('temperature', 0.5)) - url = "https://chat.acytoo.com/api/completions" - response = requests.post(url=url, headers=headers, json=payload) + response = requests.post("{cls.url}api/completions", headers=headers, json=payload) response.raise_for_status() response.encoding = "utf-8" yield response.text diff --git a/g4f/Provider/AiService.py b/g4f/Provider/AiService.py index 2c0d5de2..3453bfd9 100644 --- a/g4f/Provider/AiService.py +++ b/g4f/Provider/AiService.py @@ -5,7 +5,7 @@ from .base_provider import BaseProvider class AiService(BaseProvider): - url = "https://aiservice.vercel.app/api/chat/answer" + url = "https://aiservice.vercel.app/" working = False supports_gpt_35_turbo = True diff --git a/g4f/Provider/DfeHub.py b/g4f/Provider/DfeHub.py index 4093d0e4..6f96ec7a 100644 --- a/g4f/Provider/DfeHub.py +++ b/g4f/Provider/DfeHub.py @@ -9,7 +9,7 @@ from .base_provider import BaseProvider class DfeHub(BaseProvider): - url = "https://chat.dfehub.com/api/chat" + url = "https://chat.dfehub.com/" supports_stream = True supports_gpt_35_turbo = True @@ -50,6 +50,7 @@ class DfeHub(BaseProvider): "https://chat.dfehub.com/api/openai/v1/chat/completions", headers=headers, json=json_data, + timeout=3 ) for chunk in response.iter_lines(): diff --git a/g4f/Provider/FastGpt.py b/g4f/Provider/FastGpt.py index 950abab1..3c5a4420 100644 --- a/g4f/Provider/FastGpt.py +++ b/g4f/Provider/FastGpt.py @@ -6,7 +6,7 @@ from ..typing import Any, CreateResult class FastGpt(ABC): url: str = 'https://chat9.fastgpt.me/' - working = True + working = False needs_auth = False supports_stream = True supports_gpt_35_turbo = True diff --git a/g4f/Provider/H2o.py b/g4f/Provider/H2o.py index f9b799bb..305a0bbf 100644 --- a/g4f/Provider/H2o.py +++ b/g4f/Provider/H2o.py @@ -11,6 +11,7 @@ class H2o(BaseProvider): url = "https://gpt-gm.h2o.ai" working = True supports_stream = True + model = "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-40b-v1" @staticmethod def create_completion( @@ -47,8 +48,9 @@ class H2o(BaseProvider): "https://gpt-gm.h2o.ai/conversation", headers=headers, json=data, - ) - conversation_id = response.json()["conversationId"] + ).json() + if "conversationId" not in response: + return data = { "inputs": conversation, @@ -71,7 +73,7 @@ class H2o(BaseProvider): } response = session.post( - f"https://gpt-gm.h2o.ai/conversation/{conversation_id}", + f"https://gpt-gm.h2o.ai/conversation/{response['conversationId']}", headers=headers, json=data, ) diff --git a/g4f/Provider/V50.py b/g4f/Provider/V50.py index 125dd7c5..765f73bd 100644 --- a/g4f/Provider/V50.py +++ b/g4f/Provider/V50.py @@ -8,7 +8,7 @@ class V50(BaseProvider): supports_gpt_35_turbo = True supports_stream = False needs_auth = False - working = True + working = False @staticmethod def create_completion( @@ -46,7 +46,8 @@ class V50(BaseProvider): } response = requests.post("https://p5.v50.ltd/api/chat-process", json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {}) - yield response.text + if "https://fk1.v50.ltd" not in response.text: + yield response.text @classmethod @property diff --git a/g4f/Provider/Wewordle.py b/g4f/Provider/Wewordle.py index f7f47ee0..8e106716 100644 --- a/g4f/Provider/Wewordle.py +++ b/g4f/Provider/Wewordle.py @@ -10,22 +10,18 @@ from .base_provider import BaseProvider class Wewordle(BaseProvider): - url = "https://wewordle.org/gptapi/v1/android/turbo" + url = "https://wewordle.org/" working = True supports_gpt_35_turbo = True - @staticmethod + @classmethod def create_completion( + cls, model: str, messages: list[dict[str, str]], stream: bool, **kwargs: Any, ) -> CreateResult: - base = "" - - for message in messages: - base += "%s: %s\n" % (message["role"], message["content"]) - base += "assistant:" # randomize user id and app id _user_id = "".join( random.choices(f"{string.ascii_lowercase}{string.digits}", k=16) @@ -45,7 +41,7 @@ class Wewordle(BaseProvider): } data: dict[str, Any] = { "user": _user_id, - "messages": [{"role": "user", "content": base}], + "messages": messages, "subscriber": { "originalPurchaseDate": None, "originalApplicationVersion": None, @@ -67,8 +63,7 @@ class Wewordle(BaseProvider): }, } - url = "https://wewordle.org/gptapi/v1/android/turbo" - response = requests.post(url, headers=headers, data=json.dumps(data)) + response = requests.post(f"{cls.url}gptapi/v1/android/turbo", headers=headers, data=json.dumps(data)) response.raise_for_status() _json = response.json() if "message" in _json: diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py index a8de7dec..7ea699a2 100644 --- a/g4f/Provider/You.py +++ b/g4f/Provider/You.py @@ -1,5 +1,6 @@ import re import urllib.parse +import json from curl_cffi import requests @@ -28,8 +29,12 @@ class You(BaseProvider): impersonate="chrome107", ) response.raise_for_status() - yield _parse_output(response.text).encode().decode("unicode_escape") - + + start = 'data: {"youChatToken": ' + for line in response.content.splitlines(): + line = line.decode('utf-8') + if line.startswith(start): + yield json.loads(line[len(start): -1]) def _create_url_param(messages: list[dict[str, str]], history: list[dict[str, str]]): prompt = "" @@ -53,10 +58,4 @@ def _create_header(): return { "accept": "text/event-stream", "referer": "https://you.com/search?fromSearchBar=true&tbm=youchat", - } - - -def _parse_output(output: str) -> str: - regex = r"^data:\s{\"youChatToken\": \"(.*)\"}$" - tokens = [token for token in re.findall(regex, output, re.MULTILINE)] - return "".join(tokens) + } \ No newline at end of file diff --git a/testing/test_providers.py b/testing/test_providers.py index a5c6f87b..c4fcbc0c 100644 --- a/testing/test_providers.py +++ b/testing/test_providers.py @@ -1,67 +1,76 @@ import sys from pathlib import Path +from colorama import Fore sys.path.append(str(Path(__file__).parent.parent)) -from g4f import BaseProvider, models, provider +from g4f import BaseProvider, models, Provider +logging = False def main(): providers = get_providers() - results: list[list[str | bool]] = [] + failed_providers = [] for _provider in providers: - print("start", _provider.__name__) - actual_working = judge(_provider) - expected_working = _provider.working - match = actual_working == expected_working + if _provider.needs_auth: + continue + print("Provider:", _provider.__name__) + result = test(_provider) + print("Result:", result) + if _provider.working and not result: + failed_providers.append(_provider) - results.append([_provider.__name__, expected_working, actual_working, match]) + print() - print("failed provider list") - for result in results: - if not result[3]: - print(result) + if failed_providers: + print(f"{Fore.RED}Failed providers:\n") + for _provider in failed_providers: + print(f"{Fore.RED}{_provider.__name__}") + else: + print(f"{Fore.GREEN}All providers are working") def get_providers() -> list[type[BaseProvider]]: - provider_names = dir(provider) + provider_names = dir(Provider) ignore_names = [ "base_provider", - "BaseProvider", + "BaseProvider" ] provider_names = [ provider_name for provider_name in provider_names if not provider_name.startswith("__") and provider_name not in ignore_names ] - return [getattr(provider, provider_name) for provider_name in provider_names] + return [getattr(Provider, provider_name) for provider_name in sorted(provider_names)] def create_response(_provider: type[BaseProvider]) -> str: - model = ( - models.gpt_35_turbo.name - if _provider is not provider.H2o - else models.falcon_7b.name - ) + if _provider.supports_gpt_35_turbo: + model = models.gpt_35_turbo.name + elif _provider.supports_gpt_4: + model = models.gpt_4 + elif hasattr(_provider, "model"): + model = _provider.model + else: + model = None response = _provider.create_completion( model=model, - messages=[{"role": "user", "content": "Hello world!, plz yourself"}], + messages=[{"role": "user", "content": "Hello"}], stream=False, ) return "".join(response) - -def judge(_provider: type[BaseProvider]) -> bool: - if _provider.needs_auth: - return _provider.working - + +def test(_provider: type[BaseProvider]) -> bool: try: response = create_response(_provider) assert type(response) is str - return len(response) > 1 + assert len(response) > 0 + return response except Exception as e: - print(e) + if logging: + print(e) return False diff --git a/tool/readme_table.py b/tool/readme_table.py index 10735ba0..b578b9ca 100644 --- a/tool/readme_table.py +++ b/tool/readme_table.py @@ -7,7 +7,7 @@ sys.path.append(str(Path(__file__).parent.parent)) from g4f import models, Provider from g4f.Provider.base_provider import BaseProvider - +from testing.test_providers import test def main(): print_providers() @@ -21,25 +21,30 @@ def print_providers(): "| ------ | ------- | ------- | ----- | --------- | ------ | ---- |", ] providers = get_providers() - for _provider in providers: - netloc = urlparse(_provider.url).netloc - website = f"[{netloc}]({_provider.url})" - - provider_name = f"g4f.provider.{_provider.__name__}" - - has_gpt_35 = "✔️" if _provider.supports_gpt_35_turbo else "❌" - has_gpt_4 = "✔️" if _provider.supports_gpt_4 else "❌" - stream = "✔️" if _provider.supports_stream else "❌" - status = ( - "![Active](https://img.shields.io/badge/Active-brightgreen)" - if _provider.working - else "![Inactive](https://img.shields.io/badge/Inactive-red)" - ) - auth = "✔️" if _provider.needs_auth else "❌" - - lines.append( - f"| {website} | {provider_name} | {has_gpt_35} | {has_gpt_4} | {stream} | {status} | {auth} |" - ) + for is_working in (True, False): + for _provider in providers: + if is_working != _provider.working: + continue + netloc = urlparse(_provider.url).netloc + website = f"[{netloc}]({_provider.url})" + + provider_name = f"g4f.provider.{_provider.__name__}" + + has_gpt_35 = "✔️" if _provider.supports_gpt_35_turbo else "❌" + has_gpt_4 = "✔️" if _provider.supports_gpt_4 else "❌" + stream = "✔️" if _provider.supports_stream else "❌" + if _provider.working: + if test(_provider): + status = '![Active](https://img.shields.io/badge/Active-brightgreen)' + else: + status = '![Unknown](https://img.shields.io/badge/Unknown-grey)' + else: + status = '![Inactive](https://img.shields.io/badge/Inactive-red)' + auth = "✔️" if _provider.needs_auth else "❌" + + lines.append( + f"| {website} | {provider_name} | {has_gpt_35} | {has_gpt_4} | {stream} | {status} | {auth} |" + ) print("\n".join(lines)) @@ -79,6 +84,8 @@ def print_models(): _models = get_models() for model in _models: + if model.best_provider.__name__ not in provider_urls: + continue split_name = re.split(r":|/", model.name) name = split_name[-1]