gpt4free/g4f/Provider/Wewordle.py

65 lines
2.4 KiB
Python
Raw Normal View History

from __future__ import annotations
2023-07-28 10:07:17 +00:00
import random, string, time
from aiohttp import ClientSession
from .base_provider import AsyncProvider
2023-07-28 10:07:17 +00:00
class Wewordle(AsyncProvider):
url = "https://wewordle.org"
2023-08-27 15:37:44 +00:00
working = True
supports_gpt_35_turbo = True
2023-07-28 10:07:17 +00:00
2023-08-24 19:32:22 +00:00
@classmethod
async def create_async(
2023-08-24 19:32:22 +00:00
cls,
2023-07-28 10:07:17 +00:00
model: str,
messages: list[dict[str, str]],
proxy: str = None,
**kwargs
) -> str:
2023-08-27 15:37:44 +00:00
2023-07-28 10:07:17 +00:00
headers = {
2023-08-27 15:37:44 +00:00
"accept" : "*/*",
"pragma" : "no-cache",
"Content-Type" : "application/json",
"Connection" : "keep-alive"
2023-07-28 10:07:17 +00:00
}
_user_id = "".join(random.choices(f"{string.ascii_lowercase}{string.digits}", k=16))
_app_id = "".join(random.choices(f"{string.ascii_lowercase}{string.digits}", k=31))
_request_date = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())
data = {
2023-08-27 15:37:44 +00:00
"user" : _user_id,
"messages" : messages,
2023-07-28 10:07:17 +00:00
"subscriber": {
2023-08-27 15:37:44 +00:00
"originalPurchaseDate" : None,
"originalApplicationVersion" : None,
"allPurchaseDatesMillis" : {},
"entitlements" : {"active": {}, "all": {}},
"allPurchaseDates" : {},
"allExpirationDatesMillis" : {},
"allExpirationDates" : {},
"originalAppUserId" : f"$RCAnonymousID:{_app_id}",
"latestExpirationDate" : None,
"requestDate" : _request_date,
"latestExpirationDateMillis" : None,
"nonSubscriptionTransactions" : [],
"originalPurchaseDateMillis" : None,
"managementURL" : None,
2023-07-28 10:07:17 +00:00
"allPurchasedProductIdentifiers": [],
2023-08-27 15:37:44 +00:00
"firstSeen" : _request_date,
"activeSubscriptions" : [],
}
2023-07-28 10:07:17 +00:00
}
async with ClientSession(
headers=headers
) as session:
async with session.post(f"{cls.url}/gptapi/v1/android/turbo", proxy=proxy, json=data) as response:
response.raise_for_status()
content = (await response.json())["message"]["content"]
if content:
return content