mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-01-05 02:01:53 +03:00
commit
b2baf46e3c
51
README.md
51
README.md
@ -185,30 +185,33 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth |
|
| Website| Provider| gpt-3.5 | gpt-4 | Streaming | Status | Auth |
|
||||||
| ------ | ------- | ------- | ----- | --------- | ------ | ---- |
|
| ------ | ------- | ------- | ----- | --------- | ------ | ---- |
|
||||||
| [www.aitianhu.com](https://www.aitianhu.com/api/chat-process) | g4f.Provider.AItianhu | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [chat.acytoo.com](https://chat.acytoo.com/) | g4f.provider.Acytoo | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
|
||||||
| [chat.acytoo.com](https://chat.acytoo.com/api/completions) | 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) | ❌ |
|
||||||
| [aiservice.vercel.app](https://aiservice.vercel.app/api/chat/answer) | g4f.Provider.AiService | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [ai.ls](https://ai.ls) | g4f.provider.Ails | ✔️ | ❌ | ✔️ | ![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) | ❌ |
|
| [bard.google.com](https://bard.google.com) | g4f.provider.Bard | ❌ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ✔️ |
|
||||||
| [ai.ls](https://ai.ls) | g4f.Provider.Ails | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.provider.ChatgptAi | ❌ | ✔️ | ❌ | ![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) | ✔️ |
|
| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.ChatgptLogin | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [bing.com](https://bing.com/chat) | g4f.Provider.Bing | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [deepai.org](https://deepai.org) | g4f.provider.DeepAi | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [chatgpt.ai](https://chatgpt.ai/gpt-4/) | g4f.Provider.ChatgptAi | ❌ | ✔️ | ❌ | ![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) | ❌ |
|
||||||
| [chatgptlogin.ac](https://chatgptlogin.ac) | g4f.Provider.ChatgptLogin | ✔️ | ❌ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [next.eqing.tech](https://next.eqing.tech/) | g4f.provider.Equing | ✔️ | ❌ | ✔️ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
|
||||||
| [deepai.org](https://deepai.org) | g4f.Provider.DeepAi | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
| [chat.getgpt.world](https://chat.getgpt.world/) | g4f.provider.GetGpt | ✔️ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [chat.dfehub.com](https://chat.dfehub.com/api/chat) | g4f.Provider.DfeHub | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [gpt-gm.h2o.ai](https://gpt-gm.h2o.ai) | g4f.provider.H2o | ❌ | ❌ | ✔️ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [free.easychat.work](https://free.easychat.work) | g4f.Provider.EasyChat | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [opchatgpts.net](https://opchatgpts.net) | g4f.provider.Opchatgpts | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [forefront.com](https://forefront.com) | g4f.Provider.Forefront | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [raycast.com](https://raycast.com) | g4f.provider.Raycast | ✔️ | ✔️ | ✔️ | ![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) | ❌ |
|
| [theb.ai](https://theb.ai) | g4f.provider.Theb | ✔️ | ❌ | ✔️ | ![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) | ❌ |
|
| [play.vercel.ai](https://play.vercel.ai) | g4f.provider.Vercel | ✔️ | ❌ | ❌ | ![Unknown](https://img.shields.io/badge/Unknown-grey) | ❌ |
|
||||||
| [liaobots.com](https://liaobots.com) | g4f.Provider.Liaobots | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ✔️ |
|
| [wewordle.org](https://wewordle.org/) | g4f.provider.Wewordle | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [supertest.lockchat.app](http://supertest.lockchat.app) | g4f.Provider.Lockchat | ✔️ | ✔️ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
| [you.com](https://you.com) | g4f.provider.You | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
||||||
| [opchatgpts.net](https://opchatgpts.net) | g4f.Provider.Opchatgpts | ✔️ | ❌ | ❌ | ![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) | ❌ |
|
||||||
| [backend.raycast.com](https://backend.raycast.com/api/v1/ai/chat_completions) | g4f.Provider.Raycast | ✔️ | ✔️ | ✔️ | ![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) | ❌ |
|
||||||
| [theb.ai](https://theb.ai) | g4f.Provider.Theb | ✔️ | ❌ | ✔️ | ![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) | ❌ |
|
||||||
| [play.vercel.ai](https://play.vercel.ai) | g4f.Provider.Vercel | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
| [bing.com](https://bing.com/chat) | g4f.provider.Bing | ❌ | ✔️ | ❌ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
||||||
| [wewordle.org](https://wewordle.org/gptapi/v1/android/turbo) | g4f.Provider.Wewordle | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
| [chat.dfehub.com](https://chat.dfehub.com/) | g4f.provider.DfeHub | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
||||||
| [you.com](https://you.com) | g4f.Provider.You | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
| [chat9.fastgpt.me](https://chat9.fastgpt.me/) | g4f.provider.FastGpt | ✔️ | ❌ | ✔️ | ![Inactive](https://img.shields.io/badge/Inactive-red) | ❌ |
|
||||||
| [chat9.yqcloud.top](https://chat9.yqcloud.top/) | g4f.Provider.Yqcloud | ✔️ | ❌ | ❌ | ![Active](https://img.shields.io/badge/Active-brightgreen) | ❌ |
|
| [forefront.com](https://forefront.com) | g4f.provider.Forefront | ✔️ | ❌ | ✔️ | ![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) | ❌ |
|
||||||
|
|
||||||
### Other Models
|
### Other Models
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ from .base_provider import BaseProvider
|
|||||||
|
|
||||||
|
|
||||||
class AItianhu(BaseProvider):
|
class AItianhu(BaseProvider):
|
||||||
url = "https://www.aitianhu.com/api/chat-process"
|
url = "https://www.aitianhu.com/"
|
||||||
working = False
|
working = False
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
|
|
||||||
|
@ -7,12 +7,13 @@ from .base_provider import BaseProvider
|
|||||||
|
|
||||||
|
|
||||||
class Acytoo(BaseProvider):
|
class Acytoo(BaseProvider):
|
||||||
url = "https://chat.acytoo.com/api/completions"
|
url = "https://chat.acytoo.com/"
|
||||||
working = True
|
working = True
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def create_completion(
|
def create_completion(
|
||||||
|
cls,
|
||||||
model: str,
|
model: str,
|
||||||
messages: list[dict[str, str]],
|
messages: list[dict[str, str]],
|
||||||
stream: bool,
|
stream: bool,
|
||||||
@ -21,8 +22,7 @@ class Acytoo(BaseProvider):
|
|||||||
headers = _create_header()
|
headers = _create_header()
|
||||||
payload = _create_payload(messages, kwargs.get('temperature', 0.5))
|
payload = _create_payload(messages, kwargs.get('temperature', 0.5))
|
||||||
|
|
||||||
url = "https://chat.acytoo.com/api/completions"
|
response = requests.post("{cls.url}api/completions", headers=headers, json=payload)
|
||||||
response = requests.post(url=url, headers=headers, json=payload)
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
response.encoding = "utf-8"
|
response.encoding = "utf-8"
|
||||||
yield response.text
|
yield response.text
|
||||||
|
@ -5,7 +5,7 @@ from .base_provider import BaseProvider
|
|||||||
|
|
||||||
|
|
||||||
class AiService(BaseProvider):
|
class AiService(BaseProvider):
|
||||||
url = "https://aiservice.vercel.app/api/chat/answer"
|
url = "https://aiservice.vercel.app/"
|
||||||
working = False
|
working = False
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from .base_provider import BaseProvider
|
|||||||
|
|
||||||
|
|
||||||
class DfeHub(BaseProvider):
|
class DfeHub(BaseProvider):
|
||||||
url = "https://chat.dfehub.com/api/chat"
|
url = "https://chat.dfehub.com/"
|
||||||
supports_stream = True
|
supports_stream = True
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ class DfeHub(BaseProvider):
|
|||||||
"https://chat.dfehub.com/api/openai/v1/chat/completions",
|
"https://chat.dfehub.com/api/openai/v1/chat/completions",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=json_data,
|
json=json_data,
|
||||||
|
timeout=3
|
||||||
)
|
)
|
||||||
|
|
||||||
for chunk in response.iter_lines():
|
for chunk in response.iter_lines():
|
||||||
|
@ -6,7 +6,7 @@ from ..typing import Any, CreateResult
|
|||||||
|
|
||||||
class FastGpt(ABC):
|
class FastGpt(ABC):
|
||||||
url: str = 'https://chat9.fastgpt.me/'
|
url: str = 'https://chat9.fastgpt.me/'
|
||||||
working = True
|
working = False
|
||||||
needs_auth = False
|
needs_auth = False
|
||||||
supports_stream = True
|
supports_stream = True
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
|
@ -11,6 +11,7 @@ class H2o(BaseProvider):
|
|||||||
url = "https://gpt-gm.h2o.ai"
|
url = "https://gpt-gm.h2o.ai"
|
||||||
working = True
|
working = True
|
||||||
supports_stream = True
|
supports_stream = True
|
||||||
|
model = "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-40b-v1"
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_completion(
|
def create_completion(
|
||||||
@ -47,8 +48,9 @@ class H2o(BaseProvider):
|
|||||||
"https://gpt-gm.h2o.ai/conversation",
|
"https://gpt-gm.h2o.ai/conversation",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=data,
|
json=data,
|
||||||
)
|
).json()
|
||||||
conversation_id = response.json()["conversationId"]
|
if "conversationId" not in response:
|
||||||
|
return
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"inputs": conversation,
|
"inputs": conversation,
|
||||||
@ -71,7 +73,7 @@ class H2o(BaseProvider):
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = session.post(
|
response = session.post(
|
||||||
f"https://gpt-gm.h2o.ai/conversation/{conversation_id}",
|
f"https://gpt-gm.h2o.ai/conversation/{response['conversationId']}",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
json=data,
|
json=data,
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,7 @@ class V50(BaseProvider):
|
|||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
supports_stream = False
|
supports_stream = False
|
||||||
needs_auth = False
|
needs_auth = False
|
||||||
working = True
|
working = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_completion(
|
def create_completion(
|
||||||
@ -46,7 +46,8 @@ class V50(BaseProvider):
|
|||||||
}
|
}
|
||||||
response = requests.post("https://p5.v50.ltd/api/chat-process",
|
response = requests.post("https://p5.v50.ltd/api/chat-process",
|
||||||
json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
|
json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
|
||||||
yield response.text
|
if "https://fk1.v50.ltd" not in response.text:
|
||||||
|
yield response.text
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@property
|
@property
|
||||||
|
@ -10,22 +10,18 @@ from .base_provider import BaseProvider
|
|||||||
|
|
||||||
|
|
||||||
class Wewordle(BaseProvider):
|
class Wewordle(BaseProvider):
|
||||||
url = "https://wewordle.org/gptapi/v1/android/turbo"
|
url = "https://wewordle.org/"
|
||||||
working = True
|
working = True
|
||||||
supports_gpt_35_turbo = True
|
supports_gpt_35_turbo = True
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def create_completion(
|
def create_completion(
|
||||||
|
cls,
|
||||||
model: str,
|
model: str,
|
||||||
messages: list[dict[str, str]],
|
messages: list[dict[str, str]],
|
||||||
stream: bool,
|
stream: bool,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> CreateResult:
|
) -> CreateResult:
|
||||||
base = ""
|
|
||||||
|
|
||||||
for message in messages:
|
|
||||||
base += "%s: %s\n" % (message["role"], message["content"])
|
|
||||||
base += "assistant:"
|
|
||||||
# randomize user id and app id
|
# randomize user id and app id
|
||||||
_user_id = "".join(
|
_user_id = "".join(
|
||||||
random.choices(f"{string.ascii_lowercase}{string.digits}", k=16)
|
random.choices(f"{string.ascii_lowercase}{string.digits}", k=16)
|
||||||
@ -45,7 +41,7 @@ class Wewordle(BaseProvider):
|
|||||||
}
|
}
|
||||||
data: dict[str, Any] = {
|
data: dict[str, Any] = {
|
||||||
"user": _user_id,
|
"user": _user_id,
|
||||||
"messages": [{"role": "user", "content": base}],
|
"messages": messages,
|
||||||
"subscriber": {
|
"subscriber": {
|
||||||
"originalPurchaseDate": None,
|
"originalPurchaseDate": None,
|
||||||
"originalApplicationVersion": None,
|
"originalApplicationVersion": None,
|
||||||
@ -67,8 +63,7 @@ class Wewordle(BaseProvider):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
url = "https://wewordle.org/gptapi/v1/android/turbo"
|
response = requests.post(f"{cls.url}gptapi/v1/android/turbo", headers=headers, data=json.dumps(data))
|
||||||
response = requests.post(url, headers=headers, data=json.dumps(data))
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
_json = response.json()
|
_json = response.json()
|
||||||
if "message" in _json:
|
if "message" in _json:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import json
|
||||||
|
|
||||||
from curl_cffi import requests
|
from curl_cffi import requests
|
||||||
|
|
||||||
@ -28,8 +29,12 @@ class You(BaseProvider):
|
|||||||
impersonate="chrome107",
|
impersonate="chrome107",
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
yield _parse_output(response.text).encode().decode("unicode_escape")
|
|
||||||
|
start = 'data: {"youChatToken": '
|
||||||
|
for line in response.content.splitlines():
|
||||||
|
line = line.decode('utf-8')
|
||||||
|
if line.startswith(start):
|
||||||
|
yield json.loads(line[len(start): -1])
|
||||||
|
|
||||||
def _create_url_param(messages: list[dict[str, str]], history: list[dict[str, str]]):
|
def _create_url_param(messages: list[dict[str, str]], history: list[dict[str, str]]):
|
||||||
prompt = ""
|
prompt = ""
|
||||||
@ -53,10 +58,4 @@ def _create_header():
|
|||||||
return {
|
return {
|
||||||
"accept": "text/event-stream",
|
"accept": "text/event-stream",
|
||||||
"referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
|
"referer": "https://you.com/search?fromSearchBar=true&tbm=youchat",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _parse_output(output: str) -> str:
|
|
||||||
regex = r"^data:\s{\"youChatToken\": \"(.*)\"}$"
|
|
||||||
tokens = [token for token in re.findall(regex, output, re.MULTILINE)]
|
|
||||||
return "".join(tokens)
|
|
@ -1,67 +1,76 @@
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from colorama import Fore
|
||||||
|
|
||||||
sys.path.append(str(Path(__file__).parent.parent))
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
|
|
||||||
from g4f import BaseProvider, models, provider
|
from g4f import BaseProvider, models, Provider
|
||||||
|
|
||||||
|
logging = False
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
providers = get_providers()
|
providers = get_providers()
|
||||||
results: list[list[str | bool]] = []
|
failed_providers = []
|
||||||
|
|
||||||
for _provider in providers:
|
for _provider in providers:
|
||||||
print("start", _provider.__name__)
|
if _provider.needs_auth:
|
||||||
actual_working = judge(_provider)
|
continue
|
||||||
expected_working = _provider.working
|
print("Provider:", _provider.__name__)
|
||||||
match = actual_working == expected_working
|
result = test(_provider)
|
||||||
|
print("Result:", result)
|
||||||
|
if _provider.working and not result:
|
||||||
|
failed_providers.append(_provider)
|
||||||
|
|
||||||
results.append([_provider.__name__, expected_working, actual_working, match])
|
print()
|
||||||
|
|
||||||
print("failed provider list")
|
if failed_providers:
|
||||||
for result in results:
|
print(f"{Fore.RED}Failed providers:\n")
|
||||||
if not result[3]:
|
for _provider in failed_providers:
|
||||||
print(result)
|
print(f"{Fore.RED}{_provider.__name__}")
|
||||||
|
else:
|
||||||
|
print(f"{Fore.GREEN}All providers are working")
|
||||||
|
|
||||||
|
|
||||||
def get_providers() -> list[type[BaseProvider]]:
|
def get_providers() -> list[type[BaseProvider]]:
|
||||||
provider_names = dir(provider)
|
provider_names = dir(Provider)
|
||||||
ignore_names = [
|
ignore_names = [
|
||||||
"base_provider",
|
"base_provider",
|
||||||
"BaseProvider",
|
"BaseProvider"
|
||||||
]
|
]
|
||||||
provider_names = [
|
provider_names = [
|
||||||
provider_name
|
provider_name
|
||||||
for provider_name in provider_names
|
for provider_name in provider_names
|
||||||
if not provider_name.startswith("__") and provider_name not in ignore_names
|
if not provider_name.startswith("__") and provider_name not in ignore_names
|
||||||
]
|
]
|
||||||
return [getattr(provider, provider_name) for provider_name in provider_names]
|
return [getattr(Provider, provider_name) for provider_name in sorted(provider_names)]
|
||||||
|
|
||||||
|
|
||||||
def create_response(_provider: type[BaseProvider]) -> str:
|
def create_response(_provider: type[BaseProvider]) -> str:
|
||||||
model = (
|
if _provider.supports_gpt_35_turbo:
|
||||||
models.gpt_35_turbo.name
|
model = models.gpt_35_turbo.name
|
||||||
if _provider is not provider.H2o
|
elif _provider.supports_gpt_4:
|
||||||
else models.falcon_7b.name
|
model = models.gpt_4
|
||||||
)
|
elif hasattr(_provider, "model"):
|
||||||
|
model = _provider.model
|
||||||
|
else:
|
||||||
|
model = None
|
||||||
response = _provider.create_completion(
|
response = _provider.create_completion(
|
||||||
model=model,
|
model=model,
|
||||||
messages=[{"role": "user", "content": "Hello world!, plz yourself"}],
|
messages=[{"role": "user", "content": "Hello"}],
|
||||||
stream=False,
|
stream=False,
|
||||||
)
|
)
|
||||||
return "".join(response)
|
return "".join(response)
|
||||||
|
|
||||||
|
|
||||||
def judge(_provider: type[BaseProvider]) -> bool:
|
def test(_provider: type[BaseProvider]) -> bool:
|
||||||
if _provider.needs_auth:
|
|
||||||
return _provider.working
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = create_response(_provider)
|
response = create_response(_provider)
|
||||||
assert type(response) is str
|
assert type(response) is str
|
||||||
return len(response) > 1
|
assert len(response) > 0
|
||||||
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
if logging:
|
||||||
|
print(e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ sys.path.append(str(Path(__file__).parent.parent))
|
|||||||
|
|
||||||
from g4f import models, Provider
|
from g4f import models, Provider
|
||||||
from g4f.Provider.base_provider import BaseProvider
|
from g4f.Provider.base_provider import BaseProvider
|
||||||
|
from testing.test_providers import test
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print_providers()
|
print_providers()
|
||||||
@ -21,25 +21,30 @@ def print_providers():
|
|||||||
"| ------ | ------- | ------- | ----- | --------- | ------ | ---- |",
|
"| ------ | ------- | ------- | ----- | --------- | ------ | ---- |",
|
||||||
]
|
]
|
||||||
providers = get_providers()
|
providers = get_providers()
|
||||||
for _provider in providers:
|
for is_working in (True, False):
|
||||||
netloc = urlparse(_provider.url).netloc
|
for _provider in providers:
|
||||||
website = f"[{netloc}]({_provider.url})"
|
if is_working != _provider.working:
|
||||||
|
continue
|
||||||
|
netloc = urlparse(_provider.url).netloc
|
||||||
|
website = f"[{netloc}]({_provider.url})"
|
||||||
|
|
||||||
provider_name = f"g4f.provider.{_provider.__name__}"
|
provider_name = f"g4f.provider.{_provider.__name__}"
|
||||||
|
|
||||||
has_gpt_35 = "✔️" if _provider.supports_gpt_35_turbo else "❌"
|
has_gpt_35 = "✔️" if _provider.supports_gpt_35_turbo else "❌"
|
||||||
has_gpt_4 = "✔️" if _provider.supports_gpt_4 else "❌"
|
has_gpt_4 = "✔️" if _provider.supports_gpt_4 else "❌"
|
||||||
stream = "✔️" if _provider.supports_stream else "❌"
|
stream = "✔️" if _provider.supports_stream else "❌"
|
||||||
status = (
|
if _provider.working:
|
||||||
"![Active](https://img.shields.io/badge/Active-brightgreen)"
|
if test(_provider):
|
||||||
if _provider.working
|
status = '![Active](https://img.shields.io/badge/Active-brightgreen)'
|
||||||
else "![Inactive](https://img.shields.io/badge/Inactive-red)"
|
else:
|
||||||
)
|
status = '![Unknown](https://img.shields.io/badge/Unknown-grey)'
|
||||||
auth = "✔️" if _provider.needs_auth else "❌"
|
else:
|
||||||
|
status = '![Inactive](https://img.shields.io/badge/Inactive-red)'
|
||||||
|
auth = "✔️" if _provider.needs_auth else "❌"
|
||||||
|
|
||||||
lines.append(
|
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} | {status} | {auth} |"
|
||||||
)
|
)
|
||||||
print("\n".join(lines))
|
print("\n".join(lines))
|
||||||
|
|
||||||
|
|
||||||
@ -79,6 +84,8 @@ def print_models():
|
|||||||
|
|
||||||
_models = get_models()
|
_models = get_models()
|
||||||
for model in _models:
|
for model in _models:
|
||||||
|
if model.best_provider.__name__ not in provider_urls:
|
||||||
|
continue
|
||||||
split_name = re.split(r":|/", model.name)
|
split_name = re.split(r":|/", model.name)
|
||||||
name = split_name[-1]
|
name = split_name[-1]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user