2023-10-15 23:46:58 +00:00
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
from colorama import Fore, Style
|
|
|
|
|
|
|
|
sys.path.append(str(Path(__file__).parent.parent))
|
|
|
|
|
2024-01-01 22:20:48 +00:00
|
|
|
from g4f import Provider, ProviderType, models
|
|
|
|
from g4f.Provider import __providers__
|
2023-10-15 23:46:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
providers = get_providers()
|
|
|
|
failed_providers = []
|
|
|
|
|
2024-01-01 22:20:48 +00:00
|
|
|
for provider in providers:
|
|
|
|
if provider.needs_auth:
|
2023-10-15 23:46:58 +00:00
|
|
|
continue
|
2024-01-01 22:20:48 +00:00
|
|
|
print("Provider:", provider.__name__)
|
|
|
|
result = test(provider)
|
2023-10-15 23:46:58 +00:00
|
|
|
print("Result:", result)
|
2024-01-01 22:20:48 +00:00
|
|
|
if provider.working and not result:
|
|
|
|
failed_providers.append(provider)
|
2023-10-15 23:46:58 +00:00
|
|
|
print()
|
|
|
|
|
|
|
|
if failed_providers:
|
|
|
|
print(f"{Fore.RED + Style.BRIGHT}Failed providers:{Style.RESET_ALL}")
|
|
|
|
for _provider in failed_providers:
|
|
|
|
print(f"{Fore.RED}{_provider.__name__}")
|
|
|
|
else:
|
|
|
|
print(f"{Fore.GREEN + Style.BRIGHT}All providers are working")
|
|
|
|
|
|
|
|
|
2024-01-01 22:20:48 +00:00
|
|
|
def get_providers() -> list[ProviderType]:
|
2023-11-12 09:12:05 +00:00
|
|
|
return [
|
|
|
|
provider
|
2024-01-01 22:20:48 +00:00
|
|
|
for provider in __providers__
|
|
|
|
if provider.__name__ not in dir(Provider.deprecated)
|
2023-11-12 09:12:05 +00:00
|
|
|
and provider.__name__ not in dir(Provider.unfinished)
|
2024-02-09 13:24:15 +00:00
|
|
|
and provider.url is not None
|
2023-11-12 09:12:05 +00:00
|
|
|
]
|
2023-10-15 23:46:58 +00:00
|
|
|
|
2024-01-01 22:20:48 +00:00
|
|
|
def create_response(provider: ProviderType) -> str:
|
|
|
|
response = provider.create_completion(
|
|
|
|
model=models.default.name,
|
2023-10-15 23:46:58 +00:00
|
|
|
messages=[{"role": "user", "content": "Hello, who are you? Answer in detail much as possible."}],
|
|
|
|
stream=False,
|
|
|
|
)
|
|
|
|
return "".join(response)
|
|
|
|
|
2024-01-01 22:20:48 +00:00
|
|
|
def test(provider: ProviderType) -> bool:
|
2023-10-15 23:46:58 +00:00
|
|
|
try:
|
2024-01-01 22:20:48 +00:00
|
|
|
response = create_response(provider)
|
2023-10-15 23:46:58 +00:00
|
|
|
assert type(response) is str
|
|
|
|
assert len(response) > 0
|
|
|
|
return response
|
2024-01-01 22:20:48 +00:00
|
|
|
except Exception:
|
2023-10-15 23:46:58 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
|
|
|
|