diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-01-02 01:10:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 01:10:31 +0100 |
commit | b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366 (patch) | |
tree | 6cd09fb2eb4c144e28a82759a2a9a2fa7f30d311 /etc/testing | |
parent | Merge pull request #1414 from hlohaus/lia (diff) | |
parent | Fix markdown replace (diff) | |
download | gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.gz gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.bz2 gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.lz gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.xz gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.zst gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.zip |
Diffstat (limited to 'etc/testing')
-rw-r--r-- | etc/testing/_providers.py | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/etc/testing/_providers.py b/etc/testing/_providers.py index 0194318c..947fe7a0 100644 --- a/etc/testing/_providers.py +++ b/etc/testing/_providers.py @@ -4,24 +4,22 @@ from colorama import Fore, Style sys.path.append(str(Path(__file__).parent.parent)) -from g4f import BaseProvider, models, Provider - -logging = False +from g4f import Provider, ProviderType, models +from g4f.Provider import __providers__ def main(): providers = get_providers() failed_providers = [] - for _provider in providers: - if _provider.needs_auth: + for provider in providers: + if provider.needs_auth: continue - print("Provider:", _provider.__name__) - result = test(_provider) + print("Provider:", provider.__name__) + result = test(provider) print("Result:", result) - if _provider.working and not result: - failed_providers.append(_provider) - + if provider.working and not result: + failed_providers.append(provider) print() if failed_providers: @@ -32,38 +30,29 @@ def main(): print(f"{Fore.GREEN + Style.BRIGHT}All providers are working") -def get_providers() -> list[type[BaseProvider]]: - providers = dir(Provider) - providers = [getattr(Provider, provider) for provider in providers if provider != "RetryProvider"] - providers = [provider for provider in providers if isinstance(provider, type) and hasattr(provider, "url")] +def get_providers() -> list[ProviderType]: return [ provider - for provider in providers - if issubclass(provider, BaseProvider) - and provider.__name__ not in dir(Provider.deprecated) + for provider in __providers__ + if provider.__name__ not in dir(Provider.deprecated) and provider.__name__ not in dir(Provider.unfinished) ] - -def create_response(_provider: type[BaseProvider]) -> str: - model = models.gpt_35_turbo.name if _provider.supports_gpt_35_turbo else models.default.name - response = _provider.create_completion( - model=model, +def create_response(provider: ProviderType) -> str: + response = provider.create_completion( + model=models.default.name, messages=[{"role": "user", "content": "Hello, who are you? Answer in detail much as possible."}], stream=False, ) return "".join(response) - -def test(_provider: type[BaseProvider]) -> bool: +def test(provider: ProviderType) -> bool: try: - response = create_response(_provider) + response = create_response(provider) assert type(response) is str assert len(response) > 0 return response - except Exception as e: - if logging: - print(e) + except Exception: return False |