diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-07 19:45:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-07 19:45:04 +0200 |
commit | 7ca1a59d95b52f94f674e8f981eab910b2f03518 (patch) | |
tree | ca506c3c152f3906a5b727a4cc6ebba1fd59d335 /g4f/Provider/Wewordle.py | |
parent | ~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff) | |
parent | Fix imports in Bing (diff) | |
download | gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.gz gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.bz2 gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.lz gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.xz gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.tar.zst gpt4free-7ca1a59d95b52f94f674e8f981eab910b2f03518.zip |
Diffstat (limited to '')
-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 |