summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-09-12 04:40:10 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-09-12 04:40:10 +0200
commit618addd001077d9e4ed4d2a7aa03769a0ee0901b (patch)
tree0a1f1eb3639c34472884d8d3d7bd102b12c891ff
parentUpdate Readme (diff)
downloadgpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.gz
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.bz2
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.lz
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.xz
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.tar.zst
gpt4free-618addd001077d9e4ed4d2a7aa03769a0ee0901b.zip
Diffstat (limited to '')
-rw-r--r--README.md93
-rw-r--r--g4f/Provider/EasyChat.py2
-rw-r--r--g4f/Provider/Equing.py6
-rw-r--r--g4f/Provider/GetGpt.py2
-rw-r--r--g4f/Provider/Liaobots.py2
-rw-r--r--g4f/Provider/Wuguokai.py11
-rw-r--r--g4f/__init__.py13
-rw-r--r--g4f/models.py21
-rw-r--r--testing/test_chat_completion.py11
-rw-r--r--tool/readme_table.py57
10 files changed, 122 insertions, 96 deletions
diff --git a/README.md b/README.md
index cb749b99..98757e56 100644
--- a/README.md
+++ b/README.md
@@ -194,9 +194,6 @@ from g4f.Provider import (
ChatgptLogin,
CodeLinkAva,
DeepAi,
- EasyChat,
- Equing,
- GetGpt,
H2o,
HuggingChat,
Opchatgpts,
@@ -207,7 +204,6 @@ from g4f.Provider import (
Vercel,
Vitalentum,
Wewordle,
- Wuguokai,
Ylokh,
You,
Yqcloud,
@@ -218,7 +214,8 @@ response = g4f.ChatCompletion.create(..., provider=ProviderName)
##### Cookies Required:
-Cookies are essential for the proper functioning of many service providers. When using Bing, it's necessary to have a session where you have successfully passed the captcha. For other providers, logging into your account is a prerequisite.
+Cookies are essential for the proper functioning of some service providers.
+It is imperative to maintain an active session, typically achieved by logging into your account.
When running the g4f package locally, the package automatically retrieves cookies from your web browser using the `get_cookies` function. However, if you're not running it locally, you'll need to provide the cookies manually by passing them as parameters using the `cookies` parameter.
@@ -227,11 +224,9 @@ import g4f
from g4f.Provider import (
Bard,
Bing,
- H2o,
HuggingChat,
OpenAssistant,
OpenaiChat,
- You,
)
# Usage:
response = g4f.ChatCompletion.create(
@@ -258,18 +253,12 @@ async def run_async():
g4f.Provider.Aichat,
g4f.Provider.Ails,
g4f.Provider.Aivvm,
- g4f.Provider.Bard,
- g4f.Provider.Bing,
g4f.Provider.ChatBase,
g4f.Provider.ChatgptAi,
g4f.Provider.ChatgptLogin,
g4f.Provider.CodeLinkAva,
g4f.Provider.DeepAi,
- g4f.Provider.H2o,
- g4f.Provider.HuggingChat,
g4f.Provider.Opchatgpts,
- g4f.Provider.OpenAssistant,
- g4f.Provider.OpenaiChat,
g4f.Provider.Vercel,
g4f.Provider.Vitalentum,
g4f.Provider.Wewordle,
@@ -279,7 +268,7 @@ async def run_async():
]
responses = [
provider.create_async(
- model=None,
+ model=g4f.models.default,
messages=[{"role": "user", "content": "Hello"}],
)
for provider in _providers
@@ -338,44 +327,44 @@ if __name__ == "__main__":
### gpt-3.5 / gpt-4
-| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth |
-| ------ | ------- | ------- | ----- | --------- | ------ | ---- |
-| [www.aitianhu.com](https://www.aitianhu.com) | g4f.provider.AItianhu | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [chat.acytoo.com](https://chat.acytoo.com) | g4f.provider.Acytoo | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [chat-gpt.org](https://chat-gpt.org/chat) | g4f.provider.Aichat | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [ai.ls](https://ai.ls) | g4f.provider.Ails | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [chat.aivvm.com](https://chat.aivvm.com) | g4f.provider.Aivvm | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [bard.google.com](https://bard.google.com) | g4f.provider.Bard | ❌ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
-| [bing.com](https://bing.com/chat) | g4f.provider.Bing | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [www.chatbase.co](https://www.chatbase.co) | g4f.provider.ChatBase | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [chatgpt.ai](https://chatgpt.ai/) | g4f.provider.ChatgptAi | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [ava-ai-ef611.web.app](https://ava-ai-ef611.web.app) | g4f.provider.CodeLinkAva | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [deepai.org](https://deepai.org) | g4f.provider.DeepAi | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [free.easychat.work](https://free.easychat.work) | g4f.provider.EasyChat | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [next.eqing.tech](https://next.eqing.tech/) | g4f.provider.Equing | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [chat.getgpt.world](https://chat.getgpt.world/) | g4f.provider.GetGpt | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [gpt-gm.h2o.ai](https://gpt-gm.h2o.ai) | g4f.provider.H2o | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [huggingface.co](https://huggingface.co/chat/) | g4f.provider.HuggingChat | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
-| [liaobots.com](https://liaobots.com) | g4f.provider.Liaobots | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [open-assistant.io](https://open-assistant.io/chat) | g4f.provider.OpenAssistant | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
-| [chat.openai.com](https://chat.openai.com) | g4f.provider.OpenaiChat | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
-| [raycast.com](https://raycast.com) | g4f.provider.Raycast | ✔️ | ✔️ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
-| [theb.ai](https://theb.ai) | g4f.provider.Theb | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ✔️ |
-| [sdk.vercel.ai](https://sdk.vercel.ai) | g4f.provider.Vercel | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [app.vitalentum.io](https://app.vitalentum.io) | g4f.provider.Vitalentum | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [wewordle.org](https://wewordle.org) | g4f.provider.Wewordle | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [chat.wuguokai.xyz](https://chat.wuguokai.xyz) | g4f.provider.Wuguokai | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [chat.ylokh.xyz](https://chat.ylokh.xyz) | g4f.provider.Ylokh | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [you.com](https://you.com) | g4f.provider.You | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | g4f.provider.Yqcloud | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [aiservice.vercel.app](https://aiservice.vercel.app/) | g4f.provider.AiService | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
-| [chat.dfehub.com](https://chat.dfehub.com/) | g4f.provider.DfeHub | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
-| [chat9.fastgpt.me](https://chat9.fastgpt.me/) | g4f.provider.FastGpt | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
-| [forefront.com](https://forefront.com) | g4f.provider.Forefront | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
-| [supertest.lockchat.app](http://supertest.lockchat.app) | g4f.provider.Lockchat | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
-| [p5.v50.ltd](https://p5.v50.ltd) | g4f.provider.V50 | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Asynchron | Status | Auth |
+| ------ | ------- | ------- | ----- | --------- | --------- | ------ | ---- |
+| [www.aitianhu.com](https://www.aitianhu.com) | g4f.provider.AItianhu | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [chat.acytoo.com](https://chat.acytoo.com) | g4f.provider.Acytoo | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [chat-gpt.org](https://chat-gpt.org/chat) | g4f.provider.Aichat | ✔️ | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
+| [ai.ls](https://ai.ls) | g4f.provider.Ails | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [chat.aivvm.com](https://chat.aivvm.com) | g4f.provider.Aivvm | ✔️ | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [bard.google.com](https://bard.google.com) | g4f.provider.Bard | ❌ | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
+| [bing.com](https://bing.com/chat) | g4f.provider.Bing | ❌ | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [www.chatbase.co](https://www.chatbase.co) | g4f.provider.ChatBase | ✔️ | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [chatgpt.ai](https://chatgpt.ai/) | g4f.provider.ChatgptAi | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [ava-ai-ef611.web.app](https://ava-ai-ef611.web.app) | g4f.provider.CodeLinkAva | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [deepai.org](https://deepai.org) | g4f.provider.DeepAi | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [gpt-gm.h2o.ai](https://gpt-gm.h2o.ai) | g4f.provider.H2o | ❌ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [huggingface.co](https://huggingface.co/chat/) | g4f.provider.HuggingChat | ❌ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
+| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [open-assistant.io](https://open-assistant.io/chat) | g4f.provider.OpenAssistant | ❌ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
+| [chat.openai.com](https://chat.openai.com) | g4f.provider.OpenaiChat | ✔️ | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
+| [raycast.com](https://raycast.com) | g4f.provider.Raycast | ✔️ | ✔️ | ✔️ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
+| [theb.ai](https://theb.ai) | g4f.provider.Theb | ✔️ | ❌ | ✔️ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
+| [sdk.vercel.ai](https://sdk.vercel.ai) | g4f.provider.Vercel | ✔️ | ❌ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
+| [app.vitalentum.io](https://app.vitalentum.io) | g4f.provider.Vitalentum | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [wewordle.org](https://wewordle.org) | g4f.provider.Wewordle | ✔️ | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [chat.ylokh.xyz](https://chat.ylokh.xyz) | g4f.provider.Ylokh | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [you.com](https://you.com) | g4f.provider.You | ✔️ | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | g4f.provider.Yqcloud | ✔️ | ❌ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
+| [aiservice.vercel.app](https://aiservice.vercel.app/) | g4f.provider.AiService | ✔️ | ❌ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [chat.dfehub.com](https://chat.dfehub.com/) | g4f.provider.DfeHub | ✔️ | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [free.easychat.work](https://free.easychat.work) | g4f.provider.EasyChat | ✔️ | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [next.eqing.tech](https://next.eqing.tech/) | g4f.provider.Equing | ✔️ | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [chat9.fastgpt.me](https://chat9.fastgpt.me/) | g4f.provider.FastGpt | ✔️ | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [forefront.com](https://forefront.com) | g4f.provider.Forefront | ✔️ | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [chat.getgpt.world](https://chat.getgpt.world/) | g4f.provider.GetGpt | ✔️ | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [liaobots.com](https://liaobots.com) | g4f.provider.Liaobots | ✔️ | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [supertest.lockchat.app](http://supertest.lockchat.app) | g4f.provider.Lockchat | ✔️ | ✔️ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [p5.v50.ltd](https://p5.v50.ltd) | g4f.provider.V50 | ✔️ | ❌ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
+| [chat.wuguokai.xyz](https://chat.wuguokai.xyz) | g4f.provider.Wuguokai | ✔️ | ❌ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
### Other Models
diff --git a/g4f/Provider/EasyChat.py b/g4f/Provider/EasyChat.py
index 946d4a4d..dae5196d 100644
--- a/g4f/Provider/EasyChat.py
+++ b/g4f/Provider/EasyChat.py
@@ -13,7 +13,7 @@ class EasyChat(BaseProvider):
url: str = "https://free.easychat.work"
supports_stream = True
supports_gpt_35_turbo = True
- working = True
+ working = False
@staticmethod
def create_completion(
diff --git a/g4f/Provider/Equing.py b/g4f/Provider/Equing.py
index 0ebb93a5..261c53c0 100644
--- a/g4f/Provider/Equing.py
+++ b/g4f/Provider/Equing.py
@@ -6,12 +6,12 @@ from abc import ABC, abstractmethod
import requests
from ..typing import Any, CreateResult
+from .base_provider import BaseProvider
-class Equing(ABC):
+class Equing(BaseProvider):
url: str = 'https://next.eqing.tech/'
- working = True
- needs_auth = False
+ working = False
supports_stream = True
supports_gpt_35_turbo = True
supports_gpt_4 = False
diff --git a/g4f/Provider/GetGpt.py b/g4f/Provider/GetGpt.py
index 74e772b0..b96efaac 100644
--- a/g4f/Provider/GetGpt.py
+++ b/g4f/Provider/GetGpt.py
@@ -14,7 +14,7 @@ from .base_provider import BaseProvider
class GetGpt(BaseProvider):
url = 'https://chat.getgpt.world/'
supports_stream = True
- working = True
+ working = False
supports_gpt_35_turbo = True
@staticmethod
diff --git a/g4f/Provider/Liaobots.py b/g4f/Provider/Liaobots.py
index 2cc5ff99..33224d2e 100644
--- a/g4f/Provider/Liaobots.py
+++ b/g4f/Provider/Liaobots.py
@@ -31,7 +31,7 @@ models = {
class Liaobots(AsyncGeneratorProvider):
url = "https://liaobots.com"
- working = True
+ working = False
supports_gpt_35_turbo = True
supports_gpt_4 = True
_auth_code = None
diff --git a/g4f/Provider/Wuguokai.py b/g4f/Provider/Wuguokai.py
index a9614626..0a46f6ee 100644
--- a/g4f/Provider/Wuguokai.py
+++ b/g4f/Provider/Wuguokai.py
@@ -5,13 +5,13 @@ import random
import requests
from ..typing import Any, CreateResult
-from .base_provider import BaseProvider
+from .base_provider import BaseProvider, format_prompt
class Wuguokai(BaseProvider):
url = 'https://chat.wuguokai.xyz'
supports_gpt_35_turbo = True
- working = True
+ working = False
@staticmethod
def create_completion(
@@ -20,11 +20,6 @@ class Wuguokai(BaseProvider):
stream: bool,
**kwargs: Any,
) -> CreateResult:
- base = ''
- for message in messages:
- base += '%s: %s\n' % (message['role'], message['content'])
- base += 'assistant:'
-
headers = {
'authority': 'ai-api.wuguokai.xyz',
'accept': 'application/json, text/plain, */*',
@@ -41,7 +36,7 @@ class Wuguokai(BaseProvider):
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}
data ={
- "prompt": base,
+ "prompt": format_prompt(messages),
"options": {},
"userId": f"#/chat/{random.randint(1,99999999)}",
"usingContext": True
diff --git a/g4f/__init__.py b/g4f/__init__.py
index 065acee6..90b05c85 100644
--- a/g4f/__init__.py
+++ b/g4f/__init__.py
@@ -2,6 +2,7 @@ from __future__ import annotations
from . import models
from .Provider import BaseProvider
from .typing import Any, CreateResult, Union
+import random
logging = False
@@ -13,14 +14,22 @@ class ChatCompletion:
provider : Union[type[BaseProvider], None] = None,
stream : bool = False,
auth : Union[str, None] = None, **kwargs: Any) -> Union[CreateResult, str]:
-
+
if isinstance(model, str):
try:
model = models.ModelUtils.convert[model]
except KeyError:
raise Exception(f'The model: {model} does not exist')
- provider = model.best_provider if provider == None else provider
+
+ if not provider:
+ if isinstance(model.best_provider, tuple):
+ provider = random.choice(model.best_provider)
+ else:
+ provider = model.best_provider
+
+ if not provider:
+ raise Exception(f'No provider found')
if not provider.working:
raise Exception(f'{provider.__name__} is not working')
diff --git a/g4f/models.py b/g4f/models.py
index 0c5eb961..e095ce7e 100644
--- a/g4f/models.py
+++ b/g4f/models.py
@@ -1,31 +1,37 @@
from __future__ import annotations
from dataclasses import dataclass
-from .Provider import Bard, BaseProvider, GetGpt, H2o, Liaobots, Vercel, Equing
+from .Provider import BaseProvider, Bard, H2o, Vercel
+from .Provider import Aichat, Aivvm, ChatBase, ChatgptAi, ChatgptLogin, CodeLinkAva
+from .Provider import DeepAi, Vercel, Vitalentum, Ylokh, You, Yqcloud
+from .typing import Union
@dataclass
class Model:
name: str
base_provider: str
- best_provider: type[BaseProvider]
+ best_provider: Union[type[BaseProvider], tuple[type[BaseProvider]]] = None
# Config for HuggingChat, OpenAssistant
# Works for Liaobots, H2o, OpenaiChat, Yqcloud, You
default = Model(
name="",
- base_provider="huggingface",
- best_provider=H2o,
+ base_provider="huggingface"
)
# GPT-3.5 / GPT-4
gpt_35_turbo = Model(
name = 'gpt-3.5-turbo',
base_provider = 'openai',
- best_provider = GetGpt)
+ best_provider = (
+ Vercel, Aichat, Aivvm, ChatBase, ChatgptAi, ChatgptLogin,
+ CodeLinkAva, DeepAi, Vitalentum, Ylokh, You, Yqcloud
+ )
+)
gpt_4 = Model(
name = 'gpt-4',
base_provider = 'openai',
- best_provider = Liaobots)
+)
# Bard
palm = Model(
@@ -117,8 +123,7 @@ gpt_35_turbo_16k = Model(
gpt_35_turbo_16k_0613 = Model(
name = 'openai:gpt-3.5-turbo-16k-0613',
- base_provider = 'openai',
- best_provider = Equing)
+ base_provider = 'openai')
gpt_4_0613 = Model(
name = 'openai:gpt-4-0613',
diff --git a/testing/test_chat_completion.py b/testing/test_chat_completion.py
index 32c069be..fbaa3169 100644
--- a/testing/test_chat_completion.py
+++ b/testing/test_chat_completion.py
@@ -5,13 +5,8 @@ sys.path.append(str(Path(__file__).parent.parent))
import g4f
-stream = False
response = g4f.ChatCompletion.create(
- model="gpt-3.5-turbo",
- provider=g4f.Provider.Ails,
- messages=[{"role": "user", "content": "hello"}],
- stream=stream,
- active_server=5,
+ model=g4f.models.gpt_35_turbo,
+ messages=[{"role": "user", "content": "hello, are you GPT 4?"}]
)
-
-print(response)
+print(response) \ No newline at end of file
diff --git a/tool/readme_table.py b/tool/readme_table.py
index 3e2a6e64..9e43b0ae 100644
--- a/tool/readme_table.py
+++ b/tool/readme_table.py
@@ -5,9 +5,13 @@ from urllib.parse import urlparse
sys.path.append(str(Path(__file__).parent.parent))
+import asyncio
from g4f import models
-from g4f.Provider.base_provider import AsyncProvider
-from testing.test_providers import test, get_providers
+from g4f.Provider.base_provider import AsyncProvider, BaseProvider
+from testing.test_providers import get_providers
+
+logging = False
+
def print_imports():
print("##### Providers:")
@@ -28,21 +32,50 @@ def print_async():
print("```py")
print("_providers = [")
for _provider in get_providers():
- if issubclass(_provider, AsyncProvider):
+ if _provider.working and issubclass(_provider, AsyncProvider):
print(f" g4f.Provider.{_provider.__name__},")
print("]")
print("```")
print()
print()
+
+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)
+ return True if response else False
+ except Exception as e:
+ if logging:
+ print(f"{provider.__name__}: {e.__class__.__name__}: {e}")
+ return False
+
+
+async def test_async_list(providers: list[type[BaseProvider]]):
+ responses: list = [
+ test_async(_provider)
+ for _provider in providers
+ ]
+ return await asyncio.gather(*responses)
+
+
def print_providers():
lines = [
- "| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth |",
- "| ------ | ------- | ------- | ----- | --------- | ------ | ---- |",
+ "| 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 _provider in providers:
+ for idx, _provider in enumerate(providers):
if is_working != _provider.working:
continue
netloc = urlparse(_provider.url).netloc
@@ -53,8 +86,9 @@ def print_providers():
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:
- if test(_provider):
+ if responses[idx]:
status = '![Active](https://img.shields.io/badge/Active-brightgreen)'
else:
status = '![Unknown](https://img.shields.io/badge/Unknown-grey)'
@@ -63,7 +97,7 @@ def print_providers():
auth = "✔️" if _provider.needs_auth else "❌"
lines.append(
- f"| {website} | {provider_name} | {has_gpt_35} | {has_gpt_4} | {stream} | {status} | {auth} |"
+ f"| {website} | {provider_name} | {has_gpt_35} | {has_gpt_4} | {stream} | {can_async} | {status} | {auth} |"
)
print("\n".join(lines))
@@ -89,17 +123,16 @@ def print_models():
_models = get_models()
for model in _models:
- if model.best_provider.__name__ not in provider_urls:
+ if not model.best_provider or model.best_provider.__name__ not in provider_urls:
continue
- split_name = re.split(r":|/", model.name)
- name = split_name[-1]
+ 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
website = f"[{netloc}]({provider_url})"
+
lines.append(f"| {name} | {base_provider} | {provider_name} | {website} |")
print("\n".join(lines))