From 98d3304108de3e55c18f2af8a66a501541ec658b Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 22 Aug 2023 23:27:34 +0200 Subject: Improve providers with tests --- g4f/Provider/DfeHub.py | 1 + g4f/Provider/FastGpt.py | 2 +- g4f/Provider/H2o.py | 8 +++++--- g4f/Provider/V50.py | 5 +++-- g4f/Provider/Wewordle.py | 7 +------ g4f/Provider/You.py | 15 +++++++-------- testing/test_providers.py | 42 ++++++++++++++++++++++-------------------- 7 files changed, 40 insertions(+), 40 deletions(-) diff --git a/g4f/Provider/DfeHub.py b/g4f/Provider/DfeHub.py index 4093d0e4..5a7b22e1 100644 --- a/g4f/Provider/DfeHub.py +++ b/g4f/Provider/DfeHub.py @@ -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..cef209c9 100644 --- a/g4f/Provider/Wewordle.py +++ b/g4f/Provider/Wewordle.py @@ -21,11 +21,6 @@ class Wewordle(BaseProvider): 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 +40,7 @@ class Wewordle(BaseProvider): } data: dict[str, Any] = { "user": _user_id, - "messages": [{"role": "user", "content": base}], + "messages": messages, "subscriber": { "originalPurchaseDate": None, "originalApplicationVersion": None, diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py index 0d8114a8..cbd741ba 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,7 +29,11 @@ class You(BaseProvider): impersonate="chrome107", ) response.raise_for_status() - yield _parse_output(response.text) + 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]]): @@ -50,10 +55,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..fee79e20 100644 --- a/testing/test_providers.py +++ b/testing/test_providers.py @@ -3,50 +3,51 @@ from pathlib import Path 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 = judge(_provider) + print("Result:", result) + if _provider.working and not result: + failed_providers.append([_provider, result]) - results.append([_provider.__name__, expected_working, actual_working, match]) - - print("failed provider list") - for result in results: - if not result[3]: - print(result) + print("Failed providers:") + for _provider, result in failed_providers: + print(f"{_provider.__name__}: {result}") 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 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 + else _provider.model ) response = _provider.create_completion( model=model, - messages=[{"role": "user", "content": "Hello world!, plz yourself"}], + messages=[{"role": "user", "content": "Hello world!"}], stream=False, ) return "".join(response) @@ -59,9 +60,10 @@ def judge(_provider: type[BaseProvider]) -> bool: try: response = create_response(_provider) assert type(response) is str - return len(response) > 1 + return response except Exception as e: - print(e) + if logging: + print(e) return False -- cgit v1.2.3 From 69ca98ac85743edd76ac6ce49feb233cd5365099 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Thu, 24 Aug 2023 21:32:22 +0200 Subject: Improve provider list --- README.md | 51 +++++++++++++++++++++++++---------------------- g4f/Provider/AItianhu.py | 2 +- g4f/Provider/Acytoo.py | 8 ++++---- g4f/Provider/AiService.py | 2 +- g4f/Provider/DfeHub.py | 2 +- g4f/Provider/Wewordle.py | 8 ++++---- testing/test_providers.py | 33 ++++++++++++++++++++---------- tool/readme_table.py | 47 ++++++++++++++++++++++++------------------- 8 files changed, 88 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 39b368cc..22db26cc 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 5a7b22e1..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 diff --git a/g4f/Provider/Wewordle.py b/g4f/Provider/Wewordle.py index cef209c9..8e106716 100644 --- a/g4f/Provider/Wewordle.py +++ b/g4f/Provider/Wewordle.py @@ -10,12 +10,13 @@ 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, @@ -62,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/testing/test_providers.py b/testing/test_providers.py index fee79e20..6d3b62d8 100644 --- a/testing/test_providers.py +++ b/testing/test_providers.py @@ -1,5 +1,6 @@ import sys from pathlib import Path +from colorama import Fore sys.path.append(str(Path(__file__).parent.parent)) @@ -20,9 +21,14 @@ def main(): if _provider.working and not result: failed_providers.append([_provider, result]) - print("Failed providers:") - for _provider, result in failed_providers: - print(f"{_provider.__name__}: {result}") + print() + + if failed_providers: + print(f"{Fore.RED}Failed providers:\n") + for _provider, result in failed_providers: + print(f"{Fore.RED}{_provider.__name__}") + else: + print(f"{Fore.GREEN}All providers are working") def get_providers() -> list[type[BaseProvider]]: @@ -36,18 +42,21 @@ def get_providers() -> list[type[BaseProvider]]: 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.supports_gpt_35_turbo - else _provider.model - ) + 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!"}], + messages=[{"role": "user", "content": "Hello"}], stream=False, ) return "".join(response) @@ -57,9 +66,13 @@ def judge(_provider: type[BaseProvider]) -> bool: if _provider.needs_auth: return _provider.working + return test(_provider) + +def test(_provider: type[BaseProvider]) -> bool: try: response = create_response(_provider) assert type(response) is str + assert len(response) > 0 return response except Exception as e: if logging: 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] -- cgit v1.2.3 From 1f56c792220427b86ec7780a7a298d14f205b466 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Fri, 25 Aug 2023 00:32:13 +0200 Subject: Remove judge function --- testing/test_providers.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/testing/test_providers.py b/testing/test_providers.py index 6d3b62d8..c4fcbc0c 100644 --- a/testing/test_providers.py +++ b/testing/test_providers.py @@ -16,16 +16,16 @@ def main(): if _provider.needs_auth: continue print("Provider:", _provider.__name__) - result = judge(_provider) + result = test(_provider) print("Result:", result) if _provider.working and not result: - failed_providers.append([_provider, result]) + failed_providers.append(_provider) print() if failed_providers: print(f"{Fore.RED}Failed providers:\n") - for _provider, result in failed_providers: + for _provider in failed_providers: print(f"{Fore.RED}{_provider.__name__}") else: print(f"{Fore.GREEN}All providers are working") @@ -61,12 +61,6 @@ def create_response(_provider: type[BaseProvider]) -> str: ) return "".join(response) - -def judge(_provider: type[BaseProvider]) -> bool: - if _provider.needs_auth: - return _provider.working - - return test(_provider) def test(_provider: type[BaseProvider]) -> bool: try: -- cgit v1.2.3