summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-09-12 11:37:20 +0200
committerGitHub <noreply@github.com>2023-09-12 11:37:20 +0200
commitcf7ba76e7eb27a3e62bea900f5f7fbd3381783ba (patch)
tree0a1f1eb3639c34472884d8d3d7bd102b12c891ff
parent~ | 0.0.2.8 (diff)
parentDisable not working providers: (diff)
downloadgpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar
gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.gz
gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.bz2
gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.lz
gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.xz
gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.tar.zst
gpt4free-cf7ba76e7eb27a3e62bea900f5f7fbd3381783ba.zip
Diffstat (limited to '')
-rw-r--r--README.md127
-rw-r--r--g4f/Provider/Aivvm.py78
-rw-r--r--g4f/Provider/ChatBase.py8
-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/Vercel.py2
-rw-r--r--g4f/Provider/Vitalentum.py66
-rw-r--r--g4f/Provider/Wuguokai.py11
-rw-r--r--g4f/Provider/Ylokh.py76
-rw-r--r--g4f/Provider/You.py40
-rw-r--r--g4f/Provider/__init__.py6
-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.py63
17 files changed, 404 insertions, 130 deletions
diff --git a/README.md b/README.md
index d57a542c..98757e56 100644
--- a/README.md
+++ b/README.md
@@ -182,17 +182,18 @@ for message in response:
##### Providers:
```py
from g4f.Provider import (
+ AItianhu,
Acytoo,
Aichat,
Ails,
+ Aivvm,
Bard,
Bing,
+ ChatBase,
ChatgptAi,
ChatgptLogin,
+ CodeLinkAva,
DeepAi,
- EasyChat,
- Equing,
- GetGpt,
H2o,
HuggingChat,
Opchatgpts,
@@ -201,33 +202,31 @@ from g4f.Provider import (
Raycast,
Theb,
Vercel,
+ Vitalentum,
Wewordle,
- Wuguokai,
+ Ylokh,
You,
- Yqcloud
+ Yqcloud,
)
# Usage:
response = g4f.ChatCompletion.create(..., provider=ProviderName)
```
-##### Needs cookies:
+##### Cookies Required:
+
+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.
-Many providers need cookies to work.
-In Bing you need a session, where you have passed the captcha.
-And in others providers you have to log-in into your account.
-If you run the g4l package locally,
-cookies from your browsers are read with `get_cookies`.
-Else you have pass them in the parameter `cookies`:
```py
import g4f
from g4f.Provider import (
Bard,
Bing,
- H2o,
HuggingChat,
OpenAssistant,
OpenaiChat,
- You,
)
# Usage:
response = g4f.ChatCompletion.create(
@@ -240,29 +239,36 @@ response = g4f.ChatCompletion.create(
)
```
-##### Async support:
+##### Async Support:
-Run providers `async` to improve speed / performance.
-The full execution time corresponds to the execution time of the slowest provider.
+To enhance speed and overall performance, execute providers asynchronously. The total execution time will be determined by the duration of the slowest provider's execution.
```py
import g4f, asyncio
async def run_async():
_providers = [
- g4f.Provider.Bard,
- g4f.Provider.Bing,
- g4f.Provider.H2o,
- g4f.Provider.HuggingChat,
- g4f.Provider.Liaobots,
- g4f.Provider.OpenAssistant,
- g4f.Provider.OpenaiChat,
+ g4f.Provider.AItianhu,
+ g4f.Provider.Acytoo,
+ g4f.Provider.Aichat,
+ g4f.Provider.Ails,
+ g4f.Provider.Aivvm,
+ g4f.Provider.ChatBase,
+ g4f.Provider.ChatgptAi,
+ g4f.Provider.ChatgptLogin,
+ g4f.Provider.CodeLinkAva,
+ g4f.Provider.DeepAi,
+ g4f.Provider.Opchatgpts,
+ g4f.Provider.Vercel,
+ g4f.Provider.Vitalentum,
+ g4f.Provider.Wewordle,
+ g4f.Provider.Ylokh,
g4f.Provider.You,
g4f.Provider.Yqcloud,
]
responses = [
provider.create_async(
- model=None,
+ model=g4f.models.default,
messages=[{"role": "user", "content": "Hello"}],
)
for provider in _providers
@@ -321,39 +327,44 @@ if __name__ == "__main__":
### gpt-3.5 / gpt-4
-| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth |
-| ------ | ------- | ------- | ----- | --------- | ------ | ---- |
-| [chat.acytoo.com](https://chat.acytoo.com/) | g4f.provider.Acytoo | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [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 | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [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) | ✔️ |
-| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.provider.ChatgptAi | ❌ | ✔️ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [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 | ✔️ | ❌ | ✔️ | ![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) | ✔️ |
-| [liaobots.com](https://liaobots.com) | g4f.provider.Liaobots | ✔️ | ✔️ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
-| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [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) | ✔️ |
-| [play.vercel.ai](https://play.vercel.ai) | g4f.provider.Vercel | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
-| [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) | ❌ |
-| [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) | ❌ |
-| [www.aitianhu.com](https://www.aitianhu.com/) | g4f.provider.AItianhu | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
-| [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/Aivvm.py b/g4f/Provider/Aivvm.py
new file mode 100644
index 00000000..dbfc588d
--- /dev/null
+++ b/g4f/Provider/Aivvm.py
@@ -0,0 +1,78 @@
+from __future__ import annotations
+
+from aiohttp import ClientSession
+
+from .base_provider import AsyncGeneratorProvider
+from ..typing import AsyncGenerator
+
+models = {
+ "gpt-4": {
+ "id": "gpt-4",
+ "name": "GPT-4",
+ },
+ "gpt-3.5-turbo": {
+ "id": "gpt-3.5-turbo",
+ "name": "GPT-3.5",
+ },
+ "gpt-3.5-turbo-16k": {
+ "id": "gpt-3.5-turbo-16k",
+ "name": "GPT-3.5-16k",
+ },
+}
+
+class Aivvm(AsyncGeneratorProvider):
+ url = "https://chat.aivvm.com"
+ working = True
+ supports_gpt_35_turbo = True
+ supports_gpt_4 = True
+
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: list[dict[str, str]],
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncGenerator:
+ model = model if model else "gpt-3.5-turbo"
+ if model not in models:
+ raise ValueError(f"Model are not supported: {model}")
+ headers = {
+ "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
+ "Accept" : "*/*",
+ "Accept-language" : "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3",
+ "Origin" : cls.url,
+ "Referer" : cls.url + "/",
+ "Sec-Fetch-Dest" : "empty",
+ "Sec-Fetch-Mode" : "cors",
+ "Sec-Fetch-Site" : "same-origin",
+ }
+ async with ClientSession(
+ headers=headers
+ ) as session:
+ data = {
+ "temperature": 1,
+ "key": "",
+ "messages": messages,
+ "model": models[model],
+ "prompt": "",
+ **kwargs
+ }
+ async with session.post(cls.url + "/api/chat", json=data, proxy=proxy) as response:
+ response.raise_for_status()
+ async for stream in response.content.iter_any():
+ yield stream.decode()
+
+
+ @classmethod
+ @property
+ def params(cls):
+ params = [
+ ("model", "str"),
+ ("messages", "list[dict[str, str]]"),
+ ("stream", "bool"),
+ ("temperature", "float"),
+ ]
+ param = ", ".join([": ".join(p) for p in params])
+ return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file
diff --git a/g4f/Provider/ChatBase.py b/g4f/Provider/ChatBase.py
index 7d73fd2f..b98fe565 100644
--- a/g4f/Provider/ChatBase.py
+++ b/g4f/Provider/ChatBase.py
@@ -21,8 +21,10 @@ class ChatBase(AsyncGeneratorProvider):
) -> AsyncGenerator:
if model == "gpt-4":
chat_id = "quran---tafseer-saadi-pdf-wbgknt7zn"
- elif model == "gpt-3.5-turbo" or True:
+ elif model == "gpt-3.5-turbo" or not model:
chat_id = "chatbase--1--pdf-p680fxvnm"
+ else:
+ raise ValueError(f"Model are not supported: {model}")
headers = {
"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
"Accept" : "*/*",
@@ -45,9 +47,7 @@ class ChatBase(AsyncGeneratorProvider):
async with session.post("https://www.chatbase.co/api/fe/chat", json=data) as response:
response.raise_for_status()
async for stream in response.content.iter_any():
- stream = stream.decode()
- if stream:
- yield stream
+ yield stream.decode()
@classmethod
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/Vercel.py b/g4f/Provider/Vercel.py
index b0e1d8af..79bcf3f4 100644
--- a/g4f/Provider/Vercel.py
+++ b/g4f/Provider/Vercel.py
@@ -55,7 +55,7 @@ class Vercel(AsyncProvider):
def _create_payload(model: str, messages: list[dict[str, str]]) -> dict[str, Any]:
if model not in model_info:
- raise RuntimeError(f'Model "{model}" are not supported')
+ raise ValueError(f'Model are not supported: {model}')
default_params = model_info[model]["default_params"]
return {
"messages": messages,
diff --git a/g4f/Provider/Vitalentum.py b/g4f/Provider/Vitalentum.py
new file mode 100644
index 00000000..31ad8b80
--- /dev/null
+++ b/g4f/Provider/Vitalentum.py
@@ -0,0 +1,66 @@
+from __future__ import annotations
+
+import json
+from aiohttp import ClientSession
+
+from .base_provider import AsyncGeneratorProvider
+from ..typing import AsyncGenerator
+
+class Vitalentum(AsyncGeneratorProvider):
+ url = "https://app.vitalentum.io"
+ working = True
+ supports_gpt_35_turbo = True
+
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: list[dict[str, str]],
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncGenerator:
+ headers = {
+ "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
+ "Accept" : "text/event-stream",
+ "Accept-language" : "de,en-US;q=0.7,en;q=0.3",
+ "Origin" : cls.url,
+ "Referer" : cls.url + "/",
+ "Sec-Fetch-Dest" : "empty",
+ "Sec-Fetch-Mode" : "cors",
+ "Sec-Fetch-Site" : "same-origin",
+ }
+ conversation = json.dumps({"history": [{
+ "speaker": "human" if message["role"] == "user" else "bot",
+ "text": message["content"],
+ } for message in messages]})
+ data = {
+ "conversation": conversation,
+ "temperature": 0.7,
+ **kwargs
+ }
+ async with ClientSession(
+ headers=headers
+ ) as session:
+ async with session.post(cls.url + "/api/converse-edge", json=data, proxy=proxy) as response:
+ response.raise_for_status()
+ async for line in response.content:
+ line = line.decode()
+ if line.startswith("data: ") and not line.startswith("data: [DONE]"):
+ line = json.loads(line[6:-1])
+ content = line["choices"][0]["delta"].get("content")
+ if content:
+ yield content
+
+
+ @classmethod
+ @property
+ def params(cls):
+ params = [
+ ("model", "str"),
+ ("messages", "list[dict[str, str]]"),
+ ("stream", "bool"),
+ ("temperature", "float"),
+ ]
+ param = ", ".join([": ".join(p) for p in params])
+ return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file
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/Provider/Ylokh.py b/g4f/Provider/Ylokh.py
new file mode 100644
index 00000000..1986b6d3
--- /dev/null
+++ b/g4f/Provider/Ylokh.py
@@ -0,0 +1,76 @@
+from __future__ import annotations
+
+import json
+from aiohttp import ClientSession
+
+from .base_provider import AsyncGeneratorProvider
+from ..typing import AsyncGenerator
+
+class Ylokh(AsyncGeneratorProvider):
+ url = "https://chat.ylokh.xyz"
+ working = True
+ supports_gpt_35_turbo = True
+
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: list[dict[str, str]],
+ stream: bool = True,
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncGenerator:
+ model = model if model else "gpt-3.5-turbo"
+ headers = {
+ "User-Agent" : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0",
+ "Accept" : "*/*",
+ "Accept-language" : "de,en-US;q=0.7,en;q=0.3",
+ "Origin" : cls.url,
+ "Referer" : cls.url + "/",
+ "Sec-Fetch-Dest" : "empty",
+ "Sec-Fetch-Mode" : "cors",
+ "Sec-Fetch-Site" : "same-origin",
+ }
+ data = {
+ "messages": messages,
+ "model": model,
+ "temperature": 1,
+ "presence_penalty": 0,
+ "top_p": 1,
+ "frequency_penalty": 0,
+ "allow_fallback": True,
+ "stream": stream,
+ **kwargs
+ }
+ async with ClientSession(
+ headers=headers
+ ) as session:
+ async with session.post("https://chatapi.ylokh.xyz/v1/chat/completions", json=data, proxy=proxy) as response:
+ response.raise_for_status()
+ if stream:
+ async for line in response.content:
+ line = line.decode()
+ if line.startswith("data: ") and not line.startswith("data: [DONE]"):
+ line = json.loads(line[6:-1])
+ content = line["choices"][0]["delta"].get("content")
+ if content:
+ yield content
+ else:
+ chat = await response.json()
+ yield chat["choices"][0]["message"].get("content")
+
+
+
+ @classmethod
+ @property
+ def params(cls):
+ params = [
+ ("model", "str"),
+ ("messages", "list[dict[str, str]]"),
+ ("stream", "bool"),
+ ("proxy", "str"),
+ ("temperature", "float"),
+ ]
+ param = ", ".join([": ".join(p) for p in params])
+ return f"g4f.provider.{cls.__name__} supports: ({param})" \ No newline at end of file
diff --git a/g4f/Provider/You.py b/g4f/Provider/You.py
index 121d1dbd..4f49f15e 100644
--- a/g4f/Provider/You.py
+++ b/g4f/Provider/You.py
@@ -2,39 +2,39 @@ from __future__ import annotations
import json
-from aiohttp import ClientSession
+from curl_cffi.requests import AsyncSession
from ..typing import AsyncGenerator
-from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
+from .base_provider import AsyncGeneratorProvider, format_prompt
class You(AsyncGeneratorProvider):
url = "https://you.com"
working = True
supports_gpt_35_turbo = True
- supports_stream = True
+ supports_stream = False
- @staticmethod
+
+ @classmethod
async def create_async_generator(
+ cls,
model: str,
messages: list[dict[str, str]],
- cookies: dict = None,
+ proxy: str = None,
**kwargs,
) -> AsyncGenerator:
- if not cookies:
- cookies = get_cookies("you.com")
- headers = {
- "Accept": "text/event-stream",
- "Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
- "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0"
- }
- async with ClientSession(headers=headers, cookies=cookies) as session:
- async with session.get(
+ async with AsyncSession(proxies={"https": proxy}, impersonate="chrome107") as session:
+ headers = {
+ "Accept": "text/event-stream",
+ "Referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
+ }
+ response = await session.get(
"https://you.com/api/streamingSearch",
params={"q": format_prompt(messages), "domain": "youchat", "chat": ""},
- ) as response:
- start = 'data: {"youChatToken": '
- async for line in response.content:
- line = line.decode('utf-8')
- if line.startswith(start):
- yield json.loads(line[len(start): -2]) \ No newline at end of file
+ headers=headers
+ )
+ response.raise_for_status()
+ start = 'data: {"youChatToken": '
+ for line in response.text.splitlines():
+ if line.startswith(start):
+ yield json.loads(line[len(start): -1]) \ No newline at end of file
diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py
index a1abe452..2a3d820e 100644
--- a/g4f/Provider/__init__.py
+++ b/g4f/Provider/__init__.py
@@ -4,6 +4,7 @@ from .Aichat import Aichat
from .Ails import Ails
from .AiService import AiService
from .AItianhu import AItianhu
+from .Aivvm import Aivvm
from .Bard import Bard
from .Bing import Bing
from .ChatBase import ChatBase
@@ -25,7 +26,9 @@ from .OpenAssistant import OpenAssistant
from .Raycast import Raycast
from .Theb import Theb
from .Vercel import Vercel
+from .Vitalentum import Vitalentum
from .Wewordle import Wewordle
+from .Ylokh import Ylokh
from .You import You
from .Yqcloud import Yqcloud
from .Equing import Equing
@@ -42,6 +45,7 @@ __all__ = [
'Ails',
'AiService',
'AItianhu',
+ 'Aivvm',
'Bard',
'Bing',
'ChatBase',
@@ -63,7 +67,9 @@ __all__ = [
'OpenAssistant',
'Theb',
'Vercel',
+ 'Vitalentum',
'Wewordle',
+ 'Ylokh',
'You',
'Yqcloud',
'Equing',
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 dc7c85f3..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:")
@@ -26,23 +30,52 @@ def print_imports():
def print_async():
print("##### Async support:")
print("```py")
- print("from g4f.Provider import (")
+ print("_providers = [")
for _provider in get_providers():
- if issubclass(_provider, AsyncProvider):
- print(f" {_provider.__name__},")
- print(")")
+ 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))