diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-01 23:20:48 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-01 23:20:48 +0100 |
commit | e0aaad8f477386345a14c9adc7a7721fda115faa (patch) | |
tree | ac88be0b5d29f7e09d43ba581488750067037bfb /etc | |
parent | Add support for all models (diff) | |
download | gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.tar gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.tar.gz gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.tar.bz2 gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.tar.lz gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.tar.xz gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.tar.zst gpt4free-e0aaad8f477386345a14c9adc7a7721fda115faa.zip |
Diffstat (limited to 'etc')
-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 |