summaryrefslogtreecommitdiffstats
path: root/g4f/Provider
diff options
context:
space:
mode:
authorabc <98614666+xtekky@users.noreply.github.com>2023-10-16 01:47:10 +0200
committerabc <98614666+xtekky@users.noreply.github.com>2023-10-16 01:47:10 +0200
commit4a3b663ccd44735d77c372b5f629a728f0b90591 (patch)
treef76dba66613f4e074862d57621ea888cd3e741f7 /g4f/Provider
parent~ | new `test_providers.py` (diff)
downloadgpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.tar
gpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.tar.gz
gpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.tar.bz2
gpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.tar.lz
gpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.tar.xz
gpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.tar.zst
gpt4free-4a3b663ccd44735d77c372b5f629a728f0b90591.zip
Diffstat (limited to 'g4f/Provider')
-rw-r--r--g4f/Provider/AItianhu.py51
-rw-r--r--g4f/Provider/AItianhuSpace.py2
-rw-r--r--g4f/Provider/Acytoo.py2
-rw-r--r--g4f/Provider/Aibn.py2
-rw-r--r--g4f/Provider/Ails.py2
-rw-r--r--g4f/Provider/ChatgptDuo.py2
-rw-r--r--g4f/Provider/ChatgptFree.py11
-rw-r--r--g4f/Provider/Cromicle.py2
-rw-r--r--g4f/Provider/GptChatly.py15
-rw-r--r--g4f/Provider/Myshell.py48
-rw-r--r--g4f/Provider/Ylokh.py2
11 files changed, 107 insertions, 32 deletions
diff --git a/g4f/Provider/AItianhu.py b/g4f/Provider/AItianhu.py
index 56d9a9ab..0105c89a 100644
--- a/g4f/Provider/AItianhu.py
+++ b/g4f/Provider/AItianhu.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import json
+import browser_cookie3
from ..typing import AsyncResult, Messages
from ..requests import StreamSession
@@ -9,7 +10,7 @@ from .base_provider import AsyncGeneratorProvider, format_prompt, get_cookies
class AItianhu(AsyncGeneratorProvider):
url = "https://www.aitianhu.com"
- working = True
+ working = False
supports_gpt_35_turbo = True
@classmethod
@@ -19,11 +20,13 @@ class AItianhu(AsyncGeneratorProvider):
messages: Messages,
proxy: str = None,
cookies: dict = None,
- timeout: int = 120,
- **kwargs
- ) -> AsyncResult:
+ timeout: int = 120, **kwargs) -> AsyncResult:
+
if not cookies:
- cookies = get_cookies("www.aitianhu.com")
+ cookies = browser_cookie3.chrome(domain_name='www.aitianhu.com')
+ if not cookies:
+ raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies")
+
data = {
"prompt": format_prompt(messages),
"options": {},
@@ -32,28 +35,42 @@ class AItianhu(AsyncGeneratorProvider):
"top_p": 1,
**kwargs
}
+
headers = {
- "Authority": cls.url,
- "Accept": "application/json, text/plain, */*",
- "Origin": cls.url,
- "Referer": f"{cls.url}/"
+ 'authority': 'www.aitianhu.com',
+ 'accept': 'application/json, text/plain, */*',
+ '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',
+ 'content-type': 'application/json',
+ 'origin': 'https://www.aitianhu.com',
+ 'referer': 'https://www.aitianhu.com/',
+ 'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
+ 'sec-ch-ua-mobile': '?0',
+ 'sec-ch-ua-platform': '"macOS"',
+ 'sec-fetch-dest': 'empty',
+ 'sec-fetch-mode': 'cors',
+ 'sec-fetch-site': 'same-origin',
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
}
- async with StreamSession(
- headers=headers,
- cookies=cookies,
- timeout=timeout,
- proxies={"https": proxy},
- impersonate="chrome107",
- verify=False
- ) as session:
+
+ async with StreamSession(headers=headers,
+ cookies=cookies,
+ timeout=timeout,
+ proxies={"https": proxy},
+ impersonate="chrome107", verify=False) as session:
+
async with session.post(f"{cls.url}/api/chat-process", json=data) as response:
response.raise_for_status()
+
async for line in response.iter_lines():
if line == b"<script>":
raise RuntimeError("Solve challenge and pass cookies")
+
if b"platform's risk control" in line:
raise RuntimeError("Platform's Risk Control")
+
+ print(line)
line = json.loads(line)
+
if "detail" in line:
content = line["detail"]["choices"][0]["delta"].get("content")
if content:
diff --git a/g4f/Provider/AItianhuSpace.py b/g4f/Provider/AItianhuSpace.py
index 7eb93d48..7811c9c8 100644
--- a/g4f/Provider/AItianhuSpace.py
+++ b/g4f/Provider/AItianhuSpace.py
@@ -37,6 +37,8 @@ class AItianhuSpace(AsyncGeneratorProvider):
domain = f"{rand}.{domains[model]}"
if not cookies:
cookies = get_cookies(domain)
+ if not cookies:
+ raise RuntimeError(f"g4f.provider.{cls.__name__} requires cookies")
url = f'https://{domain}'
async with StreamSession(
diff --git a/g4f/Provider/Acytoo.py b/g4f/Provider/Acytoo.py
index cefdd1ac..830d59bc 100644
--- a/g4f/Provider/Acytoo.py
+++ b/g4f/Provider/Acytoo.py
@@ -8,7 +8,7 @@ from .base_provider import AsyncGeneratorProvider
class Acytoo(AsyncGeneratorProvider):
url = 'https://chat.acytoo.com'
- working = True
+ working = False
supports_gpt_35_turbo = True
@classmethod
diff --git a/g4f/Provider/Aibn.py b/g4f/Provider/Aibn.py
index 13f5c71e..14935888 100644
--- a/g4f/Provider/Aibn.py
+++ b/g4f/Provider/Aibn.py
@@ -11,7 +11,7 @@ from .base_provider import AsyncGeneratorProvider
class Aibn(AsyncGeneratorProvider):
url = "https://aibn.cc"
supports_gpt_35_turbo = True
- working = True
+ working = False
@classmethod
async def create_async_generator(
diff --git a/g4f/Provider/Ails.py b/g4f/Provider/Ails.py
index c1384faa..4d072646 100644
--- a/g4f/Provider/Ails.py
+++ b/g4f/Provider/Ails.py
@@ -13,7 +13,7 @@ from .base_provider import AsyncGeneratorProvider
class Ails(AsyncGeneratorProvider):
url: str = "https://ai.ls"
- working = True
+ working = False
supports_gpt_35_turbo = True
@staticmethod
diff --git a/g4f/Provider/ChatgptDuo.py b/g4f/Provider/ChatgptDuo.py
index 039efc84..fef3f856 100644
--- a/g4f/Provider/ChatgptDuo.py
+++ b/g4f/Provider/ChatgptDuo.py
@@ -8,7 +8,7 @@ from .base_provider import AsyncProvider, format_prompt
class ChatgptDuo(AsyncProvider):
url = "https://chatgptduo.com"
supports_gpt_35_turbo = True
- working = True
+ working = False
@classmethod
async def create_async(
diff --git a/g4f/Provider/ChatgptFree.py b/g4f/Provider/ChatgptFree.py
index 7dee1e64..ecba2878 100644
--- a/g4f/Provider/ChatgptFree.py
+++ b/g4f/Provider/ChatgptFree.py
@@ -1,3 +1,5 @@
+#cloudflare block
+
from __future__ import annotations
import re
@@ -5,13 +7,13 @@ from aiohttp import ClientSession
from ..typing import Messages
from .base_provider import AsyncProvider
-from .helper import format_prompt
+from .helper import format_prompt, get_cookies
class ChatgptFree(AsyncProvider):
url = "https://chatgptfree.ai"
supports_gpt_35_turbo = True
- working = True
+ working = False
_post_id = None
_nonce = None
@@ -23,6 +25,8 @@ class ChatgptFree(AsyncProvider):
proxy: str = None,
**kwargs
) -> str:
+ cookies = get_cookies('chatgptfree.ai')
+
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0",
"Accept": "*/*",
@@ -41,7 +45,8 @@ class ChatgptFree(AsyncProvider):
}
async with ClientSession(headers=headers) as session:
if not cls._nonce:
- async with session.get(f"{cls.url}/", proxy=proxy) as response:
+ async with session.get(f"{cls.url}/",
+ proxy=proxy, cookies=cookies) as response:
response.raise_for_status()
response = await response.text()
result = re.search(r'data-post-id="([0-9]+)"', response)
diff --git a/g4f/Provider/Cromicle.py b/g4f/Provider/Cromicle.py
index 93ef8035..8deb79c1 100644
--- a/g4f/Provider/Cromicle.py
+++ b/g4f/Provider/Cromicle.py
@@ -10,7 +10,7 @@ from .helper import format_prompt
class Cromicle(AsyncGeneratorProvider):
url: str = 'https://cromicle.top'
- working: bool = True
+ working: bool = False
supports_gpt_35_turbo: bool = True
@classmethod
diff --git a/g4f/Provider/GptChatly.py b/g4f/Provider/GptChatly.py
index 1d9b76cf..80fe6349 100644
--- a/g4f/Provider/GptChatly.py
+++ b/g4f/Provider/GptChatly.py
@@ -1,29 +1,36 @@
+# cloudflare block
+
from __future__ import annotations
from aiohttp import ClientSession
from ..typing import Messages
from .base_provider import AsyncProvider
+from .helper import get_cookies
class GptChatly(AsyncProvider):
url = "https://gptchatly.com"
supports_gpt_35_turbo = True
supports_gpt_4 = True
- working = True
+ working = False
@classmethod
async def create_async(
cls,
model: str,
messages: Messages,
- proxy: str = None,
- **kwargs
- ) -> str:
+ proxy: str = None, cookies: dict = None, **kwargs) -> str:
+
+ if not cookies:
+ cookies = get_cookies('gptchatly.com')
+
+
if model.startswith("gpt-4"):
chat_url = f"{cls.url}/fetch-gpt4-response"
else:
chat_url = f"{cls.url}/fetch-response"
+
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/118.0",
"Accept": "*/*",
diff --git a/g4f/Provider/Myshell.py b/g4f/Provider/Myshell.py
index 847bac2f..096545f9 100644
--- a/g4f/Provider/Myshell.py
+++ b/g4f/Provider/Myshell.py
@@ -1,3 +1,5 @@
+# not using WS anymore
+
from __future__ import annotations
import json, uuid, hashlib, time, random
@@ -19,7 +21,7 @@ models = {
class Myshell(AsyncGeneratorProvider):
url = "https://app.myshell.ai/chat"
- working = True
+ working = False
supports_gpt_35_turbo = True
supports_gpt_4 = True
@@ -172,4 +174,46 @@ def generate_visitor_id(user_agent: str) -> str:
r = hex(int(random.random() * (16**16)))[2:-2]
d = xor_hash(user_agent)
e = hex(1080 * 1920)[2:]
- return f"{f}-{r}-{d}-{e}-{f}" \ No newline at end of file
+ return f"{f}-{r}-{d}-{e}-{f}"
+
+
+
+# update
+# from g4f.requests import StreamSession
+
+# async def main():
+# headers = {
+# 'authority': 'api.myshell.ai',
+# 'accept': 'application/json',
+# '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',
+# 'content-type': 'application/json',
+# 'myshell-service-name': 'organics-api',
+# 'origin': 'https://app.myshell.ai',
+# 'referer': 'https://app.myshell.ai/',
+# 'sec-ch-ua': '"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
+# 'sec-ch-ua-mobile': '?0',
+# 'sec-ch-ua-platform': '"macOS"',
+# 'sec-fetch-dest': 'empty',
+# 'sec-fetch-mode': 'cors',
+# 'sec-fetch-site': 'same-site',
+# 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
+# 'visitor-id': '18ae8fe5d916d3-0213f29594b17f-18525634-157188-18ae8fe5d916d3',
+# }
+
+# json_data = {
+# 'conversation_scenario': 3,
+# 'botId': '4738',
+# 'message': 'hi',
+# 'messageType': 1,
+# }
+
+# async with StreamSession(headers=headers, impersonate="chrome110") as session:
+# async with session.post(f'https://api.myshell.ai/v1/bot/chat/send_message',
+# json=json_data) as response:
+
+# response.raise_for_status()
+# async for chunk in response.iter_content():
+# print(chunk.decode("utf-8"))
+
+# import asyncio
+# asyncio.run(main()) \ No newline at end of file
diff --git a/g4f/Provider/Ylokh.py b/g4f/Provider/Ylokh.py
index 59da0fa4..b13f846e 100644
--- a/g4f/Provider/Ylokh.py
+++ b/g4f/Provider/Ylokh.py
@@ -8,7 +8,7 @@ from ..typing import AsyncResult, Messages
class Ylokh(AsyncGeneratorProvider):
url = "https://chat.ylokh.xyz"
- working = True
+ working = False
supports_gpt_35_turbo = True