summaryrefslogtreecommitdiffstats
path: root/etc/tool/readme_table.py
diff options
context:
space:
mode:
Diffstat (limited to 'etc/tool/readme_table.py')
-rw-r--r--etc/tool/readme_table.py70
1 files changed, 28 insertions, 42 deletions
diff --git a/etc/tool/readme_table.py b/etc/tool/readme_table.py
index 0ce9d0b9..d5a409ec 100644
--- a/etc/tool/readme_table.py
+++ b/etc/tool/readme_table.py
@@ -1,22 +1,15 @@
import re
-import sys
-from pathlib import Path
from urllib.parse import urlparse
-
-sys.path.append(str(Path(__file__).parent.parent.parent))
-
import asyncio
-from g4f import models
-from g4f import ChatCompletion
-from g4f.Provider.base_provider import BaseProvider
-from etc.testing._providers import get_providers
+from g4f import models, ChatCompletion
+from g4f.base_provider import BaseProvider, BaseRetryProvider, ProviderType
+from etc.testing._providers import get_providers
from g4f import debug
debug.logging = True
-
-async def test_async(provider: type[BaseProvider]):
+async def test_async(provider: ProviderType):
if not provider.working:
return False
messages = [{"role": "user", "content": "Hello Assistant!"}]
@@ -32,19 +25,17 @@ async def test_async(provider: type[BaseProvider]):
print(f"{provider.__name__}: {e.__class__.__name__}: {e}")
return False
-
-async def test_async_list(providers: list[type[BaseProvider]]):
+def test_async_list(providers: list[ProviderType]):
responses: list = [
- test_async(_provider)
+ asyncio.run(test_async(_provider))
for _provider in providers
]
- return await asyncio.gather(*responses)
-
+ return responses
def print_providers():
providers = get_providers()
- responses = asyncio.run(test_async_list(providers))
+ responses = test_async_list(providers)
for type in ("GPT-4", "GPT-3.5", "Other"):
lines = [
@@ -67,7 +58,7 @@ def print_providers():
do_continue = True
if not do_continue:
continue
- netloc = urlparse(_provider.url).netloc
+ netloc = urlparse(_provider.url).netloc.replace("www.", "")
website = f"[{netloc}]({_provider.url})"
provider_name = f"`g4f.Provider.{_provider.__name__}`"
@@ -92,48 +83,43 @@ def print_providers():
def print_models():
base_provider_names = {
- "cohere": "Cohere",
"google": "Google",
"openai": "OpenAI",
- "anthropic": "Anthropic",
- "replicate": "Replicate",
"huggingface": "Huggingface",
+ "anthropic": "Anthropic",
+ "inflection": "Inflection"
}
provider_urls = {
- "Bard": "https://bard.google.com/",
- "H2o": "https://www.h2o.ai/",
- "Vercel": "https://sdk.vercel.ai/",
+ "google": "https://gemini.google.com/",
+ "openai": "https://openai.com/",
+ "huggingface": "https://huggingface.co/",
+ "anthropic": "https://www.anthropic.com/",
+ "inflection": "https://inflection.ai/",
}
lines = [
"| Model | Base Provider | Provider | Website |",
"| ----- | ------------- | -------- | ------- |",
]
-
- _models = get_models()
- for model in _models:
- if not model.best_provider or model.best_provider.__name__ not in provider_urls:
- continue
-
+ for name, model in models.ModelUtils.convert.items():
+ if name.startswith("gpt-3.5") or name.startswith("gpt-4"):
+ if name not in ("gpt-3.5-turbo", "gpt-4", "gpt-4-turbo"):
+ continue
name = re.split(r":|/", model.name)[-1]
base_provider = base_provider_names[model.base_provider]
- provider_name = f"g4f.provider.{model.best_provider.__name__}"
- provider_url = provider_urls[model.best_provider.__name__]
- netloc = urlparse(provider_url).netloc
+ if not isinstance(model.best_provider, BaseRetryProvider):
+ provider_name = f"g4f.Provider.{model.best_provider.__name__}"
+ else:
+ provider_name = f"{len(model.best_provider.providers)}+ Providers"
+ provider_url = provider_urls[model.base_provider]
+ netloc = urlparse(provider_url).netloc.replace("www.", "")
website = f"[{netloc}]({provider_url})"
lines.append(f"| {name} | {base_provider} | {provider_name} | {website} |")
print("\n".join(lines))
-
-def get_models():
- _models = [item[1] for item in models.__dict__.items()]
- _models = [model for model in _models if type(model) is models.Model]
- return [model for model in _models if model.name not in ["gpt-3.5-turbo", "gpt-4"]]
-
-
if __name__ == "__main__":
- print_providers()
- print("\n", "-" * 50, "\n")
+ #print_providers()
+ #print("\n", "-" * 50, "\n")
print_models() \ No newline at end of file