返回提交历史
Added
testing/wewordle/README.md
+1
-0
Added
testing/wewordle/Wewordle.py
+97
-0
Added
testing/wewordle/testing.py
+30
-0
XFEstudio/gpt4free
add wewordle
51a8fe19
代码差异
3 个文件
+128
-0
@@ -0,0 +1 @@
1
original from website https://chat-gpt.com/chat https://github.com/xtekky/gpt4free/issues/40#issuecomment-1629152431, i got api https://wewordle.org/gptapi/v1/web/turbo but it got limit so i try to try reverse they android app and i got api https://wewordle.org/gptapi/v1/android/turbo and just randomize user id to bypass limit
@@ -0,0 +1,97 @@
1
import os,sys
2
import requests
3
import json
4
import random
5
import time
6
import string
7
# from ...typing import sha256, Dict, get_type_hints
8
9
url = "https://wewordle.org/gptapi/v1/android/turbo"
10
model = ['gpt-3.5-turbo']
11
supports_stream = False
12
needs_auth = False
13
14
15
def _create_completion(model: str, messages: list, stream: bool, **kwargs):
16
base = ''
17
for message in messages:
18
base += '%s: %s\n' % (message['role'], message['content'])
19
base += 'assistant:'
20
# randomize user id and app id
21
_user_id = ''.join(random.choices(f'{string.ascii_lowercase}{string.digits}', k=16))
22
_app_id = ''.join(random.choices(f'{string.ascii_lowercase}{string.digits}', k=31))
23
# make current date with format utc
24
_request_date = time.strftime("%Y-%m-%dT%H:%M:%S.000Z", time.gmtime())
25
headers = {
26
'accept': '*/*',
27
'pragma': 'no-cache',
28
'Content-Type': 'application/json',
29
'Connection':'keep-alive'
30
# user agent android client
31
# 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 10; SM-G975F Build/QP1A.190711.020)',
32
33
}
34
data = {
35
"user": _user_id,
36
"messages": [
37
{"role": "user", "content": base}
38
],
39
"subscriber": {
40
"originalPurchaseDate": None,
41
"originalApplicationVersion": None,
42
"allPurchaseDatesMillis": {},
43
"entitlements": {
44
"active": {},
45
"all": {}
46
},
47
"allPurchaseDates": {},
48
"allExpirationDatesMillis": {},
49
"allExpirationDates": {},
50
"originalAppUserId": f"$RCAnonymousID:{_app_id}",
51
"latestExpirationDate": None,
52
"requestDate": _request_date,
53
"latestExpirationDateMillis": None,
54
"nonSubscriptionTransactions": [],
55
"originalPurchaseDateMillis": None,
56
"managementURL": None,
57
"allPurchasedProductIdentifiers": [],
58
"firstSeen": _request_date,
59
"activeSubscriptions": []
60
}
61
}
62
response = requests.post(url, headers=headers, data=json.dumps(data))
63
if response.status_code == 200:
64
_json = response.json()
65
if 'message' in _json:
66
yield _json['message']['content']
67
else:
68
print(f"Error Occurred::{response.status_code}")
69
return None
70
71
# params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
72
# '(%s)' % ', '.join(
73
# [f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])
74
75
76
# Temporary For ChatCompletion Class
77
class ChatCompletion:
78
@staticmethod
79
def create(model: str, messages: list, provider: None or str, stream: bool = False, auth: str = False, **kwargs):
80
kwargs['auth'] = auth
81
82
if provider and needs_auth and not auth:
83
print(
84
f'ValueError: {provider} requires authentication (use auth="cookie or token or jwt ..." param)', file=sys.stderr)
85
sys.exit(1)
86
87
try:
88
89
90
return (_create_completion(model, messages, stream, **kwargs)
91
if stream else ''.join(_create_completion(model, messages, stream, **kwargs)))
92
except TypeError as e:
93
print(e)
94
arg: str = str(e).split("'")[1]
95
print(
96
f"ValueError: {provider} does not support '{arg}' argument", file=sys.stderr)
97
sys.exit(1)
@@ -0,0 +1,30 @@
1
from Wewordle import ChatCompletion
2
3
# Test 1
4
response = ChatCompletion.create(model="gpt-3.5-turbo",
5
provider="Wewordle",
6
stream=False,
7
messages=[{'role': 'user', 'content': 'who are you?'}])
8
9
print(response)
10
11
# Test 2
12
response = ChatCompletion.create(model="gpt-3.5-turbo",
13
provider="Wewordle",
14
stream=False,
15
messages=[{'role': 'user', 'content': 'what you can do?'}])
16
17
print(response)
18
19
20
# Test 3
21
response = ChatCompletion.create(model="gpt-3.5-turbo",
22
provider="Wewordle",
23
stream=False,
24
messages=[
25
{'role': 'user', 'content': 'now your name is Bob'},
26
{'role': 'assistant', 'content': 'Hello Im Bob, you asistant'},
27
{'role': 'user', 'content': 'what your name again?'},
28
])
29
30
print(response)