summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Wewordle.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner.lohaus@netformic.com>2023-09-05 17:27:24 +0200
committerHeiner Lohaus <heiner.lohaus@netformic.com>2023-09-05 17:27:24 +0200
commit5ca47b44b2b42abb4f48163c17500b5ee67ab28f (patch)
treeb8fba4bde73d59c05857459eac41b25347d65c8e /g4f/Provider/Wewordle.py
parent~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff)
downloadgpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.gz
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.bz2
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.lz
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.xz
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.zst
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Wewordle.py55
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