返回提交历史
Modified
README.md
+61
-57
Modified
etc/testing/_providers.py
+1
-0
Modified
etc/tool/readme_table.py
+28
-42
Added
g4f/Provider/CreateImagesBing.py
+94
-0
Modified
g4f/Provider/GptChatly.py
+0
-1
Modified
g4f/Provider/Hashnode.py
+1
-1
Modified
g4f/Provider/Phind.py
+1
-1
Modified
g4f/Provider/__init__.py
+2
-0
Modified
g4f/Provider/bing/create_images.py
+4
-86
Modified
g4f/Provider/helper.py
+4
-95
Modified
g4f/Provider/needs_auth/ThebApi.py
+1
-1
Modified
g4f/__init__.py
+1
-1
Added
g4f/cookies.py
+97
-0
Modified
g4f/errors.py
+0
-3
Modified
g4f/models.py
+7
-11
Modified
g4f/webdriver.py
+3
-0
XFEstudio/gpt4free
Update provider and model list (#1568)
Move bing.create_images and cookies helper Disable some providers
5c75972c
代码差异
16 个文件
+305
-299
@@ -552,47 +552,54 @@ for choice in json_response:
552
552
| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
553
553
| ------ | ------- | ------- | ----- | ------ | ------ | ---- |
554
554
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ |  | ❌ |
555
| [chat.geekgpt.org](https://chat.geekgpt.org) | `g4f.Provider.GeekGpt` | ✔️ | ✔️ | ✔️ |  | ❌ |
556
| [gptchatly.com](https://gptchatly.com) | `g4f.Provider.GptChatly` | ✔️ | ✔️ | ❌ |  | ❌ |
557
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ |  | ❌ |
555
| [free.chatgpt.org.uk](https://free.chatgpt.org.uk) | `g4f.Provider.FreeChatgpt` | ✔️ | ✔️ | ✔️ |  | ❌ |
556
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ |  | ❌ |
557
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ✔️ | ✔️ |  | ✔️ |
558
558
| [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ |  | ✔️ |
559
| [beta.theb.ai](https://beta.theb.ai) | `g4f.Provider.Theb` | ✔️ | ✔️ | ✔️ |  | ❌ |
560
| [chat.geekgpt.org](https://chat.geekgpt.org) | `g4f.Provider.GeekGpt` | ✔️ | ✔️ | ✔️ |  | ❌ |
559
561
560
562
### GPT-3.5
561
563
562
564
| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
563
565
| ------ | ------- | ------- | ----- | ------ | ------ | ---- |
564
| [www.aitianhu.com](https://www.aitianhu.com) | `g4f.Provider.AItianhu` | ✔️ | ❌ | ✔️ |  | ❌ |
565
566
| [chat3.aiyunos.top](https://chat3.aiyunos.top/) | `g4f.Provider.AItianhuSpace` | ✔️ | ❌ | ✔️ |  | ❌ |
566
| [e.aiask.me](https://e.aiask.me) | `g4f.Provider.AiAsk` | ✔️ | ❌ | ✔️ |  | ❌ |
567
| [chat-gpt.org](https://chat-gpt.org/chat) | `g4f.Provider.Aichat` | ✔️ | ❌ | ❌ |  | ❌ |
568
| [www.chatbase.co](https://www.chatbase.co) | `g4f.Provider.ChatBase` | ✔️ | ❌ | ✔️ |  | ❌ |
567
| [aichatonline.org](https://aichatonline.org) | `g4f.Provider.AiChatOnline` | ✔️ | ❌ | ✔️ |  | ❌ |
568
| [openchat.team](https://openchat.team) | `g4f.Provider.Aura` | ✔️ | ❌ | ✔️ |  | ❌ |
569
| [chatbase.co](https://www.chatbase.co) | `g4f.Provider.ChatBase` | ✔️ | ❌ | ✔️ |  | ❌ |
569
570
| [chatforai.store](https://chatforai.store) | `g4f.Provider.ChatForAi` | ✔️ | ❌ | ✔️ |  | ❌ |
570
| [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ✔️ | ❌ | ✔️ |  | ❌ |
571
| [chatgptx.de](https://chatgptx.de) | `g4f.Provider.ChatgptX` | ✔️ | ❌ | ✔️ |  | ❌ |
572
| [chat-shared2.zhile.io](https://chat-shared2.zhile.io) | `g4f.Provider.FakeGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
573
| [freegpts1.aifree.site](https://freegpts1.aifree.site/) | `g4f.Provider.FreeGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
574
| [gptalk.net](https://gptalk.net) | `g4f.Provider.GPTalk` | ✔️ | ❌ | ✔️ |  | ❌ |
575
| [ai18.gptforlove.com](https://ai18.gptforlove.com) | `g4f.Provider.GptForLove` | ✔️ | ❌ | ✔️ |  | ❌ |
576
| [gptgo.ai](https://gptgo.ai) | `g4f.Provider.GptGo` | ✔️ | ❌ | ✔️ |  | ❌ |
577
| [hashnode.com](https://hashnode.com) | `g4f.Provider.Hashnode` | ✔️ | ❌ | ✔️ |  | ❌ |
571
| [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ✔️ | ❌ | ✔️ |  | ❌ |
572
| [chat.chatgptdemo.net](https://chat.chatgptdemo.net) | `g4f.Provider.ChatgptDemo` | ✔️ | ❌ | ✔️ |  | ❌ |
573
| [chatgpt-free.cc](https://www.chatgpt-free.cc) | `g4f.Provider.ChatgptNext` | ✔️ | ❌ | ✔️ |  | ❌ |
574
| [chat.3211000.xyz](https://chat.3211000.xyz) | `g4f.Provider.Chatxyz` | ✔️ | ❌ | ✔️ |  | ❌ |
575
| [gptalk.net](https://gptalk.net) | `g4f.Provider.GPTalk` | ✔️ | ❌ | ✔️ |  | ❌ |
576
| [geminiprochat.com](https://geminiprochat.com) | `g4f.Provider.GeminiProChat` | ✔️ | ❌ | ✔️ |  | ❌ |
577
| [gpt6.ai](https://gpt6.ai) | `g4f.Provider.Gpt6` | ✔️ | ❌ | ✔️ |  | ❌ |
578
| [gptchatly.com](https://gptchatly.com) | `g4f.Provider.GptChatly` | ✔️ | ❌ | ❌ |  | ❌ |
579
| [ai18.gptforlove.com](https://ai18.gptforlove.com) | `g4f.Provider.GptForLove` | ✔️ | ❌ | ✔️ |  | ❌ |
580
| [gptgo.ai](https://gptgo.ai) | `g4f.Provider.GptGo` | ✔️ | ❌ | ✔️ |  | ❌ |
581
| [gpttalk.ru](https://gpttalk.ru) | `g4f.Provider.GptTalkRu` | ✔️ | ❌ | ✔️ |  | ❌ |
582
| [koala.sh](https://koala.sh) | `g4f.Provider.Koala` | ✔️ | ❌ | ✔️ |  | ❌ |
578
583
| [app.myshell.ai](https://app.myshell.ai/chat) | `g4f.Provider.MyShell` | ✔️ | ❌ | ✔️ |  | ❌ |
579
| [noowai.com](https://noowai.com) | `g4f.Provider.NoowAi` | ✔️ | ❌ | ✔️ |  | ❌ |
580
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ❌ | ✔️ |  | ✔️ |
581
| [theb.ai](https://theb.ai) | `g4f.Provider.Theb` | ✔️ | ❌ | ✔️ |  | ✔️ |
582
| [sdk.vercel.ai](https://sdk.vercel.ai) | `g4f.Provider.Vercel` | ✔️ | ❌ | ✔️ |  | ❌ |
584
| [onlinegpt.org](https://onlinegpt.org) | `g4f.Provider.OnlineGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
585
| [perplexity.ai](https://www.perplexity.ai) | `g4f.Provider.PerplexityAi` | ✔️ | ❌ | ✔️ |  | ❌ |
586
| [poe.com](https://poe.com) | `g4f.Provider.Poe` | ✔️ | ❌ | ✔️ |  | ✔️ |
587
| [talkai.info](https://talkai.info) | `g4f.Provider.TalkAi` | ✔️ | ❌ | ✔️ |  | ❌ |
583
588
| [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ❌ | ✔️ |  | ❌ |
584
| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | `g4f.Provider.Yqcloud` | ✔️ | ❌ | ✔️ |  | ❌ |
585
| [chat.acytoo.com](https://chat.acytoo.com) | `g4f.Provider.Acytoo` | ✔️ | ❌ | ✔️ |  | ❌ |
586
| [aibn.cc](https://aibn.cc) | `g4f.Provider.Aibn` | ✔️ | ❌ | ✔️ |  | ❌ |
587
| [ai.ls](https://ai.ls) | `g4f.Provider.Ails` | ✔️ | ❌ | ✔️ |  | ❌ |
589
| [aitianhu.com](https://www.aitianhu.com) | `g4f.Provider.AItianhu` | ✔️ | ❌ | ✔️ |  | ❌ |
590
| [e.aiask.me](https://e.aiask.me) | `g4f.Provider.AiAsk` | ✔️ | ❌ | ✔️ |  | ❌ |
591
| [chatgpt.bestim.org](https://chatgpt.bestim.org) | `g4f.Provider.Bestim` | ✔️ | ❌ | ✔️ |  | ❌ |
592
| [chatanywhere.cn](https://chatanywhere.cn) | `g4f.Provider.ChatAnywhere` | ✔️ | ❌ | ✔️ |  | ❌ |
588
593
| [chatgpt4online.org](https://chatgpt4online.org) | `g4f.Provider.Chatgpt4Online` | ✔️ | ❌ | ✔️ |  | ❌ |
589
| [chat.chatgptdemo.net](https://chat.chatgptdemo.net) | `g4f.Provider.ChatgptDemo` | ✔️ | ❌ | ✔️ |  | ❌ |
590
| [chatgptduo.com](https://chatgptduo.com) | `g4f.Provider.ChatgptDuo` | ✔️ | ❌ | ❌ |  | ❌ |
594
| [chat.chatgptdemo.ai](https://chat.chatgptdemo.ai) | `g4f.Provider.ChatgptDemoAi` | ✔️ | ❌ | ✔️ |  | ❌ |
591
595
| [chatgptfree.ai](https://chatgptfree.ai) | `g4f.Provider.ChatgptFree` | ✔️ | ❌ | ❌ |  | ❌ |
592
596
| [chatgptlogin.ai](https://chatgptlogin.ai) | `g4f.Provider.ChatgptLogin` | ✔️ | ❌ | ✔️ |  | ❌ |
593
| [cromicle.top](https://cromicle.top) | `g4f.Provider.Cromicle` | ✔️ | ❌ | ✔️ |  | ❌ |
597
| [chatgptx.de](https://chatgptx.de) | `g4f.Provider.ChatgptX` | ✔️ | ❌ | ✔️ |  | ❌ |
598
| [chat-shared2.zhile.io](https://chat-shared2.zhile.io) | `g4f.Provider.FakeGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
599
| [freegpts1.aifree.site](https://freegpts1.aifree.site/) | `g4f.Provider.FreeGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
594
600
| [gptgod.site](https://gptgod.site) | `g4f.Provider.GptGod` | ✔️ | ❌ | ✔️ |  | ❌ |
595
| [opchatgpts.net](https://opchatgpts.net) | `g4f.Provider.Opchatgpts` | ✔️ | ❌ | ✔️ |  | ❌ |
601
| [hashnode.com](https://hashnode.com) | `g4f.Provider.Hashnode` | ✔️ | ❌ | ✔️ |  | ❌ |
602
| [sdk.vercel.ai](https://sdk.vercel.ai) | `g4f.Provider.Vercel` | ✔️ | ❌ | ✔️ |  | ❌ |
596
603
| [chat.ylokh.xyz](https://chat.ylokh.xyz) | `g4f.Provider.Ylokh` | ✔️ | ❌ | ✔️ |  | ❌ |
597
604
598
605
### Other
@@ -601,40 +608,37 @@ for choice in json_response:
601
608
| ------ | ------- | ------- | ----- | ------ | ------ | ---- |
602
609
| [bard.google.com](https://bard.google.com) | `g4f.Provider.Bard` | ❌ | ❌ | ❌ |  | ✔️ |
603
610
| [deepinfra.com](https://deepinfra.com) | `g4f.Provider.DeepInfra` | ❌ | ❌ | ✔️ |  | ❌ |
604
| [huggingface.co](https://huggingface.co/chat) | `g4f.Provider.HuggingChat` | ❌ | ❌ | ✔️ |  | ✔️ |
605
| [www.llama2.ai](https://www.llama2.ai) | `g4f.Provider.Llama2` | ❌ | ❌ | ✔️ |  | ❌ |
611
| [gemini.google.com](https://gemini.google.com) | `g4f.Provider.Gemini` | ❌ | ❌ | ❌ |  | ✔️ |
612
| [huggingface.co](https://huggingface.co/chat) | `g4f.Provider.HuggingChat` | ❌ | ❌ | ✔️ |  | ❌ |
613
| [llama2.ai](https://www.llama2.ai) | `g4f.Provider.Llama2` | ❌ | ❌ | ✔️ |  | ❌ |
614
| [labs.perplexity.ai](https://labs.perplexity.ai) | `g4f.Provider.PerplexityLabs` | ❌ | ❌ | ✔️ |  | ❌ |
615
| [phind.com](https://www.phind.com) | `g4f.Provider.Phind` | ❌ | ❌ | ✔️ |  | ❌ |
616
| [pi.ai](https://pi.ai/talk) | `g4f.Provider.Pi` | ❌ | ❌ | ✔️ |  | ❌ |
617
| [theb.ai](https://theb.ai) | `g4f.Provider.ThebApi` | ❌ | ❌ | ❌ |  | ✔️ |
606
618
| [open-assistant.io](https://open-assistant.io/chat) | `g4f.Provider.OpenAssistant` | ❌ | ❌ | ✔️ |  | ✔️ |
607
619
608
620
### Models
609
621
610
| Model | Base Provider | Provider | Website |
611
| --------------------------------------- | ------------- | ------------------- | ------------------------------------------- |
612
| palm | Google | g4f.Provider.Bard | [bard.google.com](https://bard.google.com/) |
613
| h2ogpt-gm-oasst1-en-2048-falcon-7b-v3 | Hugging Face | g4f.Provider.H2o | [www.h2o.ai](https://www.h2o.ai/) |
614
| h2ogpt-gm-oasst1-en-2048-falcon-40b-v1 | Hugging Face | g4f.Provider.H2o | [www.h2o.ai](https://www.h2o.ai/) |
615
| h2ogpt-gm-oasst1-en-2048-open-llama-13b | Hugging Face | g4f.Provider.H2o | [www.h2o.ai](https://www.h2o.ai/) |
616
| claude-instant-v1 | Anthropic | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
617
| claude-v1 | Anthropic | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
618
| claude-v2 | Anthropic | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
619
| command-light-nightly | Cohere | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
620
| command-nightly | Cohere | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
621
| gpt-neox-20b | Hugging Face | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
622
| oasst-sft-1-pythia-12b | Hugging Face | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
623
| oasst-sft-4-pythia-12b-epoch-3.5 | Hugging Face | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
624
| santacoder | Hugging Face | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
625
| bloom | Hugging Face | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
626
| flan-t5-xxl | Hugging Face | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
627
| code-davinci-002 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
628
| gpt-3.5-turbo-16k | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
629
| gpt-3.5-turbo-16k-0613 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
630
| gpt-4-0613 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
631
| text-ada-001 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
632
| text-babbage-001 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
633
| text-curie-001 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
634
| text-davinci-002 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
635
| text-davinci-003 | OpenAI | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
636
| llama13b-v2-chat | Replicate | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
637
| llama7b-v2-chat | Replicate | g4f.Provider.Vercel | [sdk.vercel.ai](https://sdk.vercel.ai/) |
622
| Model | Base Provider | Provider | Website |
623
| ----- | ------------- | -------- | ------- |
624
| gpt-3.5-turbo | OpenAI | 5+ Providers | [openai.com](https://openai.com/) |
625
| gpt-4 | OpenAI | 2+ Providers | [openai.com](https://openai.com/) |
626
| gpt-4-turbo | OpenAI | g4f.Provider.Bing | [openai.com](https://openai.com/) |
627
| Llama-2-7b-chat-hf | Huggingface | 2+ Providers | [huggingface.co](https://huggingface.co/) |
628
| Llama-2-13b-chat-hf | Huggingface | 2+ Providers | [huggingface.co](https://huggingface.co/) |
629
| Llama-2-70b-chat-hf | Huggingface | 4+ Providers | [huggingface.co](https://huggingface.co/) |
630
| CodeLlama-34b-Instruct-hf | Huggingface | 3+ Providers | [huggingface.co](https://huggingface.co/) |
631
| Mixtral-8x7B-Instruct-v0.1 | Huggingface | 3+ Providers | [huggingface.co](https://huggingface.co/) |
632
| Mistral-7B-Instruct-v0.1 | Huggingface | 3+ Providers | [huggingface.co](https://huggingface.co/) |
633
| dolphin-2.6-mixtral-8x7b | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
634
| lzlv_70b_fp16_hf | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
635
| airoboros-70b | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
636
| airoboros-l2-70b-gpt4-1.4.1 | Huggingface | g4f.Provider.DeepInfra | [huggingface.co](https://huggingface.co/) |
637
| openchat_3.5 | Huggingface | 2+ Providers | [huggingface.co](https://huggingface.co/) |
638
| gemini | Google | g4f.Provider.Gemini | [gemini.google.com](https://gemini.google.com/) |
639
| gemini-pro | Google | 2+ Providers | [gemini.google.com](https://gemini.google.com/) |
640
| claude-v2 | Anthropic | 2+ Providers | [anthropic.com](https://www.anthropic.com/) |
641
| pi | Inflection | g4f.Provider.Pi | [inflection.ai](https://inflection.ai/) |
638
642
639
643
## 🔗 Related GPT4Free Projects
640
644
@@ -36,6 +36,7 @@ def get_providers() -> list[ProviderType]:
36
36
for provider in __providers__
37
37
if provider.__name__ not in dir(Provider.deprecated)
38
38
and provider.__name__ not in dir(Provider.unfinished)
39
and provider.url is not None
39
40
]
40
41
41
42
def create_response(provider: ProviderType) -> str:
@@ -1,22 +1,15 @@
1
1
import re
2
import sys
3
from pathlib import Path
4
2
from urllib.parse import urlparse
5
6
sys.path.append(str(Path(__file__).parent.parent.parent))
7
8
3
import asyncio
9
from g4f import models
10
from g4f import ChatCompletion
11
from g4f.Provider.base_provider import BaseProvider
12
from etc.testing._providers import get_providers
13
4
5
from g4f import models, ChatCompletion
6
from g4f.base_provider import BaseProvider, BaseRetryProvider, ProviderType
7
from etc.testing._providers import get_providers
14
8
from g4f import debug
15
9
16
10
debug.logging = True
17
11
18
19
async def test_async(provider: type[BaseProvider]):
12
async def test_async(provider: ProviderType):
20
13
if not provider.working:
21
14
return False
22
15
messages = [{"role": "user", "content": "Hello Assistant!"}]
@@ -32,19 +25,17 @@ async def test_async(provider: type[BaseProvider]):
32
25
print(f"{provider.__name__}: {e.__class__.__name__}: {e}")
33
26
return False
34
27
35
36
async def test_async_list(providers: list[type[BaseProvider]]):
28
def test_async_list(providers: list[ProviderType]):
37
29
responses: list = [
38
test_async(_provider)
30
asyncio.run(test_async(_provider))
39
31
for _provider in providers
40
32
]
41
return await asyncio.gather(*responses)
42
33
return responses
43
34
44
35
def print_providers():
45
36
46
37
providers = get_providers()
47
responses = asyncio.run(test_async_list(providers))
38
responses = test_async_list(providers)
48
39
49
40
for type in ("GPT-4", "GPT-3.5", "Other"):
50
41
lines = [
@@ -67,7 +58,7 @@ def print_providers():
67
58
do_continue = True
68
59
if not do_continue:
69
60
continue
70
netloc = urlparse(_provider.url).netloc
61
netloc = urlparse(_provider.url).netloc.replace("www.", "")
71
62
website = f"[{netloc}]({_provider.url})"
72
63
73
64
provider_name = f"`g4f.Provider.{_provider.__name__}`"
@@ -92,48 +83,43 @@ def print_providers():
92
83
93
84
def print_models():
94
85
base_provider_names = {
95
"cohere": "Cohere",
96
86
"google": "Google",
97
87
"openai": "OpenAI",
98
"anthropic": "Anthropic",
99
"replicate": "Replicate",
100
88
"huggingface": "Huggingface",
89
"anthropic": "Anthropic",
90
"inflection": "Inflection"
101
91
}
102
92
provider_urls = {
103
"Bard": "https://bard.google.com/",
104
"H2o": "https://www.h2o.ai/",
105
"Vercel": "https://sdk.vercel.ai/",
93
"google": "https://gemini.google.com/",
94
"openai": "https://openai.com/",
95
"huggingface": "https://huggingface.co/",
96
"anthropic": "https://www.anthropic.com/",
97
"inflection": "https://inflection.ai/",
106
98
}
107
99
108
100
lines = [
109
101
"| Model | Base Provider | Provider | Website |",
110
102
"| ----- | ------------- | -------- | ------- |",
111
103
]
112
113
_models = get_models()
114
for model in _models:
115
if not model.best_provider or model.best_provider.__name__ not in provider_urls:
116
continue
117
104
for name, model in models.ModelUtils.convert.items():
105
if name.startswith("gpt-3.5") or name.startswith("gpt-4"):
106
if name not in ("gpt-3.5-turbo", "gpt-4", "gpt-4-turbo"):
107
continue
118
108
name = re.split(r":|/", model.name)[-1]
119
109
base_provider = base_provider_names[model.base_provider]
120
provider_name = f"g4f.provider.{model.best_provider.__name__}"
121
provider_url = provider_urls[model.best_provider.__name__]
122
netloc = urlparse(provider_url).netloc
110
if not isinstance(model.best_provider, BaseRetryProvider):
111
provider_name = f"g4f.Provider.{model.best_provider.__name__}"
112
else:
113
provider_name = f"{len(model.best_provider.providers)}+ Providers"
114
provider_url = provider_urls[model.base_provider]
115
netloc = urlparse(provider_url).netloc.replace("www.", "")
123
116
website = f"[{netloc}]({provider_url})"
124
117
125
118
lines.append(f"| {name} | {base_provider} | {provider_name} | {website} |")
126
119
127
120
print("\n".join(lines))
128
121
129
130
def get_models():
131
_models = [item[1] for item in models.__dict__.items()]
132
_models = [model for model in _models if type(model) is models.Model]
133
return [model for model in _models if model.name not in ["gpt-3.5-turbo", "gpt-4"]]
134
135
136
122
if __name__ == "__main__":
137
print_providers()
138
print("\n", "-" * 50, "\n")
123
#print_providers()
124
#print("\n", "-" * 50, "\n")
139
125
print_models()
@@ -0,0 +1,94 @@
1
from __future__ import annotations
2
3
import asyncio
4
import time
5
import os
6
from typing import Generator
7
8
from ..cookies import get_cookies
9
from ..webdriver import WebDriver, get_driver_cookies, get_browser
10
from ..image import ImageResponse
11
from ..errors import MissingRequirementsError, MissingAuthError
12
from .bing.create_images import BING_URL, create_images, create_session
13
14
BING_URL = "https://www.bing.com"
15
TIMEOUT_LOGIN = 1200
16
17
def wait_for_login(driver: WebDriver, timeout: int = TIMEOUT_LOGIN) -> None:
18
"""
19
Waits for the user to log in within a given timeout period.
20
21
Args:
22
driver (WebDriver): Webdriver for browser automation.
23
timeout (int): Maximum waiting time in seconds.
24
25
Raises:
26
RuntimeError: If the login process exceeds the timeout.
27
"""
28
driver.get(f"{BING_URL}/")
29
start_time = time.time()
30
while not driver.get_cookie("_U"):
31
if time.time() - start_time > timeout:
32
raise RuntimeError("Timeout error")
33
time.sleep(0.5)
34
35
def get_cookies_from_browser(proxy: str = None) -> dict[str, str]:
36
"""
37
Retrieves cookies from the browser using webdriver.
38
39
Args:
40
proxy (str, optional): Proxy configuration.
41
42
Returns:
43
dict[str, str]: Retrieved cookies.
44
"""
45
with get_browser(proxy=proxy) as driver:
46
wait_for_login(driver)
47
time.sleep(1)
48
return get_driver_cookies(driver)
49
50
class CreateImagesBing:
51
"""A class for creating images using Bing."""
52
53
def __init__(self, cookies: dict[str, str] = {}, proxy: str = None) -> None:
54
self.cookies = cookies
55
self.proxy = proxy
56
57
def create_completion(self, prompt: str) -> Generator[ImageResponse, None, None]:
58
"""
59
Generator for creating imagecompletion based on a prompt.
60
61
Args:
62
prompt (str): Prompt to generate images.
63
64
Yields:
65
Generator[str, None, None]: The final output as markdown formatted string with images.
66
"""
67
cookies = self.cookies or get_cookies(".bing.com", False)
68
if "_U" not in cookies:
69
login_url = os.environ.get("G4F_LOGIN_URL")
70
if login_url:
71
yield f"Please login: [Bing]({login_url})\n\n"
72
try:
73
self.cookies = get_cookies_from_browser(self.proxy)
74
except MissingRequirementsError as e:
75
raise MissingAuthError(f'Missing "_U" cookie. {e}')
76
yield asyncio.run(self.create_async(prompt))
77
78
async def create_async(self, prompt: str) -> ImageResponse:
79
"""
80
Asynchronously creates a markdown formatted string with images based on the prompt.
81
82
Args:
83
prompt (str): Prompt to generate images.
84
85
Returns:
86
str: Markdown formatted string with images.
87
"""
88
cookies = self.cookies or get_cookies(".bing.com", False)
89
if "_U" not in cookies:
90
raise MissingAuthError('Missing "_U" cookie')
91
proxy = os.environ.get("G4F_PROXY")
92
async with create_session(cookies, proxy) as session:
93
images = await create_images(session, prompt, self.proxy)
94
return ImageResponse(images, prompt, {"preview": "{image}?w=200&h=200"})
@@ -10,7 +10,6 @@ class GptChatly(AsyncProvider):
10
10
working = True
11
11
supports_message_history = True
12
12
supports_gpt_35_turbo = True
13
supports_gpt_4 = True
14
13
15
14
@classmethod
16
15
async def create_async(
@@ -13,7 +13,7 @@ class SearchTypes():
13
13
14
14
class Hashnode(AsyncGeneratorProvider):
15
15
url = "https://hashnode.com"
16
working = True
16
working = False
17
17
supports_message_history = True
18
18
supports_gpt_35_turbo = True
19
19
_sources = []
@@ -67,7 +67,7 @@ class Phind(AsyncGeneratorProvider):
67
67
if chunk.startswith(b'<PHIND_DONE/>'):
68
68
break
69
69
if chunk.startswith(b'<PHIND_BACKEND_ERROR>'):
70
raise RuntimeError(f"Response: {chunk}")
70
raise RuntimeError(f"Response: {chunk.decode()}")
71
71
if chunk.startswith(b'<PHIND_WEBRESULTS>') or chunk.startswith(b'<PHIND_FOLLOWUP>'):
72
72
pass
73
73
elif chunk.startswith(b"<PHIND_METADATA>") or chunk.startswith(b"<PHIND_INDICATOR>"):
@@ -53,6 +53,8 @@ from .Vercel import Vercel
53
53
from .Ylokh import Ylokh
54
54
from .You import You
55
55
56
from .CreateImagesBing import CreateImagesBing
57
56
58
import sys
57
59
58
60
__modules__: list = [
@@ -7,10 +7,9 @@ from __future__ import annotations
7
7
import asyncio
8
8
import time
9
9
import json
10
import os
11
10
from aiohttp import ClientSession, BaseConnector
12
11
from urllib.parse import quote
13
from typing import Generator, List, Dict
12
from typing import List, Dict
14
13
15
14
try:
16
15
from bs4 import BeautifulSoup
@@ -19,14 +18,11 @@ except ImportError:
19
18
has_requirements = False
20
19
21
20
from ..create_images import CreateImagesProvider
22
from ..helper import get_cookies, get_connector
23
from ...webdriver import WebDriver, get_driver_cookies, get_browser
21
from ..helper import get_connector
24
22
from ...base_provider import ProviderType
25
from ...image import ImageResponse
26
from ...errors import MissingRequirementsError, MissingAuthError
23
from ...errors import MissingRequirementsError
27
24
28
25
BING_URL = "https://www.bing.com"
29
TIMEOUT_LOGIN = 1200
30
26
TIMEOUT_IMAGE_CREATION = 300
31
27
ERRORS = [
32
28
"this prompt is being reviewed",
@@ -39,24 +35,6 @@ BAD_IMAGES = [
39
35
"https://r.bing.com/rp/TX9QuO3WzcCJz1uaaSwQAz39Kb0.jpg",
40
36
]
41
37
42
def wait_for_login(driver: WebDriver, timeout: int = TIMEOUT_LOGIN) -> None:
43
"""
44
Waits for the user to log in within a given timeout period.
45
46
Args:
47
driver (WebDriver): Webdriver for browser automation.
48
timeout (int): Maximum waiting time in seconds.
49
50
Raises:
51
RuntimeError: If the login process exceeds the timeout.
52
"""
53
driver.get(f"{BING_URL}/")
54
start_time = time.time()
55
while not driver.get_cookie("_U"):
56
if time.time() - start_time > timeout:
57
raise RuntimeError("Timeout error")
58
time.sleep(0.5)
59
60
38
def create_session(cookies: Dict[str, str], proxy: str = None, connector: BaseConnector = None) -> ClientSession:
61
39
"""
62
40
Creates a new client session with specified cookies and headers.
@@ -170,67 +148,6 @@ def read_images(html_content: str) -> List[str]:
170
148
raise RuntimeError("No images found")
171
149
return images
172
150
173
def get_cookies_from_browser(proxy: str = None) -> dict[str, str]:
174
"""
175
Retrieves cookies from the browser using webdriver.
176
177
Args:
178
proxy (str, optional): Proxy configuration.
179
180
Returns:
181
dict[str, str]: Retrieved cookies.
182
"""
183
with get_browser(proxy=proxy) as driver:
184
wait_for_login(driver)
185
time.sleep(1)
186
return get_driver_cookies(driver)
187
188
class CreateImagesBing:
189
"""A class for creating images using Bing."""
190
191
def __init__(self, cookies: dict[str, str] = {}, proxy: str = None) -> None:
192
self.cookies = cookies
193
self.proxy = proxy
194
195
def create_completion(self, prompt: str) -> Generator[ImageResponse, None, None]:
196
"""
197
Generator for creating imagecompletion based on a prompt.
198
199
Args:
200
prompt (str): Prompt to generate images.
201
202
Yields:
203
Generator[str, None, None]: The final output as markdown formatted string with images.
204
"""
205
cookies = self.cookies or get_cookies(".bing.com", False)
206
if "_U" not in cookies:
207
login_url = os.environ.get("G4F_LOGIN_URL")
208
if login_url:
209
yield f"Please login: [Bing]({login_url})\n\n"
210
try:
211
self.cookies = get_cookies_from_browser(self.proxy)
212
except MissingRequirementsError as e:
213
raise MissingAuthError(f'Missing "_U" cookie. {e}')
214
yield asyncio.run(self.create_async(prompt))
215
216
async def create_async(self, prompt: str) -> ImageResponse:
217
"""
218
Asynchronously creates a markdown formatted string with images based on the prompt.
219
220
Args:
221
prompt (str): Prompt to generate images.
222
223
Returns:
224
str: Markdown formatted string with images.
225
"""
226
cookies = self.cookies or get_cookies(".bing.com", False)
227
if "_U" not in cookies:
228
raise MissingAuthError('Missing "_U" cookie')
229
proxy = os.environ.get("G4F_PROXY")
230
async with create_session(cookies, proxy) as session:
231
images = await create_images(session, prompt, self.proxy)
232
return ImageResponse(images, prompt, {"preview": "{image}?w=200&h=200"})
233
234
151
def patch_provider(provider: ProviderType) -> CreateImagesProvider:
235
152
"""
236
153
Patches a provider to include image creation capabilities.
@@ -241,6 +158,7 @@ def patch_provider(provider: ProviderType) -> CreateImagesProvider:
241
158
Returns:
242
159
CreateImagesProvider: The patched provider with image creation capabilities.
243
160
"""
161
from ..CreateImagesBing import CreateImagesBing
244
162
service = CreateImagesBing()
245
163
return CreateImagesProvider(
246
164
provider,
@@ -1,104 +1,13 @@
1
1
from __future__ import annotations
2
2
3
import os
4
3
import random
5
4
import secrets
6
5
import string
7
6
from aiohttp import BaseConnector
8
7
9
try:
10
from platformdirs import user_config_dir
11
has_platformdirs = True
12
except ImportError:
13
has_platformdirs = False
14
try:
15
from browser_cookie3 import (
16
chrome, chromium, opera, opera_gx,
17
brave, edge, vivaldi, firefox,
18
_LinuxPasswordManager, BrowserCookieError
19
)
20
has_browser_cookie3 = True
21
except ImportError:
22
has_browser_cookie3 = False
23
24
from ..typing import Dict, Messages, Cookies, Optional
25
from ..errors import MissingAiohttpSocksError, MissingRequirementsError
26
from .. import debug
27
28
# Global variable to store cookies
29
_cookies: Dict[str, Cookies] = {}
30
31
if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null":
32
_LinuxPasswordManager.get_password = lambda a, b: b"secret"
33
34
def get_cookies(domain_name: str = '', raise_requirements_error: bool = True) -> Dict[str, str]:
35
"""
36
Load cookies for a given domain from all supported browsers and cache the results.
37
38
Args:
39
domain_name (str): The domain for which to load cookies.
40
41
Returns:
42
Dict[str, str]: A dictionary of cookie names and values.
43
"""
44
if domain_name in _cookies:
45
return _cookies[domain_name]
46
47
cookies = load_cookies_from_browsers(domain_name, raise_requirements_error)
48
_cookies[domain_name] = cookies
49
return cookies
50
51
def set_cookies(domain_name: str, cookies: Cookies = None) -> None:
52
if cookies:
53
_cookies[domain_name] = cookies
54
elif domain_name in _cookies:
55
_cookies.pop(domain_name)
56
57
def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool = True) -> Cookies:
58
"""
59
Helper function to load cookies from various browsers.
60
61
Args:
62
domain_name (str): The domain for which to load cookies.
63
64
Returns:
65
Dict[str, str]: A dictionary of cookie names and values.
66
"""
67
if not has_browser_cookie3:
68
if raise_requirements_error:
69
raise MissingRequirementsError('Install "browser_cookie3" package')
70
return {}
71
cookies = {}
72
for cookie_fn in [_g4f, chrome, chromium, opera, opera_gx, brave, edge, vivaldi, firefox]:
73
try:
74
cookie_jar = cookie_fn(domain_name=domain_name)
75
if len(cookie_jar) and debug.logging:
76
print(f"Read cookies from {cookie_fn.__name__} for {domain_name}")
77
for cookie in cookie_jar:
78
if cookie.name not in cookies:
79
cookies[cookie.name] = cookie.value
80
except BrowserCookieError:
81
pass
82
except Exception as e:
83
if debug.logging:
84
print(f"Error reading cookies from {cookie_fn.__name__} for {domain_name}: {e}")
85
return cookies
86
87
def _g4f(domain_name: str) -> list:
88
"""
89
Load cookies from the 'g4f' browser (if exists).
90
91
Args:
92
domain_name (str): The domain for which to load cookies.
93
94
Returns:
95
list: List of cookies.
96
"""
97
if not has_platformdirs:
98
return []
99
user_data_dir = user_config_dir("g4f")
100
cookie_file = os.path.join(user_data_dir, "Default", "Cookies")
101
return [] if not os.path.exists(cookie_file) else chrome(cookie_file, domain_name)
8
from ..typing import Messages, Optional
9
from ..errors import MissingRequirementsError
10
from ..cookies import get_cookies
102
11
103
12
def format_prompt(messages: Messages, add_special_tokens=False) -> str:
104
13
"""
@@ -149,5 +58,5 @@ def get_connector(connector: BaseConnector = None, proxy: str = None) -> Optiona
149
58
from aiohttp_socks import ProxyConnector
150
59
connector = ProxyConnector.from_url(proxy)
151
60
except ImportError:
152
raise MissingAiohttpSocksError('Install "aiohttp_socks" package for proxy support')
61
raise MissingRequirementsError('Install "aiohttp_socks" package for proxy support')
153
62
return connector
@@ -43,7 +43,7 @@ class ThebApi(AbstractProvider, ProviderModelMixin):
43
43
model: str,
44
44
messages: Messages,
45
45
stream: bool,
46
auth: str,
46
auth: str = None,
47
47
proxy: str = None,
48
48
**kwargs
49
49
) -> CreateResult:
@@ -6,9 +6,9 @@ from .errors import *
6
6
from .models import Model, ModelUtils
7
7
from .Provider import AsyncGeneratorProvider, ProviderUtils
8
8
from .typing import Messages, CreateResult, AsyncResult, Union
9
from .cookies import get_cookies, set_cookies
9
10
from . import debug, version
10
11
from .base_provider import BaseRetryProvider, ProviderType
11
from .Provider.helper import get_cookies, set_cookies
12
12
from .Provider.base_provider import ProviderModelMixin
13
13
14
14
def get_model_and_provider(model : Union[Model, str],