diff options
Diffstat (limited to 'g4f/Provider/Wewordle.py')
-rw-r--r-- | g4f/Provider/Wewordle.py | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/g4f/Provider/Wewordle.py b/g4f/Provider/Wewordle.py index 99c81a84..a7bdc722 100644 --- a/g4f/Provider/Wewordle.py +++ b/g4f/Provider/Wewordle.py @@ -1,47 +1,36 @@ from __future__ import annotations -import json -import random -import string -import time +import random, string, time +from aiohttp import ClientSession -import requests +from .base_provider import AsyncProvider -from ..typing import Any, CreateResult -from .base_provider import BaseProvider - -class Wewordle(BaseProvider): - url = "https://wewordle.org/" +class Wewordle(AsyncProvider): + url = "https://wewordle.org" working = True supports_gpt_35_turbo = True @classmethod - def create_completion( + async def create_async( cls, model: str, messages: list[dict[str, str]], - stream: bool, **kwargs: Any) -> CreateResult: - - # randomize user id and app id - _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)) + proxy: str = None, + **kwargs + ) -> str: - # make current date with format utc - _request_date = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime()) headers = { "accept" : "*/*", "pragma" : "no-cache", "Content-Type" : "application/json", "Connection" : "keep-alive" - # user agent android client - # 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 10; SM-G975F Build/QP1A.190711.020)', } - - data: dict[str, Any] = { + + _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 = { "user" : _user_id, "messages" : messages, "subscriber": { @@ -65,10 +54,12 @@ class Wewordle(BaseProvider): } } - response = requests.post(f"{cls.url}gptapi/v1/android/turbo", - headers=headers, data=json.dumps(data)) - - response.raise_for_status() - _json = response.json() - if "message" in _json: - yield _json["message"]["content"] + + 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
\ No newline at end of file |