This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
2,632 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
|
||
from ..typing import AsyncGenerator | ||
from ..requests import StreamSession | ||
from .base_provider import AsyncGeneratorProvider, format_prompt | ||
|
||
|
||
class AItianhu(AsyncGeneratorProvider): | ||
url = "https://www.aitianhu.com" | ||
working = True | ||
supports_gpt_35_turbo = True | ||
|
||
@classmethod | ||
async def create_async_generator( | ||
cls, | ||
model: str, | ||
messages: list[dict[str, str]], | ||
proxy: str = None, | ||
**kwargs | ||
) -> AsyncGenerator: | ||
data = { | ||
"prompt": format_prompt(messages), | ||
"options": {}, | ||
"systemMessage": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.", | ||
"temperature": 0.8, | ||
"top_p": 1, | ||
**kwargs | ||
} | ||
headers = { | ||
"Authority": cls.url, | ||
"Accept": "application/json, text/plain, */*", | ||
"Origin": cls.url, | ||
"Referer": f"{cls.url}/" | ||
} | ||
async with StreamSession(headers=headers, 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") | ||
if b"platform's risk control" in line: | ||
raise RuntimeError("Platform's Risk Control") | ||
line = json.loads(line) | ||
if "detail" in line: | ||
content = line["detail"]["choices"][0]["delta"].get("content") | ||
if content: | ||
yield content | ||
else: | ||
raise RuntimeError(f"Response: {line}") | ||
|
||
|
||
@classmethod | ||
@property | ||
def params(cls): | ||
params = [ | ||
("model", "str"), | ||
("messages", "list[dict[str, str]]"), | ||
("stream", "bool"), | ||
("proxy", "str"), | ||
("temperature", "float"), | ||
("top_p", "int"), | ||
] | ||
param = ", ".join([": ".join(p) for p in params]) | ||
return f"g4f.provider.{cls.__name__} supports: ({param})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from __future__ import annotations | ||
|
||
import random, json | ||
|
||
from ..typing import AsyncGenerator | ||
from ..requests import StreamSession | ||
from .base_provider import AsyncGeneratorProvider, format_prompt | ||
|
||
domains = { | ||
"gpt-3.5-turbo": ".aitianhu.space", | ||
"gpt-4": ".aitianhu.website", | ||
} | ||
|
||
class AItianhuSpace(AsyncGeneratorProvider): | ||
url = "https://chat3.aiyunos.top/" | ||
working = True | ||
supports_gpt_35_turbo = True | ||
|
||
@classmethod | ||
async def create_async_generator( | ||
cls, | ||
model: str, | ||
messages: list[dict[str, str]], | ||
stream: bool = True, | ||
**kwargs | ||
) -> AsyncGenerator: | ||
if not model: | ||
model = "gpt-3.5-turbo" | ||
elif not model in domains: | ||
raise ValueError(f"Model are not supported: {model}") | ||
|
||
chars = 'abcdefghijklmnopqrstuvwxyz0123456789' | ||
rand = ''.join(random.choice(chars) for _ in range(6)) | ||
domain = domains[model] | ||
url = f'https://{rand}{domain}' | ||
|
||
async with StreamSession(impersonate="chrome110", verify=False) as session: | ||
data = { | ||
"prompt": format_prompt(messages), | ||
"options": {}, | ||
"systemMessage": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.", | ||
"temperature": 0.8, | ||
"top_p": 1, | ||
**kwargs | ||
} | ||
headers = { | ||
"Authority": url, | ||
"Accept": "application/json, text/plain, */*", | ||
"Origin": url, | ||
"Referer": f"{url}/" | ||
} | ||
async with session.post(f"{url}/api/chat-process", json=data, headers=headers) as response: | ||
response.raise_for_status() | ||
async for line in response.iter_lines(): | ||
if line == b"<script>": | ||
raise RuntimeError("Solve Challenge") | ||
if b"platform's risk control" in line: | ||
raise RuntimeError("Platform's Risk Control") | ||
line = json.loads(line) | ||
if "detail" in line: | ||
content = line["detail"]["choices"][0]["delta"].get("content") | ||
if content: | ||
yield content | ||
elif "message" in line and "AI-4接口非常昂贵" in line["message"]: | ||
raise RuntimeError("Rate limit for GPT 4 reached") | ||
else: | ||
raise RuntimeError(f"Response: {line}") | ||
|
||
|
||
@classmethod | ||
@property | ||
def params(cls): | ||
params = [ | ||
("model", "str"), | ||
("messages", "list[dict[str, str]]"), | ||
("stream", "bool"), | ||
("temperature", "float"), | ||
("top_p", "int"), | ||
] | ||
param = ", ".join([": ".join(p) for p in params]) | ||
return f"g4f.provider.{cls.__name__} supports: ({param})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from aiohttp import ClientSession | ||
|
||
from ..typing import AsyncGenerator | ||
from .base_provider import AsyncGeneratorProvider | ||
|
||
|
||
class Acytoo(AsyncGeneratorProvider): | ||
url = 'https://chat.acytoo.com' | ||
working = True | ||
supports_gpt_35_turbo = True | ||
|
||
@classmethod | ||
async def create_async_generator( | ||
cls, | ||
model: str, | ||
messages: list[dict[str, str]], | ||
proxy: str = None, | ||
**kwargs | ||
) -> AsyncGenerator: | ||
|
||
async with ClientSession( | ||
headers=_create_header() | ||
) as session: | ||
async with session.post( | ||
cls.url + '/api/completions', | ||
proxy=proxy, | ||
json=_create_payload(messages, **kwargs) | ||
) as response: | ||
response.raise_for_status() | ||
async for stream in response.content.iter_any(): | ||
if stream: | ||
yield stream.decode() | ||
|
||
|
||
def _create_header(): | ||
return { | ||
'accept': '*/*', | ||
'content-type': 'application/json', | ||
} | ||
|
||
|
||
def _create_payload(messages: list[dict[str, str]], temperature: float = 0.5, **kwargs): | ||
return { | ||
'key' : '', | ||
'model' : 'gpt-3.5-turbo', | ||
'messages' : messages, | ||
'temperature' : temperature, | ||
'password' : '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
import time | ||
import hashlib | ||
|
||
from ..typing import AsyncGenerator | ||
from ..requests import StreamSession | ||
from .base_provider import AsyncGeneratorProvider | ||
|
||
|
||
class Aibn(AsyncGeneratorProvider): | ||
url = "https://aibn.cc" | ||
supports_gpt_35_turbo = True | ||
working = True | ||
|
||
@classmethod | ||
async def create_async_generator( | ||
cls, | ||
model: str, | ||
messages: list[dict[str, str]], | ||
**kwargs | ||
) -> AsyncGenerator: | ||
async with StreamSession(impersonate="chrome107") as session: | ||
timestamp = int(time.time()) | ||
data = { | ||
"messages": messages, | ||
"pass": None, | ||
"sign": generate_signature(timestamp, messages[-1]["content"]), | ||
"time": timestamp | ||
} | ||
async with session.post(f"{cls.url}/api/generate", json=data) as response: | ||
response.raise_for_status() | ||
async for chunk in response.iter_content(): | ||
yield chunk.decode() | ||
|
||
@classmethod | ||
@property | ||
def params(cls): | ||
params = [ | ||
("model", "str"), | ||
("messages", "list[dict[str, str]]"), | ||
("stream", "bool"), | ||
("temperature", "float"), | ||
] | ||
param = ", ".join([": ".join(p) for p in params]) | ||
return f"g4f.provider.{cls.__name__} supports: ({param})" | ||
|
||
|
||
def generate_signature(timestamp: int, message: str, secret: str = "undefined"): | ||
data = f"{timestamp}:{message}:{secret}" | ||
return hashlib.sha256(data.encode()).hexdigest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
from aiohttp import ClientSession | ||
|
||
from .base_provider import AsyncProvider, format_prompt | ||
|
||
|
||
class Aichat(AsyncProvider): | ||
url = "https://chat-gpt.org/chat" | ||
working = True | ||
supports_gpt_35_turbo = True | ||
|
||
@staticmethod | ||
async def create_async( | ||
model: str, | ||
messages: list[dict[str, str]], | ||
proxy: str = None, | ||
**kwargs | ||
) -> str: | ||
headers = { | ||
"authority": "chat-gpt.org", | ||
"accept": "*/*", | ||
"cache-control": "no-cache", | ||
"content-type": "application/json", | ||
"origin": "https://chat-gpt.org", | ||
"pragma": "no-cache", | ||
"referer": "https://chat-gpt.org/chat", | ||
"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/113.0.0.0 Safari/537.36", | ||
} | ||
async with ClientSession( | ||
headers=headers | ||
) as session: | ||
json_data = { | ||
"message": format_prompt(messages), | ||
"temperature": kwargs.get('temperature', 0.5), | ||
"presence_penalty": 0, | ||
"top_p": kwargs.get('top_p', 1), | ||
"frequency_penalty": 0, | ||
} | ||
async with session.post( | ||
"https://chat-gpt.org/api/text", | ||
proxy=proxy, | ||
json=json_data | ||
) as response: | ||
response.raise_for_status() | ||
result = await response.json() | ||
if not result['response']: | ||
raise Exception(f"Error Response: {result}") | ||
return result["message"] |
Oops, something went wrong.