返回提交历史
Modified
README.md
+57
-63
Modified
etc/testing/_providers.py
+8
-2
Modified
etc/tool/readme_table.py
+55
-74
Modified
g4f/Provider/MyShell.py
+1
-0
Modified
g4f/Provider/needs_auth/OpenaiChat.py
+69
-45
Modified
g4f/models.py
+1
-1
Modified
requirements.txt
+1
-1
XFEstudio/gpt4free
Add auto_continue to OpenaiChat Update readme provider tables
745ea57c
代码差异
7 个文件
+192
-186
@@ -371,73 +371,67 @@ if __name__ == "__main__":
371
371
```
372
372
373
373
## 🚀 Providers and Models
374
374
375
### GPT-4
375
| Website| Provider| gpt-3.5 | gpt-4 | Stream | Async | Status | Auth |
376
| ------ | ------- | ------- | ----- | --------- | --------- | ------ | ---- |
377
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ | ✔️ |  | ❌ |
378
| [chat.geekgpt.org](https://chat.geekgpt.org) | `g4f.Provider.GeekGpt` | ✔️ | ✔️ | ✔️ | ❌ |  | ❌ |
379
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ | ✔️ |  | ❌ |
380
| [www.phind.com](https://www.phind.com) | `g4f.Provider.Phind` | ❌ | ✔️ | ✔️ | ✔️ |  | ❌ |
381
| [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ | ❌ |  | ✔️ |
382
| [chat.aivvm.com](https://chat.aivvm.com) | `g4f.Provider.Aivvm` | ✔️ | ✔️ | ✔️ | ❌ |  | ❌ |
383
| [gptchatly.com](https://gptchatly.com) | `g4f.Provider.GptChatly` | ✔️ | ✔️ | ❌ | ✔️ |  | ❌ |
384
| [supertest.lockchat.app](http://supertest.lockchat.app) | `g4f.Provider.Lockchat` | ✔️ | ✔️ | ✔️ | ❌ |  | ❌ |
385
| [app.myshell.ai](https://app.myshell.ai/chat) | `g4f.Provider.Myshell` | ✔️ | ✔️ | ✔️ | ✔️ |  | ❌ |
376
377
| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
378
| ------ | ------- | ------- | ----- | ------ | ------ | ---- |
379
| [bing.com](https://bing.com/chat) | `g4f.Provider.Bing` | ❌ | ✔️ | ✔️ |  | ❌ |
380
| [chat.geekgpt.org](https://chat.geekgpt.org) | `g4f.Provider.GeekGpt` | ✔️ | ✔️ | ✔️ |  | ❌ |
381
| [gptchatly.com](https://gptchatly.com) | `g4f.Provider.GptChatly` | ✔️ | ✔️ | ❌ |  | ❌ |
382
| [liaobots.site](https://liaobots.site) | `g4f.Provider.Liaobots` | ✔️ | ✔️ | ✔️ |  | ❌ |
383
| [www.phind.com](https://www.phind.com) | `g4f.Provider.Phind` | ❌ | ✔️ | ✔️ |  | ❌ |
384
| [raycast.com](https://raycast.com) | `g4f.Provider.Raycast` | ✔️ | ✔️ | ✔️ |  | ✔️ |
386
385
387
386
### GPT-3.5
388
387
389
| Website| Provider| gpt-3.5 | Stream | Async | Status | Auth |
390
| ------ | ------- | ------- | --------- | --------- | ------ | ---- |
391
| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | `g4f.Provider.Yqcloud` | ✔️ | ✔️ | ✔️ |  | ❌ |
392
| [www.aitianhu.com](https://www.aitianhu.com) | `g4f.Provider.AItianhu` | ✔️ | ✔️ | ✔️ |  | ❌ |
393
| [chat3.aiyunos.top](https://chat3.aiyunos.top/) | `g4f.Provider.AItianhuSpace` | ✔️ | ✔️ | ✔️ |  | ❌ |
394
| [e.aiask.me](https://e.aiask.me) | `g4f.Provider.AiAsk` | ✔️ | ✔️ | ✔️ |  | ❌ |
395
| [chat-gpt.org](https://chat-gpt.org/chat) | `g4f.Provider.Aichat` | ✔️ | ❌ | ✔️ |  | ❌ |
396
| [www.chatbase.co](https://www.chatbase.co) | `g4f.Provider.ChatBase` | ✔️ | ✔️ | ✔️ |  | ❌ |
397
| [chatgpt.ai](https://chatgpt.ai/) | `g4f.Provider.ChatgptAi` | ✔️ | ❌ | ✔️ |  | ❌ |
398
| [chatgptfree.ai](https://chatgptfree.ai) | `g4f.Provider.ChatgptFree` | ✔️ | ❌ | ✔️ |  | ❌ |
399
| [chatgptx.de](https://chatgptx.de) | `g4f.Provider.ChatgptX` | ✔️ | ✔️ | ✔️ |  | ❌ |
400
| [freegpts1.aifree.site](https://freegpts1.aifree.site/) | `g4f.Provider.FreeGpt` | ✔️ | ✔️ | ✔️ |  | ❌ |
401
| [gptalk.net](https://gptalk.net) | `g4f.Provider.GPTalk` | ✔️ | ✔️ | ✔️ |  | ❌ |
402
| [ai18.gptforlove.com](https://ai18.gptforlove.com) | `g4f.Provider.GptForLove` | ✔️ | ✔️ | ✔️ |  | ❌ |
403
| [gptgo.ai](https://gptgo.ai) | `g4f.Provider.GptGo` | ✔️ | ✔️ | ✔️ |  | ❌ |
404
| [www.llama2.ai](https://www.llama2.ai) | `g4f.Provider.Llama2` | ✔️ | ✔️ | ✔️ |  | ❌ |
405
| [noowai.com](https://noowai.com) | `g4f.Provider.NoowAi` | ✔️ | ✔️ | ✔️ |  | ❌ |
406
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ✔️ | ✔️ |  | ✔️ |
407
| [theb.ai](https://theb.ai) | `g4f.Provider.Theb` | ✔️ | ✔️ | ❌ |  | ✔️ |
408
| [sdk.vercel.ai](https://sdk.vercel.ai) | `g4f.Provider.Vercel` | ✔️ | ✔️ | ❌ |  | ❌ |
409
| [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ✔️ | ✔️ |  | ❌ |
410
| [chat.acytoo.com](https://chat.acytoo.com) | `g4f.Provider.Acytoo` | ✔️ | ✔️ | ✔️ |  | ❌ |
411
| [aiservice.vercel.app](https://aiservice.vercel.app/) | `g4f.Provider.AiService` | ✔️ | ❌ | ❌ |  | ❌ |
412
| [aibn.cc](https://aibn.cc) | `g4f.Provider.Aibn` | ✔️ | ✔️ | ✔️ |  | ❌ |
413
| [ai.ls](https://ai.ls) | `g4f.Provider.Ails` | ✔️ | ✔️ | ✔️ |  | ❌ |
414
| [chataigpt.org](https://chataigpt.org) | `g4f.Provider.ChatAiGpt` | ✔️ | ✔️ | ✔️ |  | ❌ |
415
| [chatforai.store](https://chatforai.store) | `g4f.Provider.ChatForAi` | ✔️ | ✔️ | ✔️ |  | ❌ |
416
| [chatgpt4online.org](https://chatgpt4online.org) | `g4f.Provider.Chatgpt4Online` | ✔️ | ✔️ | ✔️ |  | ❌ |
417
| [chat.chatgptdemo.net](https://chat.chatgptdemo.net) | `g4f.Provider.ChatgptDemo` | ✔️ | ✔️ | ✔️ |  | ❌ |
418
| [chatgptduo.com](https://chatgptduo.com) | `g4f.Provider.ChatgptDuo` | ✔️ | ❌ | ✔️ |  | ❌ |
419
| [chatgptlogin.ai](https://chatgptlogin.ai) | `g4f.Provider.ChatgptLogin` | ✔️ | ✔️ | ✔️ |  | ❌ |
420
| [ava-ai-ef611.web.app](https://ava-ai-ef611.web.app) | `g4f.Provider.CodeLinkAva` | ✔️ | ✔️ | ✔️ |  | ❌ |
421
| [cromicle.top](https://cromicle.top) | `g4f.Provider.Cromicle` | ✔️ | ✔️ | ✔️ |  | ❌ |
422
| [chat.dfehub.com](https://chat.dfehub.com/) | `g4f.Provider.DfeHub` | ✔️ | ✔️ | ❌ |  | ❌ |
423
| [free.easychat.work](https://free.easychat.work) | `g4f.Provider.EasyChat` | ✔️ | ✔️ | ❌ |  | ❌ |
424
| [next.eqing.tech](https://next.eqing.tech/) | `g4f.Provider.Equing` | ✔️ | ✔️ | ❌ |  | ❌ |
425
| [chat9.fastgpt.me](https://chat9.fastgpt.me/) | `g4f.Provider.FastGpt` | ✔️ | ✔️ | ❌ |  | ❌ |
426
| [forefront.com](https://forefront.com) | `g4f.Provider.Forefront` | ✔️ | ✔️ | ❌ |  | ❌ |
427
| [chat.getgpt.world](https://chat.getgpt.world/) | `g4f.Provider.GetGpt` | ✔️ | ✔️ | ❌ |  | ❌ |
428
| [gptgod.site](https://gptgod.site) | `g4f.Provider.GptGod` | ✔️ | ✔️ | ✔️ |  | ❌ |
429
| [komo.ai](https://komo.ai/api/ask) | `g4f.Provider.Komo` | ✔️ | ✔️ | ✔️ |  | ❌ |
430
| [ai.okmiku.com](https://ai.okmiku.com) | `g4f.Provider.MikuChat` | ✔️ | ✔️ | ✔️ |  | ❌ |
431
| [opchatgpts.net](https://opchatgpts.net) | `g4f.Provider.Opchatgpts` | ✔️ | ✔️ | ✔️ |  | ❌ |
432
| [www.perplexity.ai](https://www.perplexity.ai) | `g4f.Provider.PerplexityAi` | ✔️ | ❌ | ✔️ |  | ❌ |
433
| [talkai.info](https://talkai.info) | `g4f.Provider.TalkAi` | ✔️ | ✔️ | ✔️ |  | ❌ |
434
| [p5.v50.ltd](https://p5.v50.ltd) | `g4f.Provider.V50` | ✔️ | ❌ | ❌ |  | ❌ |
435
| [app.vitalentum.io](https://app.vitalentum.io) | `g4f.Provider.Vitalentum` | ✔️ | ✔️ | ✔️ |  | ❌ |
436
| [wewordle.org](https://wewordle.org) | `g4f.Provider.Wewordle` | ✔️ | ❌ | ✔️ |  | ❌ |
437
| [chat.wuguokai.xyz](https://chat.wuguokai.xyz) | `g4f.Provider.Wuguokai` | ✔️ | ❌ | ❌ |  | ❌ |
438
| [chat.ylokh.xyz](https://chat.ylokh.xyz) | `g4f.Provider.Ylokh` | ✔️ | ✔️ | ✔️ |  | ❌ |
439
440
### Other Models
388
| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
389
| ------ | ------- | ------- | ----- | ------ | ------ | ---- |
390
| [www.aitianhu.com](https://www.aitianhu.com) | `g4f.Provider.AItianhu` | ✔️ | ❌ | ✔️ |  | ❌ |
391
| [chat3.aiyunos.top](https://chat3.aiyunos.top/) | `g4f.Provider.AItianhuSpace` | ✔️ | ❌ | ✔️ |  | ❌ |
392
| [e.aiask.me](https://e.aiask.me) | `g4f.Provider.AiAsk` | ✔️ | ❌ | ✔️ |  | ❌ |
393
| [chat-gpt.org](https://chat-gpt.org/chat) | `g4f.Provider.Aichat` | ✔️ | ❌ | ❌ |  | ❌ |
394
| [www.chatbase.co](https://www.chatbase.co) | `g4f.Provider.ChatBase` | ✔️ | ❌ | ✔️ |  | ❌ |
395
| [chatforai.store](https://chatforai.store) | `g4f.Provider.ChatForAi` | ✔️ | ❌ | ✔️ |  | ❌ |
396
| [chatgpt.ai](https://chatgpt.ai) | `g4f.Provider.ChatgptAi` | ✔️ | ❌ | ✔️ |  | ❌ |
397
| [chatgptx.de](https://chatgptx.de) | `g4f.Provider.ChatgptX` | ✔️ | ❌ | ✔️ |  | ❌ |
398
| [chat-shared2.zhile.io](https://chat-shared2.zhile.io) | `g4f.Provider.FakeGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
399
| [freegpts1.aifree.site](https://freegpts1.aifree.site/) | `g4f.Provider.FreeGpt` | ✔️ | ❌ | ✔️ |  | ❌ |
400
| [gptalk.net](https://gptalk.net) | `g4f.Provider.GPTalk` | ✔️ | ❌ | ✔️ |  | ❌ |
401
| [ai18.gptforlove.com](https://ai18.gptforlove.com) | `g4f.Provider.GptForLove` | ✔️ | ❌ | ✔️ |  | ❌ |
402
| [gptgo.ai](https://gptgo.ai) | `g4f.Provider.GptGo` | ✔️ | ❌ | ✔️ |  | ❌ |
403
| [hashnode.com](https://hashnode.com) | `g4f.Provider.Hashnode` | ✔️ | ❌ | ✔️ |  | ❌ |
404
| [app.myshell.ai](https://app.myshell.ai/chat) | `g4f.Provider.MyShell` | ✔️ | ❌ | ✔️ |  | ❌ |
405
| [noowai.com](https://noowai.com) | `g4f.Provider.NoowAi` | ✔️ | ❌ | ✔️ |  | ❌ |
406
| [chat.openai.com](https://chat.openai.com) | `g4f.Provider.OpenaiChat` | ✔️ | ❌ | ✔️ |  | ✔️ |
407
| [theb.ai](https://theb.ai) | `g4f.Provider.Theb` | ✔️ | ❌ | ✔️ |  | ✔️ |
408
| [sdk.vercel.ai](https://sdk.vercel.ai) | `g4f.Provider.Vercel` | ✔️ | ❌ | ✔️ |  | ❌ |
409
| [you.com](https://you.com) | `g4f.Provider.You` | ✔️ | ❌ | ✔️ |  | ❌ |
410
| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | `g4f.Provider.Yqcloud` | ✔️ | ❌ | ✔️ |  | ❌ |
411
| [chat.acytoo.com](https://chat.acytoo.com) | `g4f.Provider.Acytoo` | ✔️ | ❌ | ✔️ |  | ❌ |
412
| [aibn.cc](https://aibn.cc) | `g4f.Provider.Aibn` | ✔️ | ❌ | ✔️ |  | ❌ |
413
| [ai.ls](https://ai.ls) | `g4f.Provider.Ails` | ✔️ | ❌ | ✔️ |  | ❌ |
414
| [chatgpt4online.org](https://chatgpt4online.org) | `g4f.Provider.Chatgpt4Online` | ✔️ | ❌ | ✔️ |  | ❌ |
415
| [chat.chatgptdemo.net](https://chat.chatgptdemo.net) | `g4f.Provider.ChatgptDemo` | ✔️ | ❌ | ✔️ |  | ❌ |
416
| [chatgptduo.com](https://chatgptduo.com) | `g4f.Provider.ChatgptDuo` | ✔️ | ❌ | ❌ |  | ❌ |
417
| [chatgptfree.ai](https://chatgptfree.ai) | `g4f.Provider.ChatgptFree` | ✔️ | ❌ | ❌ |  | ❌ |
418
| [chatgptlogin.ai](https://chatgptlogin.ai) | `g4f.Provider.ChatgptLogin` | ✔️ | ❌ | ✔️ |  | ❌ |
419
| [cromicle.top](https://cromicle.top) | `g4f.Provider.Cromicle` | ✔️ | ❌ | ✔️ |  | ❌ |
420
| [gptgod.site](https://gptgod.site) | `g4f.Provider.GptGod` | ✔️ | ❌ | ✔️ |  | ❌ |
421
| [opchatgpts.net](https://opchatgpts.net) | `g4f.Provider.Opchatgpts` | ✔️ | ❌ | ✔️ |  | ❌ |
422
| [chat.ylokh.xyz](https://chat.ylokh.xyz) | `g4f.Provider.Ylokh` | ✔️ | ❌ | ✔️ |  | ❌ |
423
424
### Other
425
426
| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |
427
| ------ | ------- | ------- | ----- | ------ | ------ | ---- |
428
| [bard.google.com](https://bard.google.com) | `g4f.Provider.Bard` | ❌ | ❌ | ❌ |  | ✔️ |
429
| [deepinfra.com](https://deepinfra.com) | `g4f.Provider.DeepInfra` | ❌ | ❌ | ✔️ |  | ❌ |
430
| [huggingface.co](https://huggingface.co/chat) | `g4f.Provider.HuggingChat` | ❌ | ❌ | ✔️ |  | ✔️ |
431
| [www.llama2.ai](https://www.llama2.ai) | `g4f.Provider.Llama2` | ❌ | ❌ | ✔️ |  | ❌ |
432
| [open-assistant.io](https://open-assistant.io/chat) | `g4f.Provider.OpenAssistant` | ❌ | ❌ | ✔️ |  | ✔️ |
433
434
### Models
441
435
442
436
| Model | Base Provider | Provider | Website |
443
437
| --------------------------------------- | ------------- | ------------------- | ------------------------------------------- |
@@ -35,8 +35,14 @@ def main():
35
35
def get_providers() -> list[type[BaseProvider]]:
36
36
providers = dir(Provider)
37
37
providers = [getattr(Provider, provider) for provider in providers if provider != "RetryProvider"]
38
providers = [provider for provider in providers if isinstance(provider, type)]
39
return [provider for provider in providers if issubclass(provider, BaseProvider)]
38
providers = [provider for provider in providers if isinstance(provider, type) and hasattr(provider, "url")]
39
return [
40
provider
41
for provider in providers
42
if issubclass(provider, BaseProvider)
43
and provider.__name__ not in dir(Provider.deprecated)
44
and provider.__name__ not in dir(Provider.unfinished)
45
]
40
46
41
47
42
48
def create_response(_provider: type[BaseProvider]) -> str:
@@ -3,58 +3,32 @@ import sys
3
3
from pathlib import Path
4
4
from urllib.parse import urlparse
5
5
6
sys.path.append(str(Path(__file__).parent.parent))
6
sys.path.append(str(Path(__file__).parent.parent.parent))
7
7
8
8
import asyncio
9
9
from g4f import models
10
from g4f.Provider.base_provider import AsyncProvider, BaseProvider
11
from g4f.Provider.retry_provider import RetryProvider
12
from testing._providers import get_providers
13
14
logging = False
15
16
17
def print_imports():
18
print("##### Providers:")
19
print("```py")
20
print("from g4f.Provider import (")
21
for _provider in get_providers():
22
if _provider.working:
23
print(f" {_provider.__name__},")
24
25
print(")")
26
print("# Usage:")
27
print("response = g4f.ChatCompletion.create(..., provider=ProviderName)")
28
print("```")
29
print()
30
print()
31
32
def print_async():
33
print("##### Async support:")
34
print("```py")
35
print("_providers = [")
36
for _provider in get_providers():
37
if _provider.working and issubclass(_provider, AsyncProvider):
38
print(f" g4f.Provider.{_provider.__name__},")
39
print("]")
40
print("```")
41
print()
42
print()
10
from g4f import ChatCompletion
11
from g4f.Provider.base_provider import BaseProvider
12
from etc.testing._providers import get_providers
13
14
from g4f import debug
15
16
debug.logging = True
43
17
44
18
45
19
async def test_async(provider: type[BaseProvider]):
46
20
if not provider.working:
47
21
return False
48
model = models.gpt_35_turbo.name if provider.supports_gpt_35_turbo else models.default.name
49
22
messages = [{"role": "user", "content": "Hello Assistant!"}]
50
23
try:
51
if issubclass(provider, AsyncProvider):
52
response = await provider.create_async(model=model, messages=messages)
53
else:
54
response = provider.create_completion(model=model, messages=messages, stream=False)
24
response = await asyncio.wait_for(ChatCompletion.create_async(
25
model=models.default,
26
messages=messages,
27
provider=provider
28
), 30)
55
29
return bool(response)
56
30
except Exception as e:
57
if logging:
31
if debug.logging:
58
32
print(f"{provider.__name__}: {e.__class__.__name__}: {e}")
59
33
return False
60
34
@@ -68,44 +42,53 @@ async def test_async_list(providers: list[type[BaseProvider]]):
68
42
69
43
70
44
def print_providers():
71
lines = [
72
"| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Asynchron | Status | Auth |",
73
"| ------ | ------- | ------- | ----- | --------- | --------- | ------ | ---- |",
74
]
75
45
76
46
providers = get_providers()
77
47
responses = asyncio.run(test_async_list(providers))
78
48
79
for is_working in (True, False):
80
for idx, _provider in enumerate(providers):
81
if is_working != _provider.working:
82
continue
83
if _provider == RetryProvider:
84
continue
85
86
netloc = urlparse(_provider.url).netloc
87
website = f"[{netloc}]({_provider.url})"
88
89
provider_name = f"`g4f.Provider.{_provider.__name__}`"
90
91
has_gpt_35 = "✔️" if _provider.supports_gpt_35_turbo else "❌"
92
has_gpt_4 = "✔️" if _provider.supports_gpt_4 else "❌"
93
stream = "✔️" if _provider.supports_stream else "❌"
94
can_async = "✔️" if issubclass(_provider, AsyncProvider) else "❌"
95
if _provider.working:
96
status = ''
97
if responses[idx]:
49
for type in ("GPT-4", "GPT-3.5", "Other"):
50
lines = [
51
"",
52
f"### {type}",
53
"",
54
"| Website | Provider | GPT-3.5 | GPT-4 | Stream | Status | Auth |",
55
"| ------ | ------- | ------- | ----- | ------ | ------ | ---- |",
56
]
57
for is_working in (True, False):
58
for idx, _provider in enumerate(providers):
59
if is_working != _provider.working:
60
continue
61
do_continue = False
62
if type == "GPT-4" and _provider.supports_gpt_4:
63
do_continue = True
64
elif type == "GPT-3.5" and not _provider.supports_gpt_4 and _provider.supports_gpt_35_turbo:
65
do_continue = True
66
elif type == "Other" and not _provider.supports_gpt_4 and not _provider.supports_gpt_35_turbo:
67
do_continue = True
68
if not do_continue:
69
continue
70
netloc = urlparse(_provider.url).netloc
71
website = f"[{netloc}]({_provider.url})"
72
73
provider_name = f"`g4f.Provider.{_provider.__name__}`"
74
75
has_gpt_35 = "✔️" if _provider.supports_gpt_35_turbo else "❌"
76
has_gpt_4 = "✔️" if _provider.supports_gpt_4 else "❌"
77
stream = "✔️" if _provider.supports_stream else "❌"
78
if _provider.working:
98
79
status = ''
80
if responses[idx]:
81
status = ''
82
else:
83
status = ''
99
84
else:
100
status = ''
101
else:
102
status = ''
103
auth = "✔️" if _provider.needs_auth else "❌"
104
105
lines.append(
106
f"| {website} | {provider_name} | {has_gpt_35} | {has_gpt_4} | {stream} | {can_async} | {status} | {auth} |"
107
)
108
print("\n".join(lines))
85
status = ''
86
auth = "✔️" if _provider.needs_auth else "❌"
87
88
lines.append(
89
f"| {website} | {provider_name} | {has_gpt_35} | {has_gpt_4} | {stream} | {status} | {auth} |"
90
)
91
print("\n".join(lines))
109
92
110
93
def print_models():
111
94
base_provider_names = {
@@ -151,8 +134,6 @@ def get_models():
151
134
152
135
153
136
if __name__ == "__main__":
154
print_imports()
155
print_async()
156
137
print_providers()
157
138
print("\n", "-" * 50, "\n")
158
139
print_models()
@@ -10,6 +10,7 @@ from .helper import format_prompt
10
10
class MyShell(AsyncGeneratorProvider):
11
11
url = "https://app.myshell.ai/chat"
12
12
working = True
13
supports_gpt_35_turbo = True
13
14
14
15
@classmethod
15
16
async def create_async_generator(
@@ -1,6 +1,6 @@
1
1
from __future__ import annotations
2
2
3
import uuid, json, time, os
3
import uuid, json, time, asyncio
4
4
from py_arkose_generator.arkose import get_values_for_request
5
5
6
6
from ..base_provider import AsyncGeneratorProvider
@@ -24,6 +24,7 @@ class OpenaiChat(AsyncGeneratorProvider):
24
24
proxy: str = None,
25
25
timeout: int = 120,
26
26
access_token: str = None,
27
auto_continue: bool = False,
27
28
cookies: dict = None,
28
29
**kwargs
29
30
) -> AsyncResult:
@@ -34,50 +35,73 @@ class OpenaiChat(AsyncGeneratorProvider):
34
35
"Accept": "text/event-stream",
35
36
"Authorization": f"Bearer {access_token}",
36
37
}
37
async with StreamSession(
38
proxies=proxies,
39
headers=headers,
40
impersonate="chrome107",
41
timeout=timeout
42
) as session:
43
messages = [
44
{
45
"id": str(uuid.uuid4()),
46
"author": {"role": "user"},
47
"content": {"content_type": "text", "parts": [format_prompt(messages)]},
48
},
49
]
50
data = {
51
"action": "next",
52
"arkose_token": await get_arkose_token(proxy),
53
"messages": messages,
54
"conversation_id": None,
55
"parent_message_id": str(uuid.uuid4()),
56
"model": "text-davinci-002-render-sha",
57
"history_and_training_disabled": True,
58
}
59
async with session.post(f"{cls.url}/backend-api/conversation", json=data) as response:
60
response.raise_for_status()
61
last_message = ""
62
async for line in response.iter_lines():
63
if line.startswith(b"data: "):
64
line = line[6:]
65
if line == b"[DONE]":
66
break
67
try:
68
line = json.loads(line)
69
except:
70
continue
71
if "message" not in line:
72
continue
73
if "error" in line and line["error"]:
74
raise RuntimeError(line["error"])
75
if "message_type" not in line["message"]["metadata"]:
76
continue
77
if line["message"]["metadata"]["message_type"] == "next":
78
new_message = line["message"]["content"]["parts"][0]
79
yield new_message[len(last_message):]
80
last_message = new_message
38
messages = [
39
{
40
"id": str(uuid.uuid4()),
41
"author": {"role": "user"},
42
"content": {"content_type": "text", "parts": [format_prompt(messages)]},
43
},
44
]
45
message_id = str(uuid.uuid4())
46
data = {
47
"action": "next",
48
"arkose_token": await get_arkose_token(proxy),
49
"messages": messages,
50
"conversation_id": None,
51
"parent_message_id": message_id,
52
"model": "text-davinci-002-render-sha",
53
"history_and_training_disabled": not auto_continue,
54
}
55
conversation_id = None
56
while not end_turn:
57
if not auto_continue:
58
end_turn = True
59
async with StreamSession(
60
proxies=proxies,
61
headers=headers,
62
impersonate="chrome107",
63
timeout=timeout
64
) as session:
65
async with session.post(f"{cls.url}/backend-api/conversation", json=data) as response:
66
try:
67
response.raise_for_status()
68
except:
69
raise RuntimeError(f"Response: {await response.text()}")
70
last_message = ""
71
async for line in response.iter_lines():
72
if line.startswith(b"data: "):
73
line = line[6:]
74
if line == b"[DONE]":
75
break
76
try:
77
line = json.loads(line)
78
except:
79
continue
80
if "message" not in line:
81
continue
82
if "error" in line and line["error"]:
83
raise RuntimeError(line["error"])
84
end_turn = line["message"]["end_turn"]
85
message_id = line["message"]["id"]
86
if line["conversation_id"]:
87
conversation_id = line["conversation_id"]
88
if "message_type" not in line["message"]["metadata"]:
89
continue
90
if line["message"]["metadata"]["message_type"] in ("next", "continue"):
91
new_message = line["message"]["content"]["parts"][0]
92
yield new_message[len(last_message):]
93
last_message = new_message
94
if end_turn:
95
return
96
data = {
97
"action": "continue",
98
"arkose_token": await get_arkose_token(proxy),
99
"conversation_id": conversation_id,
100
"parent_message_id": message_id,
101
"model": "text-davinci-002-render-sha",
102
"history_and_training_disabled": False,
103
}
104
await asyncio.sleep(5)
81
105
82
106
@classmethod
83
107
async def browse_access_token(cls) -> str:
@@ -82,7 +82,7 @@ llama2_7b = Model(
82
82
best_provider = RetryProvider([Llama2, DeepInfra]))
83
83
84
84
llama2_13b = Model(
85
name ="meta-llama/Llama-2-13b-chat-hf",
85
name = "meta-llama/Llama-2-13b-chat-hf",
86
86
base_provider = 'huggingface',
87
87
best_provider = RetryProvider([Llama2, DeepInfra]))
88
88
@@ -21,4 +21,4 @@ asgiref
21
21
fastapi
22
22
uvicorn
23
23
flask
24
git+https://github.com/hlohaus/py-arkose-token-generator.git
24
py-arkose-generator