diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-11-12 14:55:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-12 14:55:23 +0100 |
commit | df8f41645c04f21d16fa14a4f2f5196f57e76dc9 (patch) | |
tree | 6ebaed4ccdd981c9c74ac1eaec3c18084a008138 /etc | |
parent | Merge pull request #1239 from hlohaus/pi (diff) | |
parent | Add auto_continue to OpenaiChat (diff) | |
download | gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.tar gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.tar.gz gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.tar.bz2 gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.tar.lz gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.tar.xz gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.tar.zst gpt4free-df8f41645c04f21d16fa14a4f2f5196f57e76dc9.zip |
Diffstat (limited to 'etc')
-rw-r--r-- | etc/testing/_providers.py | 10 | ||||
-rw-r--r-- | etc/tool/readme_table.py | 129 |
2 files changed, 63 insertions, 76 deletions
diff --git a/etc/testing/_providers.py b/etc/testing/_providers.py index ec0e0271..0194318c 100644 --- a/etc/testing/_providers.py +++ b/etc/testing/_providers.py @@ -35,8 +35,14 @@ def main(): 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)] - return [provider for provider in providers if issubclass(provider, BaseProvider)] + providers = [provider for provider in providers if isinstance(provider, type) and hasattr(provider, "url")] + return [ + provider + for provider in providers + if issubclass(provider, BaseProvider) + and provider.__name__ not in dir(Provider.deprecated) + and provider.__name__ not in dir(Provider.unfinished) + ] def create_response(_provider: type[BaseProvider]) -> str: diff --git a/etc/tool/readme_table.py b/etc/tool/readme_table.py index c7eb3caf..0ce9d0b9 100644 --- a/etc/tool/readme_table.py +++ b/etc/tool/readme_table.py @@ -3,58 +3,32 @@ import sys from pathlib import Path from urllib.parse import urlparse -sys.path.append(str(Path(__file__).parent.parent)) +sys.path.append(str(Path(__file__).parent.parent.parent)) import asyncio from g4f import models -from g4f.Provider.base_provider import AsyncProvider, BaseProvider -from g4f.Provider.retry_provider import RetryProvider -from testing._providers import get_providers - -logging = False - - -def print_imports(): - print("##### Providers:") - print("```py") - print("from g4f.Provider import (") - for _provider in get_providers(): - if _provider.working: - print(f" {_provider.__name__},") - - print(")") - print("# Usage:") - print("response = g4f.ChatCompletion.create(..., provider=ProviderName)") - print("```") - print() - print() - -def print_async(): - print("##### Async support:") - print("```py") - print("_providers = [") - for _provider in get_providers(): - if _provider.working and issubclass(_provider, AsyncProvider): - print(f" g4f.Provider.{_provider.__name__},") - print("]") - print("```") - print() - print() +from g4f import ChatCompletion +from g4f.Provider.base_provider import BaseProvider +from etc.testing._providers import get_providers + +from g4f import debug + +debug.logging = True async def test_async(provider: type[BaseProvider]): if not provider.working: return False - model = models.gpt_35_turbo.name if provider.supports_gpt_35_turbo else models.default.name messages = [{"role": "user", "content": "Hello Assistant!"}] try: - if issubclass(provider, AsyncProvider): - response = await provider.create_async(model=model, messages=messages) - else: - response = provider.create_completion(model=model, messages=messages, stream=False) + response = await asyncio.wait_for(ChatCompletion.create_async( + model=models.default, + messages=messages, + provider=provider + ), 30) return bool(response) except Exception as e: - if logging: + if debug.logging: print(f"{provider.__name__}: {e.__class__.__name__}: {e}") return False @@ -68,44 +42,53 @@ async def test_async_list(providers: list[type[BaseProvider]]): def print_providers(): - lines = [ - "| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Asynchron | Status | Auth |", - "| ------ | ------- | ------- | ----- | --------- | --------- | ------ | ---- |", - ] providers = get_providers() responses = asyncio.run(test_async_list(providers)) - for is_working in (True, False): - for idx, _provider in enumerate(providers): - if is_working != _provider.working: - continue - if _provider == RetryProvider: - 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 "❌" - can_async = "✔️" if issubclass(_provider, AsyncProvider) else "❌" - if _provider.working: - status = '![Active](https://img.shields.io/badge/Active-brightgreen)' - if responses[idx]: + for type in ("GPT-4", "GPT-3.5", "Other"): + lines = [ + "", + f"### {type}", + "", + "| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |", + "| ------ | ------- | ------- | ----- | ------ | ------ | ---- |", + ] + for is_working in (True, False): + for idx, _provider in enumerate(providers): + if is_working != _provider.working: + continue + do_continue = False + if type == "GPT-4" and _provider.supports_gpt_4: + do_continue = True + elif type == "GPT-3.5" and not _provider.supports_gpt_4 and _provider.supports_gpt_35_turbo: + do_continue = True + elif type == "Other" and not _provider.supports_gpt_4 and not _provider.supports_gpt_35_turbo: + do_continue = True + if not do_continue: + 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: status = '![Active](https://img.shields.io/badge/Active-brightgreen)' + if responses[idx]: + status = '![Active](https://img.shields.io/badge/Active-brightgreen)' + else: + status = '![Unknown](https://img.shields.io/badge/Unknown-grey)' 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} | {can_async} | {status} | {auth} |" - ) - print("\n".join(lines)) + 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)) def print_models(): base_provider_names = { @@ -151,8 +134,6 @@ def get_models(): if __name__ == "__main__": - print_imports() - print_async() print_providers() print("\n", "-" * 50, "\n") print_models()
\ No newline at end of file |