Skip to content

Commit

Permalink
~ | remove non-working providers
Browse files Browse the repository at this point in the history
  • Loading branch information
xtekky committed Oct 15, 2023
1 parent 46398e8 commit 4a3b663
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 32 deletions.
51 changes: 34 additions & 17 deletions g4f/Provider/AItianhu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import browser_cookie3

from ..typing import AsyncResult, Messages
from ..requests import StreamSession
Expand All @@ -9,7 +10,7 @@

class AItianhu(AsyncGeneratorProvider):
url = "https://www.aitianhu.com"
working = True
working = False
supports_gpt_35_turbo = True

@classmethod
Expand All @@ -19,11 +20,13 @@ async def create_async_generator(
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": {},
Expand All @@ -32,28 +35,42 @@ async def create_async_generator(
"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:
Expand Down
2 changes: 2 additions & 0 deletions g4f/Provider/AItianhuSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ async def create_async_generator(
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(
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/Acytoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Acytoo(AsyncGeneratorProvider):
url = 'https://chat.acytoo.com'
working = True
working = False
supports_gpt_35_turbo = True

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/Aibn.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Aibn(AsyncGeneratorProvider):
url = "https://aibn.cc"
supports_gpt_35_turbo = True
working = True
working = False

@classmethod
async def create_async_generator(
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/Ails.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Ails(AsyncGeneratorProvider):
url: str = "https://ai.ls"
working = True
working = False
supports_gpt_35_turbo = True

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/ChatgptDuo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ChatgptDuo(AsyncProvider):
url = "https://chatgptduo.com"
supports_gpt_35_turbo = True
working = True
working = False

@classmethod
async def create_async(
Expand Down
11 changes: 8 additions & 3 deletions g4f/Provider/ChatgptFree.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#cloudflare block

from __future__ import annotations

import re
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

Expand All @@ -23,6 +25,8 @@ async def create_async(
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": "*/*",
Expand All @@ -41,7 +45,8 @@ async def create_async(
}
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)
Expand Down
2 changes: 1 addition & 1 deletion g4f/Provider/Cromicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Cromicle(AsyncGeneratorProvider):
url: str = 'https://cromicle.top'
working: bool = True
working: bool = False
supports_gpt_35_turbo: bool = True

@classmethod
Expand Down
15 changes: 11 additions & 4 deletions g4f/Provider/GptChatly.py
Original file line number Diff line number Diff line change
@@ -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": "*/*",
Expand Down
48 changes: 46 additions & 2 deletions g4f/Provider/Myshell.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# not using WS anymore

from __future__ import annotations

import json, uuid, hashlib, time, random
Expand All @@ -19,7 +21,7 @@

class Myshell(AsyncGeneratorProvider):
url = "https://app.myshell.ai/chat"
working = True
working = False
supports_gpt_35_turbo = True
supports_gpt_4 = True

Expand Down Expand Up @@ -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}"
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())
2 changes: 1 addition & 1 deletion g4f/Provider/Ylokh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Ylokh(AsyncGeneratorProvider):
url = "https://chat.ylokh.xyz"
working = True
working = False
supports_gpt_35_turbo = True


Expand Down

0 comments on commit 4a3b663

Please sign in to comment.